Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Problem with "addMIPStart"

    Posted 02/06/11 05:33 PM

    Originally posted by: Swisscube


    Hello,

    I have the following problem with CPLEX. I use CPLEX with Java and I want to set as starting point a solution from which I know that it is nearly optimal. My Java Code looks like this:

    IloIntVar[] y = cplex.intVarArray(Parameters.numberOfTasks*numberOfServicesPerTask, 0, 1);
    double[] yValuesExtended =
    new doublehttp://Parameters.numberOfTasks*numberOfServicesPerTask;
    cplex.addMIPStart(y, yValuesExtended);

    When I execute it, it keeps throwing

    java.lang.NullPointerException at ilog.cplex.CpxNumVar.getVarIndexValue(CpxNumVar.java:268)
    at ilog.cplex.CplexI.addMIPStart(CplexI.java:2779)
    ...

    I'm quite new to Cplex, so maybe it is something simple. But I have already been working on this for a while and I don't find it (it's also urgent). Any help would be greatly appreciated - thanks in advance,

    I.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Problem with "addMIPStart"

    Posted 02/06/11 07:42 PM

    Originally posted by: SystemAdmin


    First, part of your code is illegible -- the forum software interpreted it as a hyperlink. Bracketing code with the {code} tag (see markup help to the right) would avoid this. Using the Preview tab would let you know if you were successful.

    Second, there needs to be something between the declaration of the two vectors and their use in addMIPStart -- you need to put the variables used in your model into the variable vector and the corresponding values for them in the initial solution into the double vector.

    /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


  • 3.  Re: Problem with "addMIPStart"

    Posted 02/07/11 07:36 AM

    Originally posted by: Swisscube


    First of all: thank you for your quick response!

    > Paul Rubin wrote:
    > First, part of your code is illegible -- the forum software interpreted it as a hyperlink. Bracketing code with the {code} tag (see markup help to the right) would avoid this. Using the Preview tab would let you know if you were successful.
    >
    Yes, you're right - sorry

    > Second, there needs to be something between the declaration of the two vectors and their use in addMIPStart -- you need to put the variables used in your model into the variable vector and the corresponding values for them in the initial solution into the double vector.
    Well, the variable y (IloIntVar vector) is used in the model and I surely would have to put the values of the initial solution into the yValuesExtended double vector. However, it throws a null pointer exception so as I understand it, this cannot be due to providing the wrong values in the values vector ... ? In each case the variables and the values vector have the same size. (I assigned the yValuesExtended vector to the right solution values in the previous version of the code but now I simplified it a lot in order to find the bug)
    Could you maybe provide a very simple code example for the use of addMIPStart? Just for assigning lets say two IloIntVars to two values using addMIPStart. This would be great!
    Thanks.
    >
    > /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


  • 4.  Re: Problem with "addMIPStart"

    Posted 02/07/11 11:48 AM

    Originally posted by: SystemAdmin


    > Swisscube wrote:

    > Could you maybe provide a very simple code example for the use of addMIPStart? Just for assigning lets say two IloIntVars to two values using addMIPStart. This would be great!

    /* * Sample model: * maximize x0 + 2x1 + 3x2 * s.t. x0 + x1 <= y0 * x1 + x2 <= y1 * 2y0 + 3y1 <= 20 * x >= 0 * y1, y2 in {0,...,10} */
            IloCplex cplex = new IloCplex();
            IloNumVar[] y = cplex.intVarArray(2, 0, 10);
            IloNumVar[] x = cplex.numVarArray(3, 0.0, Double.MAX_VALUE);
            cplex.addMaximize(cplex.scalProd(new double[] {1.0, 2.0, 3.0}, x));
            cplex.addLe(cplex.sum(x[0], x[1]), y[0]);
            cplex.addLe(cplex.sum(x[1], x[2]), y[1]);
            cplex.addLe(cplex.scalProd(new double[] {2.0, 3.0}, y), 20);
            // add y = (5, 3) as a starting solution
            cplex.addMIPStart(y, new double[] {5.0, 3.0});
            if (cplex.solve()) {
              System.out.println("OV = " + cplex.getObjValue());
            }
    


    /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


  • 5.  Re: Problem with "addMIPStart"

    Posted 02/09/11 10:19 AM

    Originally posted by: Swisscube


    Okay, thanks for the responses! I think I solved it now - the problem was the order. I first called "addMIPStart" and then wanted to add the constraints etc. before I call "solve" but I had to call "addMIPStart" directly before "solve" when the model is already complete. Thanks again!
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Problem with "addMIPStart"

    Posted 02/10/11 06:38 AM

    Originally posted by: SystemAdmin


    To be more precise: All the variables you pass to addMIPStart() must be part of the model at the time you call addMIPStart().
    So yes, your problem was just the order of the statements.
    #CPLEXOptimizers
    #DecisionOptimization