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