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.

Implementing Callbacks in <strong>ILOG</strong> <strong>CPLEX</strong> with Concert TechnologyCallbacks are accessed via the IloCplex::Callback handle class in the C++implementation of IloCplex. It points to an implementation object of a subclass ofIloCplex::CallbackI. In Java and .NET, there is no handle class and a programmerdeals only with implementation classes which are subclasses of IloCplex.Callback. Onesuch implementation class is provided for each type of callback. The implementation classprovides the functions that can be used for the particular callback as protected methods.To reflect the fact that some callbacks share part of their protected API, the callback classesare organized in a class hierarchy, as documented in the reference manuals of the APIs. Forexample, the class hierarchy of C++ callbacks is visible when you select Tree or Graph inthe reference manual of that API. Likewise, the class and interface hierarchy of Javacallbacks is visible when you select Tree in the reference manual of the Java API. Similarly,you can see the class and interface hierarchy of .NET callbacks in that reference manual.This hierarchy means that, for example, all functions available for the MIP callback are alsoavailable for the probing, fractional cut, and disjunctive cut callbacks. In particular, thefunction to abort the current optimization is provided by the class IloCplex::CallbackI(IloCplex.Callback in Java and Cplex.Callback in .NET) and is thus available to allcallbacks.There are two ways of implementing callbacks for IloCplex: a more complex way thatexposes all the C++ implementation details, and a simplified way that uses macros to handlethe C++ technicalities. Since Java and .NET do not provide macros, only the more complexway is available for Java or .NET users. This section first explains the more complex wayand discusses the underlying design. To implement your C or C++ callback quickly withoutdetails about the internal design, proceed directly to Writing Callbacks with Macros onpage 455.Writing Callback Classes by HandTo implement your own callback for IloCplex, first select the callback class correspondingto the callback you want implemented. From it derive your own implementation class andoverwrite the virtual method main. This is where you implement the callback actions, usingthe protected methods of the callback class from which you derived your callback or one ofits base classes.Next write a function that creates a new object of your implementation class using theenvironment operator new and returning it as an IloCplex::Callback handle object.Here is an example implementation of such a function:IloCplex::Callback MyCallback(IloEnv env, IloInt num) {return (new (env) MyCallbackI(num));}454 <strong>ILOG</strong> <strong>CPLEX</strong> <strong>11.0</strong> — USER’ S MANUAL

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

Saved successfully!

Ooh no, something went wrong!