Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  HeuristicCallback: setSolution

    Posted 03/15/16 07:07 AM

    Originally posted by: Claus Brech


    Hello everyone,

    I am implementing a Mathheuristic using Java with CPLEX 12.6.1 and I have a problem concerning the setSolution()-Method within a HeuristicCallback. My problem is, that the solution I inject via setSolution is not accepted as a new incumbent, even though it is feasible and no feasible integer solution has been found so far. Is there a way of forcing CPLEX to use it as the next incumbent?

     

    Here is what I have done so far:

    • I used setBounds within HeuristicCallback first and then invoked the method solve() in order to verify that my proposed solution is feasible. It is feasible in all cases.
    • From this useful entry I have gathered that the incumbent is not updated immediatly. However, even after 10 minutes of run-time it does not accept my proposed incumbent, even though it would improve the best solution found so far.

    Maybe I should mention that I also use UserCallBacks and LazyConstraintCallback and preprocessing is turned on. I read in this topic that CPLEX 12.6.1 has issues with warm starts if lazy constraints are present. I was wondering if this might be also responsible for the problem I am having.

     

    I would appreciate if someone who has encountered a similar problem could help me out. Please let me know if you need more information on my code.

     

    Thanks in advance

     

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: HeuristicCallback: setSolution

    Posted 03/21/16 02:34 AM

    UserCutCallback and LazyConstraintCallback should not be an issue here.

    I tried a few things here but could not reproduce your problem. Do you have a (small) code example that you can share that reproduces the issue?

    Just to rule out some frequent problems:

    • Did solve() return true before you called setSolution()?
    • Do you call setSolution() more than once per callback invocation?
    • Does your model contain only linear constraints or does it also contain logical constraints, SOS constraints etc.?
    • Does the problem persist if you disable presolve?

    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: HeuristicCallback: setSolution

    Posted 03/29/16 07:07 AM

    Originally posted by: Claus Brech


    Thank you for your answer. Regarding your questions: 

    • solve() returns true and setSolution() is only invoked once each time the heuristic callback is called.
    • My model contains only linear constraints
    • I will try it out with disabled presolve, thanks for your idea!

    I could not think of a small example, but maybe the general structure of my code makes it a bit more clear. The algorithm I am developping is based on Benders Decomposition and therefore I have a master and and sub problem. Here is some code to illustrate what I want to do:

     

    IloCplex master = new IloCplex; //Benders Masterproblem

    IloCplex sub = new IloCplex(); //Benders Subproblem

    buildMaster(); //Method to set objective function and constraints for master problem
    buildSub(); // //Method to set objective function and constraints for sub problem

    sub.setParam(IloCplex.BooleanParam.PreInd, false); 

    master.use(new BendersCallback(this)); //Lazy Constraint Callback to generate Benders Cuts at each incumbent during B&B
    master.use(new HybridACO(this)); // UserCutCallback generating heuristic solutions<- The solutions generated here are the ones I want to inject

    master.use(new Injector(this)); // Heuristic callback that should inject solutions in case better solutions have been found by the UserCutCallback

    Unfortunately, even though the injected solution is valid, CPLEX just seem to ignore it. However, I found a workaround that is not optimal but good enough for me.

    The workaround involves:

    • I divided the algorithm in two phases. In phase 1 I use HybridACO (my heuristic within a UserCutCallback) to find heuristic solutions and store them.
    • In phase 2, I create a new instance of my master problem, add all benders cuts of phase 1 and the best solution found during phase two. Therefore, I inject the solution at the root node. Apparently CPLEX is fine with that as it accepts the solution immediatly.

    I have another question: Do you have experience in implementing Benders Decomposition in CPLEX? My experience is, that preprocessing of the sub problem needs to be turned off, since otherwise I get a lot of null pointer exceptions accessing variables and constraints that CPLEX removed. Is there a way to iterate over the preprocessed model?

     

    Best regards

    Claus Brech

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: HeuristicCallback: setSolution

    Posted 03/29/16 12:10 PM

    I don't see anything wrong with the code you outlined. If solve() returns true in the heuristic callback then setSolution() should correctly inject the solution. How exactly do you call setSolution()? Do you pass values for all variables (not just the integer variables)? The code should roughly look like this:

    if ( solve() ) {
       setSolution(x, getValues(x)); // x is an array that contains _all_ variables
    }

    Does your code look reasonably similar to this?

    About the null pointer exceptions: This should not happen. There is no way to iterate over the preprocessed model but in any control callback you can use getFeasibilities() to find the variables that were presolved out. The function will return Implied for any variable that was removed by presolve.

    Are you by any chance mixing variables or constraints from the master and the sub-problem when you observe those null pointer exceptions?


    #CPLEXOptimizers
    #DecisionOptimization