Topic
2 replies Latest Post - ‏2012-12-19T16:52:51Z by SystemAdmin
SystemAdmin
SystemAdmin
754 Posts
ACCEPTED ANSWER

Pinned topic How to Stop CPLEX when it reaches a certain incumbent solution?

‏2012-12-17T00:19:08Z |
I wanted to instruct CPLEX to terminate when it reaches a certain incumbent value (let's say I can assign a reasonable specific value). But I don't know how to do it. Does anyone have a clue?
Btw, right now, I just simply add a constraint where I set this specified value as a lower bound for the objective value, which works. But I more prefer to have a more generic way to do it. I never used callback before, but I guess I probably can keep track of the current objective corresponding to the incumbent solution first and then decide to stop to it or not. Am I on the right track? And if it is a right way to go, how to do it specifically?

Thanks very much for your help in advance!
Updated on 2012-12-19T16:52:51Z at 2012-12-19T16:52:51Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    754 Posts
    ACCEPTED ANSWER

    Re: How to Stop CPLEX when it reaches a certain incumbent solution?

    ‏2012-12-18T23:19:53Z  in response to SystemAdmin
    You could certainly do it with an incumbent callback, which will be called each time CPLEX encounters a new incumbent solution. In the Java API (other APIs will be similar but not identical), create a class that extends IloCplex.IncumbentCallback. In the main() method, use getObjValue() to fetch the objective value of the latest incumbent. If it is worse than your cutoff, do nothing. If it satisfies your cutoff, use the getValue() or getValues() methods to record the solution itself, then call the abort() method to stop the computation. CPLEX will return thinking that the previous incumbent is the winner, so do not attempt to obtain the final solution from CPLEX after the solve (that's why you used getValue).

    An alternative, if you'd rather have CPLEX end with the qualifying solution rather than its predecessor, is to create a globally visible boolean flag (initially false) and use two callbacks. The incumbent callback's main method is much simpler than before: use getObjValue to get the new solution's objective value, compare it to your cutoff, and if it satisfies the stopping criterion set the global flag true. The other callback extends IloCplex.BranchCallback, but does no actual branching. Its main method examines the flag and, if true, invokes the abort() method.

    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)
    • SystemAdmin
      SystemAdmin
      754 Posts
      ACCEPTED ANSWER

      Re: How to Stop CPLEX when it reaches a certain incumbent solution?

      ‏2012-12-19T16:52:51Z  in response to SystemAdmin
      Hi Paul, thanks so much for your timely reply to my question! You clearly answered my question. But I am not very familiar with how to implement Callback yet. I will learn callback first and then try both ways you suggested.
      Thanks again!!