Namespace: ILOG.CPLEX
Assembly: ILOG.CPLEX (in ILOG.CPLEX.dll) Version: 22.1.1.0
Syntax
| C# |
|---|
public abstract class Callback : Cloneable |
| Visual Basic |
|---|
Public MustInherit Class Callback _ Implements Cloneable |
Remarks
This class defines the common interface available to all callback classes. A callback is an object with a method main implemented by the user. This method is called by the Cplex algorithm at specific points during the optimization. For each of these points, CPLEX provides a context or an extension of Cplex.Callback. To implement and use a particular callback, the user must observe the following steps:
- Select the callback class corresponding to the callback to be implemented, and create an extension of that class.
- Implement the method main for this extension. When doing so, you can use all of the methods defined in the callback class and its base classes.
- If the default implementation of the method clone is not adequate, and if the callback is to be used for parallel optimization, this method also needs to be implemented by the user. Recall that the default clone method performs a shallow copy, so typically a user implementation needs to perform a deep copy for objects that should be local to threads or the user implementation must use the synchronize keyword where synchronization is required.
- Create an instance of the user-written callback class and pass it to Cplex with the method Cplex.Use.
The next time a solution method is executed on the Cplex object for which the callback has been set, the method main of the callback will be called each time the corresponding point in the optimization algorithm is reached, for example at each iteration.
The methods of this class are protected to make sure they are used only to derive a user-written callback class or to implement the main method in it.
This class serves two different purposes:
- It is the base class for the legacy callbacks. A legacy callback is implemented by inheritance from any of the descendants of this class and by the user implementation of the main method.
- It provides a namespace for the more generic callback that is implemented by implementation of the Function interface (more specifically the Function.Invoke(Cplex.Callback.Context) method) and then using the Context passed into that function to performs queries and actions.
Inheritance Hierarchy
ILOG.CPLEX..::..Cplex..::..Callback
ILOG.CPLEX..::..Cplex..::..OptimizationCallback
ILOG.CPLEX..::..Cplex..::..TuningCallback