Using callbacks in the Python API

Introduces callbacks in the Python API.

Callbacks allow user-written Python functions to supplement the algorithms CPLEX applies to solve optimization problems. Like other APIs of CPLEX, the Python API supports user-written callbacks for many purposes, such as:

complex termination criteria;

  • complex termination criteria;

alternative branching rules;

  • alternative branching rules;

user-defined cutting planes;

  • user-defined cutting planes;

additional criteria for feasibility of new incumbents;

  • additional criteria for feasibility of new incumbents;

and many other possibilities.

  • and many other possibilities.

In the Python API, the callback classes are defined in the module callbacks of the package cplex. They occupy a hierarchy of classes similar to that of the other object-oriented APIs, such as C++ or Java.

callbacks.SimplexCallback
 callbacks.BarrierCallback
 callbacks.CrossoverCallback
 callbacks.TuningCallback
 callbacks.MIPInfoCallback
 callbacks.MIPCallback
      callbacks.BranchCallback
      callbacks.UserCutCallback
      callbacks.LazyConstraintCallback
      callbacks.HeuristicCallback
      callbacks.SolveCallback
      callbacks.IncumbentCallback
      callbacks.NodeCallback

The topic Using legacy optimization callbacks offers general guidance about writing and using your own callbacks.