Overview | Group | Tree | Graph | Index | Concepts |
This is the abstract base class for user-written callback classes. It provides their common application programming interface (API). Callbacks may be called repeatedly at various points during an optimization; for each place a callback is called, ILOG CPLEX provides a separate callback class (derived from this class). Such a callback class provides the specific API as a protected method to use for the particular implementation.
You do not create instances of this class; rather, you use one of
its child classes to implement your own callback. In order to implement
your user-written callbacks with an instance of IloCplex
,
you should follow these steps:
MyCallbackI
, say,
from the appropriate predefined callback class.main
routine of your
user-written callback. (All constructors of predefined callback
classes are protected; they can be called only from
user-written derived subclasses.)duplicateCallback
.myCallback
, say,
that creates an instance of your implementation
class in the Concert Technology environment and returns it as an IloCplex::Callback
handle.IloCplex::use
.
Macros ILOXXXCALLBACKn
(for n
from 0 to 7) are
available to facilitate steps 2 through 5, where XXX
stands for the particular callback under construction and n
stands for the number of parameters that
the function written in step 5 is to
receive in addition to the environment parameter.
You can use one instance of a callback with only one instance of
IloCplex
. When you use a callback with a second instance of
IloCplex
,
a copy will be automatically created using the method
duplicateCallback
, and that copy will be
used instead.
Also, an instance of IloCplex
takes account of
only one instance of a particular callback at any given time. That is, if
you call IloCplex::use
more than once with
the same class of callback, the last call overrides any previous one. For
example, you can use only one primal simplex callback at a time, or you can
use only one network callback at a time; and so forth.
There are two varieties of callbacks:
IloCplex
. The
information available depends on the algorithm (primal
simplex, dual simplex, barrier, mixed integer, or network) that you are
using. For example,
a query callback can return the current objective value,
the number of simplex iterations that have been completed, and other
details. Query callbacks can also be called from presolve, probing,
fractional cuts, and disjunctive cuts.IloCplex
. For example, control
callbacks enable you to select the
next node to process or to control the creation of subnodes (among other
possibilities).Existing extractables should never be modified within a callback. Temporary extractables, such as arrays, expressions, and range constraints, can be created and modified. Temporary extractables are often useful, for example, for computing cuts.
See Also:
ILOBARRIERCALLBACK0, ILOBRANCHCALLBACK0, IloCplex, IloCplex::BarrierCallbackI, IloCplex::BranchCallbackI, IloCplex::Callback, IloCplex::ControlCallbackI, IloCplex::CrossoverCallbackI, IloCplex::CutCallbackI, IloCplex::DisjunctiveCutCallbackI, IloCplex::SimplexCallbackI, IloCplex::FractionalCutCallbackI, IloCplex::HeuristicCallbackI, IloCplex::IncumbentCallbackI, IloCplex::ContinuousCallbackI, IloCplex::MIPCallbackI, IloCplex::NetworkCallbackI, IloCplex::NodeCallbackI, IloCplex::PresolveCallbackI, IloCplex::ProbingCallbackI, IloCplex::SolveCallbackI, ILOCROSSOVERCALLBACK0, ILOCUTCALLBACK0, ILOBRANCHCALLBACK0, ILODISJUNCTIVECUTCALLBACK0, ILOFRACTIONALCUTCALLBACK0, ILOHEURISTICCALLBACK0, ILOINCUMBENTCALLBACK0, ILOCONTINUOUSCALLBACK0, ILOMIPCALLBACK0, ILONETWORKCALLBACK0, ILONODECALLBACK0, ILOPRESOLVECALLBACK0, ILOPROBINGCALLBACK0, ILOSIMPLEXCALLBACK0, ILOSOLVECALLBACK0
Method Summary | |
---|---|
protected void | abort() |
protected virtual CallbackI * | duplicateCallback() |
protected IloEnv | getEnv() |
protected IloModel | getModel() |
protected IloInt | getNcols() |
protected IloInt | getNQCs() |
protected IloInt | getNrows() |
protected virtual void | main() |
Method Detail |
---|
This method stops the current optimization.
This virtual method must be implemented to create a copy of the
invoking callback object on the same environment. Typically the following
implementation will work for a callback class called
MyCallbackI
:
IloCplex::CallbackI* MyCallbackI::duplicateCallback() const { return (new (getEnv()) MyCallbackI(*this)); }
This method is called by an IloCplex
object in two
cases:
cplex.use(cb)
is called for a callback object
cb
that is already used by another instance of
IloCplex
, a copy of the implementation object of
cb
is created by calling duplicateCallback
and used in its place. The method use
will return
a handle to that copy.IloCplex
creates copies of every callback that it uses by calling
duplicateCallback
. One copy of a callback is created for each
additional thread being used in the parallel optimizer. During the
optimization, each thread will invoke the copy corresponding to the thread
number. The methods provided by the callback APIs are guaranteed to be
threadsafe. However, when accessing parameters passed to callbacks or
members stored in a callback, it is up to the user to make
sure of thread safety
by synchronizing access or creating distinct copies of the data in the
implementation of duplicateCallback
.This method returns the environment belonging to the
IloCplex
object that invoked
the method main
.
This method returns the model currently extracted for the
instance of IloCplex
where the invoking callback
executed.
This method returns the number of quadratic constraints in the model currently being optimized.
This method returns the number of columns in the model currently being optimizated.
This method returns the number of rows in the model currently being optimized.
This virtual method is to be implemented by the user in a
derived callback class to define the functionality of the callback. When
an instance of IloCplex
uses a callback (an instance of
IloCplex::CallbackI
or one of its derived subclasses),
IloCplex
calls this virtual method main
at the point during the optimization at which the callback is executed.