Originally posted by: SystemAdmin
I think I tripped over a small cosmetic bug in CPLEX 12.4.0.0 (Linux version, Java API). The following code snippet generates the constraint x <= y + 2z + 17 two slightly different ways:
IloCplex cplex =
new IloCplex(); IloNumVar x = cplex.numVar(0.0, Double.MAX_VALUE,
"x"); IloNumVar y = cplex.numVar(0.0, Double.MAX_VALUE,
"y"); IloNumVar z = cplex.numVar(0.0, Double.MAX_VALUE,
"z"); IloLinearNumExpr ex1 = cplex.linearNumExpr(); IloLinearNumExpr ex2 = cplex.linearNumExpr(); ex1.addTerm(1.0, x); ex1.addTerm(-1.0, y); ex1.addTerm(-2.0, z); ex2.setConstant(17.); ex2.addTerm(1.0, y); ex2.addTerm(2.0, z); IloConstraint c1 = cplex.le(ex1, 17.); IloConstraint c2 = cplex.le(x, ex2); System.out.println(
"Version 1: " + c1 +
"\nVersion 2: " + c2);
Here's the output:
Version 1: IloRange : -infinity <= (1.0*x - 1.0*y - 2.0*z) <= 17.0 Version 2: IloRange : -infinity <= (1.0*x - 1.0*y - 2.0*z -17.0) <= 17.0
Note that the second version shows the constant term in both the expression and the upper bound, which would seem to indicate the constraint is x <= y + 2z + 34. Judging from results on a real problem (with more complex constraints, but the same basic approach), I think the second constraint is actually implemented correctly but just prints out incorrectly.
Paul
Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
#CPLEXOptimizers#DecisionOptimization