0

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!

1 Answer 1

1

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:

  1. In case 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.
  2. In case 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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.