| Overview | Group | Tree | Graph | Deprecated | Index | Concepts |

Goals are the building blocks of custom search algorithms in CP Optimizer.
Goals depend on two classes: IlcGoal and IlcGoalI. The class IlcGoal is the handle class. An instance of the class
IlcGoal contains a data member (the handle
pointer) that points to an instance of the class IlcGoalI (the
implementation object) allocated on the CP Optimizer heap.
For goals to use in an IBM® ILOG® Concert Technology model, see
IloGoal.
If you define a new class of goals for use during a CP Optimizer
search, you must define the implementation class together with the
corresponding virtual member function, execute, and a function
that returns an instance of the handle class IlcGoal.
A goal can be defined in terms of other goals, called its
subgoals. See the functions IlcAnd
and IlcOr for examples. A subgoal is
not executed immediately. In fact, it is added to the goal stack,
and the execute member function of the current goal terminates
before the subgoal is executed. When the execution of the goal itself is
complete, the subgoal will be returned.
A goal can also be defined as a choice between other goals. This choice
is implemented by the function IlcOr.
For more information, see the concept Goals in CP Optimizer.
See Also:
| Method Summary | |
|---|---|
public virtual IlcGoal | execute() |
public void | fail(IlcAny label) |
public void | fail() |
public IlcCPEngine | getCPEngine() const |
public | IlcGoalI(IlcCPEngine solver) |
| Method Detail |
|---|
This constructor creates a goal implementation. This constructor should not be called directly because this is an abstract class. This constructor is called automatically in the constructors of its subclasses.
This member function must be redefined when you derive a new subclass of IlcGoalI.
This member function is called when the invoking goal is popped from the goal stack and executed.
This member function should return 0 if the invoking goal has no subgoals. Otherwise it should
return the subgoal of the goal.
Example
Here's how to define a class of goals without subgoals. This goal merely prints the integer passed as its argument.
class PrintXI :public IlcGoalI {
IlcInt x;
public:
PrintXI(IlcCPEngine cp, IlcInt xx): IlcGoalI(cp), x(xx){}
~PrintXI(){}
IlcGoal execute() {
IlcCPEngine cp = getCPEngine();
cp.out() << "PrintX: a goal with one data member" << std::endl;
cp.out() << x << std::endl;
return 0;
}
};
IlcGoal PrintX(IlcCPEngine cp, IlcInt x) {
return new (cp.getHeap()) PrintXI(cp, x);
}The macro ILCGOAL makes it easier to define goals.
Here's an example of a goal with one subgoal:
ILCGOAL0(Print){
IlcCPEngine cp = getCPEngine();
cp.out() << "before one subgoal" << std::endl;
return PrintX(cp,2);
}A goal can also be defined as a choice between other goals. This choice is implemented by the
function IlcOr. For example, the following goal has three choices:
ILCGOAL0(PrintOne) {
IlcCPEngine cp = getCPEngine();
cp.out() << "print one" << std::endl;
return IlcOr(PrintX(cp,1), PrintX(cp,2), PrintX(cp,3)));
}This member function causes the invoking goal to fail. The argument label
makes the invoking goal fail at the choice point named label.
This member function causes the invoking goal to fail.
This member function returns the engine object passed at the construction of the goal.