Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

SolutionPool vs. cplex.getValue(IloNumVar, int)

  • 1.  SolutionPool vs. cplex.getValue(IloNumVar, int)

    Posted Fri March 28, 2008 05:29 PM

    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


  • 2.  Re: SolutionPool vs. cplex.getValue(IloNumVar, int)

    Posted Mon March 31, 2008 12:14 AM

    Originally posted by: SystemAdmin


    [MaryFenelon said:]

    It looks like you have found a bug in our Java API.  We'll fix it in our spring release.  As a workaround, you can use the array version of getValues, that is, make an IloNumVar array to hold your variables and then use that in a getValues call:

        IloNumVar[] var = {a, b, c};
        double[] var_values = cplex.getValues(var, 0, 3, i);


    Thanks for providing a simple example that showed the bug.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: SolutionPool vs. cplex.getValue(IloNumVar, int)

    Posted Mon September 29, 2008 09:50 PM

    Originally posted by: SystemAdmin


    [msamo said:]

    I have the same problem with C#. Is it possible that there is a bug also for the .NET framework?
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: SolutionPool vs. cplex.getValue(IloNumVar, int)

    Posted Mon September 29, 2008 10:12 PM

    Originally posted by: SystemAdmin


    [MaryFenelon said:]

    Yes, there was a similar bug.  The bug was fixed in the 11.1 release.
    #CPLEXOptimizers
    #DecisionOptimization