Skip to main content
FRAMES NO FRAMES

IlcOr

public IlcGoal IlcOr(const IlcGoal g1, const IlcGoal g2, IlcAny label=0)
public IlcGoal IlcOr(const IlcGoal g1, const IlcGoal g2, const IlcGoal g3, IlcAny label=0)
public IlcGoal IlcOr(const IlcGoal g1, const IlcGoal g2, const IlcGoal g3, const IlcGoal g4, IlcAny label=0)
public IlcGoal IlcOr(const IlcGoal g1, const IlcGoal g2, const IlcGoal g3, const IlcGoal g4, const IlcGoal g5, IlcAny label=0)
Definition file: ilcp/cpext.h
Include file: <ilcp/cpext.h>
Returns a goal that is a choice point.

A goal can be defined as a choice between other goals. The function IlcOr implements a goal as a choice between subgoals (between two and five subgoals). When this goal is executed, the state of CP Optimizer, including the state of the goal stack, is saved. This activity is called setting a choice point. Then all the subgoals are saved as untried subgoals of the choice point. Then the first untried subgoal is removed from the set of untried subgoals of the choice point and is called. If it fails, the state of CP Optimizer is restored and the next untried subgoal is called, and so on, until either a subgoal succeeds or until no more untried subgoals remain. In the latter case, the choice point itself fails. If the optional argument, label, is given, the choice point is labeled with it. The apparent limitation to five subgoals can be overcome by several calls to IlcOr since it is associative.

If a goal is null (that is, if its implementation is null), it will be silently transformed into a goal that always succeeds.

Examples:

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)));
 }

Here is how to define a choice point with eight subgoals:

 IlcOr(IlcOr(g1, g2, g3, g4, g5),
             IlcOr(g6, g7, g8));

For more information, see the concepts Goal Goals in CP Optimizer and Choice point in CP Optimizer .

See Also: