Originally posted by: SystemAdmin
[Hendrik said:]
Hi everybody,
I'm just trying out the new solution pool feature in Cplex 11.0 using the Java interface. I was able to run the example provided ("Populate.java") but I failed to use it in my own code: All the solutions in the pool always seemed to be the same.
I boiled down the problem to the following minimal example:
import ilog.concert.
;
import ilog.cplex.;
public class PopulateFail {
public static void main(String[] args) {
try {
IloCplex cplex = new IloCplex();
IloNumVar a = cplex.intVar(0, 10);
IloNumVar b = cplex.intVar(2, 10);
IloNumVar c = cplex.intVar(0, 5);
cplex.addGe(cplex.sum(cplex.prod(3, a), b), 6);
cplex.addGe(cplex.sum(c, b), 5);
IloLinearNumExpr objFunc = cplex.linearNumExpr();
objFunc.addTerm(1, a);
objFunc.addTerm(2, b);
objFunc.addTerm(1, c);
cplex.addMinimize(objFunc);
if (cplex.populate()) {
System.out.println("Solution status = " + cplex.getStatus());
System.out.println("Incumbent objective value = " + cplex.getObjValue());
System.out.println("a = " + cplex.getValue(a));
System.out.println("b = " + cplex.getValue(b));
System.out.println("c = " + cplex.getValue(c));
System.out.println();
cplex.writeSolutions("poolSolutions.xml");
for (int i = 0; i < cplex.getSolnPoolNsolns(); i++) {<br /> System.out.println("Solution " + i + ": a = " + cplex.getValue(a, i) + ", b = "
+ cplex.getValue(b, i) + ", c = " + cplex.getValue(c, i) + ", obj.value = "
+ cplex.getObjValue(i));
}
}
cplex.end();
} catch (IloException e) {
System.err.println("Concert exception caught: " + e);
}
}
}
The output is the following:
Populate: phase I
Tried aggregator 1 time.
Reduced MIP has 2 rows, 3 columns, and 4 nonzeros.
Presolve time = 0.00 sec.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: none, using 1 thread.
Root relaxation solution time = 0.00 sec.
Nodes Cuts/
Node Left Objective IInf Best Integer Best Node ItCnt Gap
* 0+ 0 12.0000 8.3333 0 30.56%
* 0+ 0 9.0000 8.3333 0 7.41%
Populate: phase II
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: none, using 1 thread.
Nodes Cuts/
Node Left Objective IInf Best Integer Best Node ItCnt Gap
0 0 infeasible 9.0000 8.3333 0 7.41%
Solution status = Optimal
Incumbent objective value = 9.0
a = 2.0
b = 2.0
c = 3.0
Solution 0: a = 2.0, b = 2.0, c = 3.0, obj.value = 12.0
Solution 1: a = 2.0, b = 2.0, c = 3.0, obj.value = 9.0
Interesting are the last two lines: Although the objective function values are different, the variable assignments are reported to be the same! I further investigated and wrote an XML-file with the solutions (using the cplex.writeSolutions(String) method, see code above). Turns out that in the XML the correct assignments are given for the first pool solution:
<variables>
<variable name="IloX0" index="0" value="0"/>
<variable name="IloX1" index="1" value="6"/>
<variable name="IloX2" index="2" value="0"/>
</variables>
How can that be? What do I do wrong when using cplex.getValue(IloNumVar, int)?
Any help is appreciated!
Best regards,
Hendrik.
#CPLEXOptimizers#DecisionOptimization