12.07.2015 Views

ILOG CPLEX 11.0 User's Manual

ILOG CPLEX 11.0 User's Manual

ILOG CPLEX 11.0 User's 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.

It is not customary to write such a function for Java nor for .NET, but new is called explicitlyfor creating a callback object when needed. After an implementation object of your callbackis created (either with the constructor function in C++ or by directly calling the new operatorfor Java or .NET), use it with IloCplex by calling cplex.use with the callback object asan argument. In C++, to remove a callback that is being used by a cplex object, callcallback.end on the IloCplex::Callback handle callback. In Java or .NET, there is noway of removing individual callbacks from your IloCplex or Cplex object. Instead, youcan remove all callbacks by calling cplex.clearCallbacks. Since Java and .NET usegarbage collection for memory management, there is nothing equivalent to the end methodfor callbacks in the Java or .NET API.One object of a callback implementation class can be used with only one IloCplex objectat a time. Thus, when you use a callback with more than one cplex object, a copy of theimplementation object is created every time cplex.use is called except for the first time. InC++, the method IloCplex::use returns a handle to the callback object that has actuallybeen installed to enable calling end on it.To construct the copies of the callback objects in C++, class IloCplex::CallbackIdefines another pure virtual method:virtual IloCplex::CallbackI*IloCplex::CallbackI::duplicateCallback() const = 0;which must be implemented for your callback class. This method will be called to create thecopies needed for using a callback on different cplex objects or on one cplex object with aparallel optimizer.In most cases you can avoid writing callback classes by hand, using supplied macros thatmake the process as easy as implementing a function. You must implement a callback byhand only if the callback manages internal data not passed as arguments, or if the callbackrequires eight or more arguments.Writing Callbacks with MacrosThis is how to implement a callback using macros. Since macros are not supported in Javanor 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 tothe 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 isILOSIMPLEXCALLBACK1. Generally, for every callback type XXX and any number ofarguments n from 0 to 7, there is a macro called ILOXXXCALLBACKn. Table 30.2 lists thecallbacks and the corresponding macros and classes (where n is a placeholder for 0 to 7).<strong>ILOG</strong> <strong>CPLEX</strong> <strong>11.0</strong> — USER’ S MANUAL 455

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

Saved successfully!

Ooh no, something went wrong!