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_cs.cs example for details of how
to use Gurobi callbacks.