ILOG CPLEX 11.0 User's Manual > Advanced Programming Techniques > Using Optimization Callbacks > Implementing Callbacks in ILOG CPLEX with Concert Technology > Writing Callbacks with Macros |
Writing Callbacks with Macros |
INDEX PREVIOUS NEXT |
This is how to implement a callback using macros. Since macros are not supported in Java nor in .NET, this technique will only apply to C++ applications.
Start by deciding which callback you want to implement and how many arguments to pass to the callback function. These two pieces of information determine the macro you need to use.
For example, to implement a simplex callback with one argument, the macro is ILOSIMPLEXCALLBACK1
. Generally, for every callback type XXX
and any number of arguments n
from 0
to 7
, there is a macro called ILOXXXCALLBACKn
. Table 30.2 lists the callbacks and the corresponding macros and classes (where n is a placeholder for 0 to 7).
The protected methods of the corresponding class and its base classes specify the functions that can be called for implementing your callback. See the ILOG CPLEX Reference Manual with respect to these classes for details of which functions can be called.
Here is an example of how to implement a simplex callback with the name MyCallback
that takes one argument:
This callback aborts the simplex algorithm at the iteration indicated by the number num
. It queries the current iteration number by calling the function getNiterations
, a protected method of the class IloCplex::ContinuousCallbackI
.
To use this callback with an IloCplex
object cplex
, simply call:
The callback that is added to cplex
is returned by the method use
and stored in the variable mycallback
. This allows you to call mycallback.end
to remove the callback from cplex
. If you do not intend to access your callback (for example, in order to delete it before ending the environment), you may safely leave out the declaration and initialization of the variable mycallback
.
Copyright © 1987-2007 ILOG S.A. All rights reserved. Legal terms. | PREVIOUS NEXT |