FRAMES NO FRAMES

Macro ILOCPGOALWRAPPER0

Definition file: ilsolver/ilosolverint.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)

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 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 IloSolver::solve and IloSolver:startNewSearch.

Example

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

 ILOCPGOALWRAPPER1(MyGenerate, solver, IloIntVarArray, vars) {
   return IlcGenerate(solver.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 IloSolver) const;
   virtual IloGoalI* makeClone(IloEnvI*) const;
 };

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

 MyGenerateConcertI::~MyGenerateConcertI () {}

 IloGoalI* MyGenerateConcertI::makeClone(IloEnvI* env) const {
   IloIntVarArray na1 = IloGetClone(env, vars);
   return new (env) MyGenerateConcertI(env, na1);
 }

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

 IlcGoal MyGenerateConcertI::extract(const IloSolver solver) const {
   return IlcGenerate(solver.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);
 IloIntVar x(env, 0, 10);
 model.add(x); // This is mandatory otherwise the variable will not be
 extracted
 IloSolver solver(model);
 solver.solve(IloInstantiate(env, x));
 env.end();

See Also: