Kassem M Danach
Kassem M Danach

Reputation: 1

Cplex Objective Function Error

I declare a variable linObj as IloNumExpr, and I have 4 loops (loop element i,j,k and l) where each time I add to this variable a summation of two other variable like:

linObj = cplex.sum(linObj, cplex.sum(s[i][j][j][k],s[i][j][l][k])

When loops are closed I declare linObj as the objective function.

Now, I have an error called ilog.cplex.MultiObjectiveException.

Upvotes: 0

Views: 425

Answers (1)

Delfic
Delfic

Reputation: 167

With that exception you're probably doing something like this inside your loops:

linObj = cplex.sum(linObj, cplex.sum(s[i][j][j][k],s[i][j][l][k]);
cplex.addMinimize(linObj);

Thus getting multiple objectives. Only call cplex.addMinimize(linObj); after the loops and you should only get one objective.

Moreover, you should consider changing your code to:

IloLinearNumExpr linObj = cplex.linearNumExpr();
/*loops*/

linObj.addTerm(1, cplex.sum(s[i][j][j][k],s[i][j][l][k]);

/*after loops*/
cplex.addMinimize(linObj);

Hope this helps

Upvotes: 1

Related Questions