Linear Programming with Google or-tools in C++: Use callback function to stop search

Viewed 32

I am using Google's or-tools library in Combination with the SCIP solver to solve an integer linear program, by leveraging the MPSolver class. I would like to have a customizable callback function being called every-time a new solution candidate is found. This callback function should be able to evaluate the solution and and stop the ilp-solver early if the solution is "good enough" based on some users criteria. The equivalent in Gurobi-py would look something like this:


  def callback(model_cb: gp.Model, where):
        assert where != gp.GRB.Callback.MULTIOBJ
        if where == gp.GRB.Callback.MIPSOL:
                model_cb._check_is_success(model_cb.cbGetSolution(s)):
                model._interrupted_success = True
                model_cb.terminate()
model = gp.Model()
model._check_is_success = check_is_success
model._interrupted_success = False
[...]
# Set up model
model.optimize(callback)

I found the SetCallback in the [OR-Tools documentation}(https://developers.google.com/optimization/reference/linear_solver/linear_solver/MPSolver) for the MPSolver class, but no usage examples. Where can I find an example on how to use Callback functions for early termination of the ILP-solver in or-tools?

1 Answers
Related