Gurobi callback class. This is an abstract class. To implement a
callback, you should create a subclass of this class and implement a
callback() method. If you pass an object of this subclass to
callback() method of the class will be called
periodically. Depending on where the callback is called
from, you can obtain various information about the progress
of the optimization.
Note that this class contains one protected int member
where. You can query this variable from your
callback() method to determine where the callback was called
Gurobi callbacks can be used both to monitor the progress of the optimization and to modify the behavior of the Gurobi optimizer. A simple user callback function might call the GRBCallback::getIntInfo or GRBCallback::getDoubleInfo methods to produce a custom display, or perhaps to terminate optimization early (using GRBCallback::abort). More sophisticated MIP callbacks might use GRBCallback::getNodeRel or GRBCallback::getSolution to retrieve values from the solution to the current node, and then use GRBCallback::addCut or GRBCallback::addLazy to add a constraint to cut off that solution, or GRBCallback::setSolution to import a heuristic solution built from that solution.
When solving a model using multiple threads, note that the user callback is only ever called from a single thread, so you don't need to worry about the thread-safety of your callback.
You can look at the
callback_c++.cpp example for details of how
to use Gurobi callbacks.