Try our new documentation site (beta).


GRBCallback

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 method GRBModel.setCallback before calling GRBModel.optimize, the 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 variable: where. You can query this variable from your callback() method to determine where the callback was called from.

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. 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.



Subsections

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search

Gurobi Optimization