Overview | Group | Tree | Graph | Index | Concepts |
This macro defines a constraint 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 t
i and a name
a
i.
Since the argument this
is used to name the constraint
class, it is not possible to use the same name for several constraints.
You can use the macro ILOCPCONSTRAINTWRAPPER
to wrap an
existing instance of IlcConstraint
when you want to use it
within Concert Technology model objects. In order to use an instance of
IlcConstraint
in that way, you need to follow these steps:
IlcConstraint
in an instance of
IloConstraint
.
IloSolver
by calling the member function
IloSolver::extract
. During extraction,
IloSolver::extract
will put back the instance of
IloConstraint
.You must use the following IloCPConstraintI member functions to force extraction of an extractable or an array of extractables:
void use(const IloSolver solver, const IloExtractable ext)const; void use(const IloSolver solver, const IloExtractableArray extArray)const;
Example
Here's how to define a constraint wrapper with one data member:
ILOCPCONSTRAINTWRAPPER1(IloFreqConstraint, solver, IloIntVarArray, _vars) { use(solver, _vars); return IlcFreqConstraint(solver, solver.getIntVarArray(_vars)); }
In order to use IloSolver::getIntVarArray
, the object must
be extracted. To force extraction of an extractable or an array of
extractables, pass them as parameters of the use
method.
That macro generates code similar to the following lines:
class IloFreqConstraintI : public IloCPConstraintI { ILOCPCONSTRAINTWRAPPERDECL private: IloIntVarArray _vars; public: IloFreqConstraintI(IloEnvI*, const IloIntVarArray&, const char*); virtual IloExtractableI* makeClone(IloEnvI*) const; virtual void display(ostream & out) const; IlcConstraint extract(const IloSolver) const; }; ILOCPCONSTRAINTWRAPPERIMPL(IloFreqConstraintI) IloFreqConstraintI::IloFreqConstraintI(IloEnvI* env, const IloIntVarArray& T_vars, const char* name) : IloCPConstraintI (env, name), _vars ((IloIntVarArray&)T_vars) {} IloExtractableI* IloFreqConstraintI::makeClone(IloEnvI* env) const { IloIntVarArray targ1 = IloGetClone(env, _vars); return new (env) IloFreqConstraintI(env, (const IloIntVarArray &)targ1, (const char*)0); } void IloFreqConstraintI::display(ostream& out) const { out << "IloFreqConstraintI" << " ("; if (getName()) out << getName(); else out << getId(); out << ")" << endl; out << " " << "_vars" << " " << _vars << endl; } IloConstraint IloFreqConstraint(IloEnv env, IloIntVarArray _vars, const char* name=0) { IloFreqConstraintI::InitTypeIndex(); return new (env) IloFreqConstraintI(env.getImpl(), _vars, name); } IlcConstraint IloFreqConstraintI::extract(const IloSolver& solver) const { use(solver, _vars); return IlcFreqConstraint(solver, solver.getIntVarArray(_vars)); }
See Also: