Often, in a problem, a set of objects must satisfy similar constraints. In these cases, it is worth trying to use generic constraints, that is, constraints that are shared by several constrained variables. Since generic constraints are shared, they may save a lot of memory. For instance, the constraint IloAllDiff
is a generic constraint: only one constraint is allocated, whatever the number of variables in the array it constrains.
In fact, there are two ways in Solver to implement such a constraint: as a generic constraint or as a class constraint.
-
generic constraint: the constraint has a data member containing the array of constrained variables sharing the constraint;
-
class constraint: the constructor for the class posts the constraint on each instance of the given class.