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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

This return statement returns an And goal that first executes the Or goal and then the currentgoal itself specified by the this argument. When the Or goal is executed next, it will createtwo subnodes. In the first subnode, the first local cut goal representing var ≤ val(wherevar ≤valvaldenotes the floor of val) will be executed, thus adding the constraintfor the subtree of this node. Similarly, the second subnode will be created,and when executing its constraint goal the constraint var ≥ val + 1 will be added for thesubtree. this is then executed on each of the nodes that have just been created; the samegoal is used for both subtrees. Further details about how goals are processed are available inThe Goal Stack on page 435, Controlling Goal-Defined Search on page 440, and SearchLimits on page 444.Example: Goals in Branch & CutConsider the following example to clarify the discussions of goals. This example is availableas ilogoalex1.cpp in the examples/src subdirectory of your <strong>ILOG</strong> <strong>CPLEX</strong>distribution. The equivalent Java implementation can be found as GoalEx1.java in thesame location. The C#.NET version is in Goalex1.cs and the VB.NET version is inGoalex1.vb.This example shows how to implement and use a goal for controlling the branch strategyused by <strong>ILOG</strong> <strong>CPLEX</strong>. As discussed, goals are implemented as subclasses of the classIloCplex::GoalI (IloCplex.Goal or Cplex.Goal). The C++ implementation of thatexample uses the macroILO<strong>CPLEX</strong>GOAL1(MyBranchGoal, IloNumVarArray, vars)instead. This macro defines two things, class MyBranchGoalI and the functionIloCplex::Goal MyBranchGoal(IloEnv env, IloNumVarArray vars);The class MyBranchGoalI is defined as a subclass of class IloCplex::GoalI(IloCplex.Goal or Cplex.Goal) and has a private member IloNumVarArray vars.The function MyBranchGoal creates an instance of class MyBranchGoalI, initializes themember vars to the argument vars passed to the function, and returns a handle to the newgoal object. The curly brackets "{ ... }" following the macro enclose the implementation ofthe method MyBranchGoalI::execute containing the actual code of the goal.The use of the macro is very convenient as the amount of user code is equivalent to theamount for defining a function, but with a slightly unusual syntax. IloCplex provides sevensuch macros that can be used for defining goals with 0 to 6 private members. If more than 6members are needed, IloCplex::GoalI (IloCplex.Goal or Cplex.Goal) must besubclassed by hand.Since the Java programming language does not provide macros, a subclass ofIloCplex.Goal must always be implemented by hand. In this example, this class is called<strong>ILOG</strong> <strong>CPLEX</strong> <strong>11.0</strong> — USER’ S MANUAL 433

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

Saved successfully!

Ooh no, something went wrong!