Reputation: 96
I#m trying to model the objective function sum(i in Sites,j in Sites, k in Routings)(c[i][j] * x[i][j][k]*TruckKmCost) in Cplex using java.
IloLinearNumExpr expr = cplex.linearNumExpr();
for (int i = 1; i <= nbFarmer; i++) {
for (int j = 1; j <= nbFarmer; j++) {
for (int k = 1; k <= nbRouting; k++) {
expr.addTerm(truckKmCost, c[i][j],x[i][j][k]);
}
}
}
This was my attempt, but the method addTerm only accepts (double, IloNumVar), and I can't convert c[i][j] to IloNumVar, because I need it as an int so i can add my int values to it.
There must be a pretty easy solution, maybe somebody can help me, I'm a little stumped right now.
Thanks a lot!
Upvotes: 0
Views: 66
Reputation: 5930
You did not specify whether c[i][j]
is a variable or a number. Depending on this there are two different solutions to your issue:
c[i][j]
is a number then just write expr.addTerm(truckKmCost * c[i][j], x[i][j][k])
, that is, merge the two numbers into one single argument to addTerm
.c[i][j]
is a variable then your objective is not linear but quadratic. In that case you cannot use IloLinearNumExpr
but have to use IloQuadNumExpr
. The addTerm()
of this class takes two variables as arguments.Upvotes: 1