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.

The Java implementation of the callback is quite similar:public static class Callback extends IloCplex.CutCallback {double eps = 1.0e-6;IloRange[] cut;Callback(IloRange[] cuts) { cut = cuts; }}public void main() throws IloException {int num = cut.length;for (int i = 0; i < num; ++i) {if ( cut[i] != null ) {double val = getValue(cut[i].getExpr());if ( cut[i].getLB() > val+eps || val-eps > cut[i].getUB() ) {add(cut[i]);cut[i] = null;}}}}Instead of receiving expressions and righthand side values, the application directly passes anarray of IloRange constraints to the callback; the constraints are stored in cut. The mainloops over all cuts and evaluates the constraint expressions at the current solution by callinggetValue(cut[i].getExpr). If this value exceeds the constraint bounds by more thaneps, the cut is added during the search by a call to add(cut[i]) and cut[i] is set to nullto avoid unneccessarily evaluating it again.As for the C++ implementation, the array of cuts passed to the callback is initialized in aseparate function makeCuts. The callback is then created and used to with the noswot cutsby calling.cplex.use(new Callback(makeCuts(cplex, lp)));IloCplex provides an easier way to manage such cuts in a case like this, where all cuts canbe easily enumerated before starting the optimization. Calling the methods cplex.addCutand cplex.addCuts allows you to copy the cuts to IloCplex before the optimization.Thus, instead of creating and using the callback, a user could have written:cplex.addCuts(makeCuts(var));as shown in example iloadmipex4.cpp in the distribution. During branch & cut,<strong>ILOG</strong> <strong>CPLEX</strong> will consider adding individual cuts to its representation of the model only ifthey are violated by a node LP solution in about the same way this example handles them.Whether this or adding the cuts directly to the model gives better performance when solvingthe model depends on the individual problem.The complete program iloadmipex5.cpp appears online in the standard distribution atyour<strong>CPLEX</strong>installation/examples/src.The Java version is found in fileAdMIPex5.java at the same location. The C#.NET implementation is in AdMIPex5.csand the VB.NET implementation is in AdMIPex5.vb.466 <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!