NO FRAMES

Class IloCplex::CallbackI

Definition file: ilocplexi.h
Include files: ilcplex/ilocplex.h

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:

  1. Determine which kind of callback you want to write, and choose the appropriate class for it. The class hierarchy in Tree may give you some ideas here.
  2. Derive your own subclass, MyCallbackI, say, from the appropriate predefined callback class.
  3. In your subclass of the callback class, use the protected API defined in the base class to implement the 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.)
  4. In your subclass, implement the method duplicateCallback.
  5. Write a function myCallback, say, that creates an instance of your implementation class in the Concert Technology environment and returns it as an IloCplex::Callback handle.
  6. Create an instance of your callback class and pass it to the member function IloCplex::use.
Note

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:

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:

Method Summary
protected voidabort()
protected virtual CallbackI *duplicateCallback()
protected IloEnvgetEnv()
protected IloModelgetModel()
protected IloIntgetNcols()
protected IloIntgetNQCs()
protected IloIntgetNrows()
protected virtual voidmain()
Method Detail

abort

protected void abort()

This method stops the current optimization.


duplicateCallback

protected virtual CallbackI * duplicateCallback()

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:


getEnv

protected IloEnv getEnv()

This method returns the environment belonging to the IloCplex object that invoked the method main.


getModel

protected IloModel getModel()

This method returns the model currently extracted for the instance of IloCplex where the invoking callback executed.


getNQCs

protected IloInt getNQCs()

This method returns the number of quadratic constraints in the model currently being optimized.


getNcols

protected IloInt getNcols()

This method returns the number of columns in the model currently being optimizated.


getNrows

protected IloInt getNrows()

This method returns the number of rows in the model currently being optimized.


main

protected virtual void main()

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.