> Advanced Programming Techniques > Using 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, this technique will only apply to C++ applications.
Start by determining 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 parameter, the macro is ILOSIMPLEXCALLBACK1
. Generally, for every callback type XXX
and any number of parameters n
from 0
to 7,
there is a macro called ILOXXXCALLBACKn
. Table 22.1 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 determine the functions that can be called for implementing your callback. See the ILOG CPLEX Reference Manual.
Here is an example of how to implement a simplex callback with the name MyCallback
that takes one parameter:
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 variable mycallback
. This allows you to call mycallback.end
to remove the callback from cplex
. If you do not intend accessing your callback, for example in order to delete it before ending the environment, you may safely leave out the declaration and initialization of variable mycallback
.
Copyright © 1987-2003 ILOG, S.A. All rights reserved. Legal terms. | PREVIOUS NEXT |