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 will be able to
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) or to proceed to the next phase of the computation (using GRBCallback.proceed). 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. For multi-objective problems, you might use GRBCallback.stopOneMultiObj to interrupt the optimization process of one of the optimization steps in a multi-objective MIP problem without stopping the hierarchical optimization process.
When solving a model using multiple threads, 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.
Note that changing parameters from within a callback is not supported, doing so may lead to undefined behavior.
You can look at the
Callback.java example for details of how
to use Gurobi callbacks.