1
votes

I am trying to model an objective function using Cplex in java. My objective function is a product of a probability and a cost expression, that is: Obj= sum(Pr(i)*Cost(i)).

I modeled like this:

IloLinearNumExpr objective = cplex.linearNumExpr();


for (int i=0; i<M; i++){

                objective.addTerm(Pc[i],SupplierCost[i]);

  }

But I have the error message that "The method addTerm(double, IloNumVar) in the type IloLinearNumExpr is not applicable for the arguments (double, IloLinearNumExpr)".

What is wrong?

Thanks!

1
could you paste the SupplierCost definition? - jjlema

1 Answers

0
votes

IloLinearNumExpr.addTerm only applies to double and IloNumVar. By the error message, your SupplierCost[i] is a IloNumExpr, not an IloNumVar. You can add Pc[i] * Supplier[i] to objective by using the IloCplex.prod method to create a new IloNumExpr and using the IloNumExpr.add method to add the resulting IloNumExpr to objective.

IloLinearNumExpr objective = cplex.linearNumExpr();
for (int i=0; i<M; i++){
     objective.add(cplex.prod(Pc[i],SupplierCost[i]));
}