Overview | Group | Tree | Graph | Index | Concepts |
This macro creates an instance of the class DemonClass
which
is a subclass of
IlcResourceDemon
.
When this demon is triggered, it
executes the function method
of the constraint ConstraintClass
given as parameter to the macro. The signature of this method must
be: void ConstraintClass::method(IlcResourceConstraint rct)
. The
resource constraint given as argument is the one that is
responsible for the triggering of the demon; for example, the
resource constraint whose set of successors has changed.
Once the resource demon class has been defined with the macro
ILCRESOURCEDEMON(DemonClass, ConstraintClass, method)
, an instance
of this demon can be created by passing an instance of
ConstraintClass
as a parameter as follows:
ConstraintClass* ct = ...; IlcResourceDemon myDemon = DemonClass(ct);
Example
The following code defines a couple of demons
PrintDemonSucc
and PrintDemonPred
that respectively print the new
successors and predecessors of any resource constraints whose set
of successors or predecessors has changed.
class PrintCtI :public IlcConstraintI { public: PrintCtI(IloSolver solver) :IlcConstraintI(solver){} void printNewSuccessors(IlcResourceConstraint changedRct) { getSolver().out() << "New successors of " << changedRct << ":" << endl; for (IlcResourceConstraintDeltaIterator ite(changedRct, IlcSuccessors); ite.ok(); ++ite) { getSolver().out() << "t" << *ite << endl; } } void printNewPredecessors(IlcResourceConstraint changedRct) { getSolver().out() << "New predecessors of " << changedRct << ":" << endl; for (IlcResourceConstraintDeltaIterator ite(changedRct, IlcPredecessors); ite.ok(); ++ite) { getSolver().out() << "t" << *ite << endl; } } }; ILCRESOURCEDEMON(PrintDemonSucc, PrintCtI, printNewSuccessors); ILCRESOURCEDEMON(PrintDemonPred, PrintCtI, printNewPredecessors); IloSolver solver ...; IlcResource resource ...; PrintCtI* printCt = new (solver) PrintCtI(solver); resource.whenSuccessors(PrintDemonSucc(printCt)); resource.whenPredecessors(PrintDemonPred(printCt));
See Also: