I just began using cplex with its c++ API and I have this unusual encounter when I try to do up a simple quadratic program.
IloEnv env;
IloNumVarArray x(env, 3, 0, IloInfinity, ILOINT);
IloModel model(env);
IloExpr obj(env);
obj= x[0]*x[1] ;
model.add(IloMaximize(env, obj - 120*x[2] ));
model.add(x[0] <= 200);
model.add(x[1] >= 4500);
model.add(x[1] <= 5500);
model.add(x[2] >= 100);
model.add(x[2] <= 300);
Cplex solves and provide me with the following solution:x[0] = 200, x[1] = 5500 & x[2] = 100. This seems totally reasonable to me. However, the above codes does not work when I perform the following changes to how i formulate iloexpr:
obj= x[0]*x[1] - 120*x[2];
model.add(IloMaximize(env, obj ));
Solving it, I get x[0] = 0, x[1] = 4500, x[2] = 300. In fact, the objective value = 36000 which doesnt make sense to me.
Does anyone has any idea what is wrong with my formulation? Thanks!