user2114036
user2114036

Reputation: 163

CPLEX C++ Quadratic objective function

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!

Upvotes: 1

Views: 568

Answers (1)

David Nehme
David Nehme

Reputation: 21597

Your maximization objective is not concave. In fact it is neither concave or convex. Cplex only supports maximizing concave or linear functions. Cplex doesn't verify that your objective funcrion is within its scope. It leaves that as the modeler's responsibility, partly because it is almost as computationally difficult to verify as it is to actually compute an optimal solution.

Upvotes: 1

Related Questions