FRAMES NO FRAMES

Class IlcGoalI

Definition file: ilsolver/basic.h
Include file: <ilsolver/ilosolver.h>

Goals are the building blocks of search algorithms in Solver. Goals as they are represented in a Solver search (for example, inside a constraint or inside another goal) 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 Solver 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 Solver 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 Goal.

See Also:

Constructor and Destructor Summary
public IlcGoalI(IloSolver solver)
Method Summary
public virtual IlcGoalexecute()
public voidfail(IlcAny label=0)
public IloSolvergetSolver() const
public IloSolverI *getSolverI() const
public virtual IlcBoolisAConstraint() const
Constructor and Destructor Detail

IlcGoalI

public IlcGoalI(IloSolver solver)

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.


Method Detail

execute

public virtual IlcGoal execute()

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(IloSolver s, IlcInt xx): IlcGoal(s), x(xx){}
     ~PrintXI(){}
     IlcGoal execute() {
         IloSolver s = getSolver();
         s.out() << "PrintX: a goal with one data member" << endl;
         s.out() << x << endl;
         return 0;
     }
 };

 IlcGoal PrintX(IloSolver s, IlcInt x) {
     return new (s.getHeap()) PrintXI(s, x);
 }

The macro ILCGOAL makes it easier to define goals.

Here's an example of a goal with one subgoal:

 ILCGOAL0(Print()){
     IloSolver s = getSolver();
     s.out() << "before one subgoal" << endl;
     return PrintX(s,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) {
     IloSolver s = getSolver();
     s.out() << "print one" << endl;
     return IlcOr(PrintX(s,1), PrintX(s,2), PrintX(s,3)));
 }

fail

public void fail(IlcAny label=0)

This member function causes the invoking goal to fail. The optional argument label makes the invoking goal fail at the choice point named label.


getSolver

public IloSolver getSolver() const

This member function returns the solver (a handle) of the invoking goal implementation.


getSolverI

public IloSolverI * getSolverI() const

This member function returns a pointer to the implementation object of the solver where the invoking goal was extracted.


isAConstraint

public virtual IlcBool isAConstraint() const

This member function lets you know whether the active demon is a constraint (in that case, it returns IlcTrue or a goal (in that case, it returns IlcFalse).