Base class of user-written implementation classes of goals.
For a list of all members of this type, see Cplex.Goal Members.
System.Object
ILOG.CPLEX.Cplex.Goal
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
This is an advanced class.
Important:
Advanced classes typically demand a profound understanding of the algorithms used by ILOG CPLEX. Thus they incur a higher risk of incorrect behavior in your application, behavior that can be difficult to debug. Therefore, ILOG encourages you to consider carefully whether you can accomplish the same task by means of other classes instead.
Goals can be used to control the branch-and-cut search in Cplex
. In some respects, goals are an alternative to callbacks for controlling branch-and-cut search. Goals are implemented in subclasses of class Cplex.Goal
. Thus, this is the base class for user-written implementation classes of CPLEX goals. To implement your own goal, you need to create a subclass of Cplex.Goal
and implement its pure virtual method execute
. After implementing your goal class, you use it by calling the method Cplex.Solve(goal)
instead of the standard Cplex.Solve
without parameter.
The execute
method is called by Cplex
at each branch-and-cut node (referred to as the current node) after the node relaxation has been solved. Every node maintains a stack of goals, and the top goal from this stack is popped and executed until the stack becomes empty or some special goal is encountered as described below. When the goal stack of a node becomes empty, CPLEX continues with its built-in search for that subtree. When Cplex.Solve(goal)
is called, goal
is simply pushed on the goal stack of the root node before the branch-and-cut search begins.
The method Cplex.Goal.Execute
is where you can control the branch-and-cut search of Cplex
. Class Cplex.Goal
provides several methods for querying information about the current node. It is, however, the goal returned by the execute
method that determines how to proceed with the search. CPLEX provides several methods that create special goals that can be used to define the ongoing search in addition to any user-written goal:
Cplex.Or
creates a goal that will create child nodes when executed. One child will be created for every parameter passed to the method Cplex.Or
. Each child node will be initialized with a copy of the goal stack of the current node. Goals provided to the method Cplex.Or
as parameters are then pushed onto the goal stack of the corresponding child. Finally, the current node will be deleted and a new node will be picked from the tree for evaluation. Cplex.ConstraintGoal
with a constraint as its parameter as a local cut. When executed, the constraint will be added to the node problem for all nodes in that subtree. It will not, however, be added to nodes outside the subtree; use the method Cplex.GlobalCutGoal
for doing this. Other methods for creating constraint goals more conveniently are Cplex.LeGoal
, Cplex.GeGoal
, and Cplex.EqGoal
.Cplex.GlobalCutGoal
. When executed, they add a global cut to the model being solved.Cplex.And
takes several goals as parameters. When executed, it simply pushes these goals on the goal stack in reverse order so that they will be executed in the order they have been provided as parameters.Cplex.SolutionGoal
returns a goal that attempts to inject a solution into the branch-and-cut search.Cplex.BranchAsCplex
will cause CPLEX to continue with its own branching decision. This is different from continuing with an empty goal stack in that goals can still be executed at every node, thus maintaining the possibility of taking control at any time.Cplex.FailGoal
is executed, the current node will be pruned. That is, the search will be discontinued below the current node. If available, one of the remaining nodes from the branch-and-cut tree will be chosen for evaluation.null
, which will simply be ignored.Goals returned by Cplex.Or
and Cplex.And
allow you to combine goals. Cplex.And
allows you to execute different goals at one node, while Cplex.Or
allows you to execute different goals on different newly, created nodes. A typical use of these two goals in a return statement of a user written goal is:
return cplex.And ( cplex.Or (branch1, branch2), this);
The Cplex.And
goal first pushes this
, that is, the goal currently being executed, on the goal stack and then it pushes the Cplex.Or
goal. Thus the Cplex.Or
goal is on top of the stack and will be executed next. When the Cplex.Or
is executed, it creates two new nodes and copies the remaining goal stack to both of them. Thus both new nodes will have Cplex.Or
proceeds to push branch1
on the goal stack of the first child node and branch2
on the goal stack of the second goal child node. Typically, branch1
and branch2
would eventually contain constraint goals so by executing branch1
and branch2
at the respective child nodes, the child nodes will be restricted to represent smaller subproblems than their parent. After branch1
and branch2
have been executed this
is on top of the node stack of both child nodes, that is, both child nodes will continue branching according to the same rule. In summary, the above example creates branches described branch1
and branch2
and continues in both branches to control the same search strategy this
.
If the default implementation of method clone
is not adequate and the goal is to be used for parallel optimization, this method also needs to be implemented by the user. Recall that the default clone
method performs a shallow copy, so typically a user implementation would perform a deep copy for objects that should be local to threads or use the synchronize
keyword where synchronization is required.
For more information about goals see the chapter in the ILOG CPLEX User's Manual.
Namespace: ILOG.CPLEX
Assembly: ILOG.CPLEX (in ILOG.CPLEX.dll)