Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Using heuristic solutions within HeuristicCallback // or using addMIPStart

    Posted 05/28/15 07:49 AM

    Originally posted by: ORstudent


    Hello,

    I am trying to use ILOHEURISTICCALLBACK for introducing solutions that got from heuristic but it gives me the following error:

    The referenced IloExtractable has not been extracted by the IloAlgorithm.

    What I am doing is the following:

    xBest2 is a double array with the values of the decision variables for getting the objective value of the heuristic

    bestSol2 is a double with the objective value of the solution I got from the heuristic

    ILOHEURISTICCALLBACK1(heurCB,IloNumVarArray, vars)
    {
    int cols   = vars.getSize();
    IloNumArray X12 = IloNumArray(getEnv(),cols);
    IloNum objVal = getIncumbentObjValue();
    if(bestSol2!=-1&&bestSol2>objVal) //if the solution of the heuristic is better than the incumbent got by CPLEX so far, I replace it
    {
    for(int i=0;i<cols;i++)
    X12[i] =(bool)xBest2[i]; 
    objVal=bestSol2;
    setSolution(vars,X12,objVal); //Here I got the error
     
    }
    }

    Any clue of why I am getting the error?

    Thanks!!

    ---

    Edit :

    Or should I directly use addMIPStart, that will make the same??


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Using heuristic solutions within HeuristicCallback // or using addMIPStart

    Posted 05/28/15 04:29 PM

    Most likely the vars array contains an IloNumVar that was never actually used in the model (did not appear in any constraint, nor in the objective function). CPLEX would ignore that variable when extracting the model, and trying to set a value for it would trigger the exception you got.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Using heuristic solutions within HeuristicCallback // or using addMIPStart

    Posted 05/29/15 01:56 AM

    Originally posted by: ORstudent


    Thanks for answering Paul! I am a little bit puzzled, I use cplex.use(heurCB(env,X11)) where X11 are the decision variables defined in the model as IloNumVarArray. I have printed the vars.size(), and I get the size of X11. Then, for solving this problem what I should do with vars? (any small/tiny example or indication will be very good welcome :-))

    I mean, I have IloNumVarArray X11 which are my decision variables in the model, once that I use cplex.use(heurCB(env,X11)) so I give the X11 to the heuristic callback, but still getting the error. I have changed vars to X11 in the definition of the callbakc as ILOHEURISTICCALLBACK1(heurCB,IloNumVarArray, X11) , but getting same error...

    On the other hand, do you think what I am doing is similar to addMIPStart?

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Using heuristic solutions within HeuristicCallback // or using addMIPStart

    Posted 05/29/15 03:45 AM

    What Paul meant was that the X11 array may contain a variable that is never referenced in any constraint or the objective function. If that is the case then the variable is not extracted to CPLEX for the solve and you will get the exception you describe.

    You can do cplex.add(X11) before calling cplex.solve() to make sure CPLEX extracts all variables in X11, even those that are never mentioned in the model. That should fix the exception.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Using heuristic solutions within HeuristicCallback // or using addMIPStart

    Posted 05/29/15 05:00 AM

    Originally posted by: ORstudent


    Thanks for answering Daniel!

    cplex.add() requires me a callback, what I did was the following:

    IloNumVarArray startVar(aEnv);
    for(int i=0;i<X11.getSize()-1;i++)
    startVar.add(X11[i]);
    cplex.use(heurCB(aEnv,startVar));

    cplex.solve();

    and now can use the heurCB without problem :-),  is this correct?

    Also, BTW addMIPstart do the same as what I am doing in he heuristiccallback (checking the incumbent and changing it by one from an heuristic in case of improvement)?

    Thanks both!!!


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Using heuristic solutions within HeuristicCallback // or using addMIPStart

    Posted 06/02/15 07:41 AM

    cplex.add() does not require a callback. add() is an instance method of the IloCplex class.

    I don't see how the things you did would have fixed the problem you described.

    MIP starts and solutions injected by the heuristic callback are treated slightly differently. If you know your solution even before you call cplex.solve() then it is better to use a MIP start. If you can discover the solution only while the solve process is already running then you are stuck with the heuristic callback.


    #CPLEXOptimizers
    #DecisionOptimization