KACBinConstraint¶
-
class KACBinConstraint : public KConstraint¶
This class implements a generic class for propagation of any binary constraint by local 2-consistency (arc consistency) \ Two algorithms (AC3 and AC2001) are available for propagation of the constraint.
Example : X == Y + C
class XEqualYC : public KACBinConstraint { int _C; public: XEqualYC(const char* name, KIntVar& v1, KIntVar& v2, int cst) : KACBinConstraint(v1, v2, KACBinConstraint::ALGORITHM_AC2001, "XEqualYC") { _C = cst; } virtual bool testIfSatisfied(int valX, int valY) { return (valX == valY + _C); // the constraint is true if only iff valX == valY + C } };
- See
- Since
2016.1
Public Types
Public Functions
-
KACBinConstraint(KIntVar &v1, KIntVar &v2, int acAlgorithm = ALGORITHM_AC2001, const char *name = 0)¶
Constructor. This constructor takes threee arguments
- Parameters
v1 – the first variable of the constraint
v2 – the second variable of the constraint
acAlgorithm – ALGORITHM_AC2001 (default value) for propagation by the AC2001 algorithm , ALGORITHM_AC3 for propagation by the AC3 algorithm
name – label for pretty printing of the constraint
-
virtual bool testIfSatisfied(int val1, int val2)¶
Abstract interface for generic propagation of any binary constraint
- Returns
true if and only if the constraint is satisfied when v1 == val1 & v2 == val2
-
virtual KACBinConstraint *getInstanceCopyPtr(const KProblem &problem) const¶
Virtual copy method. Each modeling elements stored (and used) in the binary constraint must be copied using the KProblem::getCopyPtr() method.