Skip to main content
FRAMES NO FRAMES

Macro ILOCPGOALWRAPPER0

Definition file: ilcp/cpext.h
ILOCPGOALWRAPPER0(_this, solver)
ILOCPGOALWRAPPER1(_this, solver, t1, a1)
ILOCPGOALWRAPPER2(_this, solver, t1, a1, t2, a2)
ILOCPGOALWRAPPER3(_this, solver, t1, a1, t2, a2, t3, a3)
ILOCPGOALWRAPPER4(_this, solver, t1, a1, t2, a2, t3, a3, t4, a4)
ILOCPGOALWRAPPER5(_this, solver, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5)
Macro for wrapping a new goal class.

This macro defines a goal class named _thisI with n data members. When n is greater than zero, the types and names of the data members must be supplied as arguments to the macro. Each data member is defined by its type ti and a name ai.

You can use the macro ILOCPGOALWRAPPER to wrap an existing instance of IlcGoal when you want to use it within IBM® ILOG® Concert Technology model objects. In order to use an instance of IlcGoal in that way, you need to follow these steps:

  1. Use the macro to wrap the instance of IlcGoal in an instance of IloGoal.
  2. Use the IloGoal generated by IlcCPEngine::solve and IlcCPEngine:startNewSearch.

Example

Here's how to define a goal wrapper with one data member:

 ILOCPGOALWRAPPER1(MyGenerate, cp, IloIntVarArray, vars) {
   return IlcGenerate(cp.getIntVarArray(vars), IlcChooseMinSizeMin);
 }

That macro generates code similar to the following lines:

 class MyGenerateConcertI : public IloGoalI {
   IloIntVarArray vars ;
 public:
   MyGenerateConcertI (IloEnvI*, IloIntVarArray );
   ~MyGenerateConcertI ();
   virtual IlcGoal extract(const IloCPEngine) const;
 };

 MyGenerateConcertI::MyGenerateConcertI(IloEnvI* env,
                                     IloIntVarArray varsvars) :
   IloGoalI(env), vars (varsvars) {}

 MyGenerateConcertI::~MyGenerateConcertI () {}

 IloGoal MyGenerate (IloEnv env, IloIntVarArray varsvars) {
   return new (env) MyGenerateConcertI (env.getImpl(), varsvars);
 }

 IlcGoal MyGenerateConcertI::extract(const IloCPEngine solver) const {
   return IlcGenerate(cp.getIntVarArray(vars), IlcChooseMinSizeMin);
 }

The extraction of a goal does not extract and must not extract its arguments. Therefore, when using a goal you must make sure that the arguments will be extracted by the model. A good way to ensure this is to add the arguments to the models.

This is illustrated by the following example:

 IloEnv env;
 IloModel model(env);
 IloIntVarArray x(env, 3, 0, 10);
 model.add(x); // This is mandatory otherwise the variables will not be extracted
  solver(model);
 cp.solve(MyGenerate(env, x));
 env.end();

See Also: