| Overview | Group | Tree | Graph | Deprecated | 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 ti and a name
ai.
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 IBM® ILOG® 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.
IloCP by calling the member function
IloCP::extract. During extraction,
IloCP::extract will put back the instance of
IloConstraint.You must use the following IloCPConstraintI member
functions to force extraction of a variable or an array of variables:
void use(const IloCPEngine solver, const IloNumVar x) const; void use(const IloCPEngine solver, const IloIntervalVar x) const; void use(const IloCPEngine solver, const IloIntervalSequenceVar x) const; void use(const IloCPEngine solver, const IloNumVarArray xa) const; void use(const IloCPEngine solver, const IloIntervalVarArray xa) const; void use(const IloCPEngine solver, const IloIntervalSequenceVarArray xa) const;
Each object type passed as a parameter must be processable by an
object of type std::ostream (needed for the display
member function - see example below). If needed, you can do
this by writing code like the following code for some type MyType
used in the constraint wrapper. Note that most Concert Technology
objects already have this capability.
std::ostream& operator << (std::ostream& out, const MyType& myObj) {
// ... insert code for displaying myObj ...
return out;
}
Example
Here's how to define a constraint wrapper with one data member:
ILOCPCONSTRAINTWRAPPER1(IloFreqConstraint, cp, IloIntVarArray, _vars) {
use(cp, _vars);
return IlcFreqConstraint(cp, cp.getIntVarArray(_vars));
}In order to use IloCPEngine::getIntVarArray, the array must
be extracted. To force extraction of an extractable or an array of
extractables, pass them as parameters of the use method.
The 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 IloCPEngine) 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 << ")" << std::endl;
out << " " << "_vars" << " " << _vars <<
std::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 IloCPEngine& cp) const
{
use(cp, _vars);
return IlcFreqConstraint(cp, cp.getIntVarArray(_vars));
}
See Also: