30.01.2015 Views

ILOG CPLEX C++ API 9.0 Reference Manual

ILOG CPLEX C++ API 9.0 Reference Manual

ILOG CPLEX C++ API 9.0 Reference Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

IloCplex::CallbackI<br />

You do not create instances of this class; rather, you use one of its child classes to<br />

implement your own callback. In order to implement your user-written callbacks with an<br />

instance of IloCplex, you should follow these steps:<br />

◆<br />

◆<br />

◆<br />

Determine which kind of callback you want to write, and choose the appropriate<br />

class for it. The class hierarchy in Tree may give you some ideas here.<br />

Derive your own subclass, MyCallbackI, say, from the appropriate predefined<br />

callback class.<br />

In your subclass of the callback class, use the protected <strong>API</strong> defined in the base<br />

class to implement the main routine of your user-written callback. (All constructors<br />

of predefined callback classes are protected; they can be called only from userwritten<br />

derived subclasses.)<br />

◆ In your subclass, implement the method duplicateCallback.<br />

◆<br />

◆<br />

Write a function myCallback, say, that creates an instance of your<br />

implementation class in the Concert Technology environment and returns it as an<br />

IloCplex::Callback handle.<br />

Create an instance of your callback class and pass it to the member function use.<br />

Note: Macros ILOXXXCALLBACKn (for n from 0 to 7) are available to facilitate<br />

steps 2 through 5, where XXX stands for the particular callback under construction<br />

and n stands for the number of parameters that the function written in step 5 is to<br />

receive in addition to the environment parameter.<br />

You can use one instance of a callback with only one instance of IloCplex. When you<br />

use a callback with a second instance of IloCplex, a copy will be automatically<br />

created using the method duplicateCallback, and that copy will be used instead.<br />

Also, an instance of IloCplex takes account of only one instance of a particular<br />

callback at any given time. That is, if you call use more than once with the same class<br />

of callback, the last call overrides any previous one. For example, you can use only one<br />

primal simplex callback at a time, or you can use only one network callback at a time;<br />

and so forth.<br />

There are two varieties of callbacks:<br />

◆ Query callbacks enable your application to retrieve information about the current<br />

solution in an instance of IloCplex. The information available depends on the<br />

algorithm (primal simplex, dual simplex, barrier, mixed integer, or network) that you<br />

are using. For example, a query callback can return the current objective value, the<br />

number of simplex iterations that have been completed, and other details. Query<br />

<strong>ILOG</strong> <strong>CPLEX</strong> <strong>C++</strong> <strong>API</strong> <strong>9.0</strong> REFERENCE M ANUAL 99

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!