An implementation of the array of cardinalities for the integer expressions. One can use
IntArrayCards
to control the number of occurences of several values among the constrained variables in an array of constrained variables. There is a simle example explaining the idea of using
IntExpArray
:
Constariner C = new Constrainer('IntArrayCards_Test'); IntExpArray array = new IntExpArray(C,10,0,9,'array'); IntArrayCards cards = new IntArrayCards(C,array); for (int i=0; i < (array.max()-array.min()+1); i++){ IntExp acard = cards.cardAt(i); C.postConstraint(acard.eq(1)); }
Here states that each integer value from the interval [0,9] must occure in the "array" exactly once. So one can readily guess that the only possible solution is array[i] == i, correct to permutations of the array's elements.
IntArrayCards
has the only constructor {@link #IntArrayCards(Constrainer,IntExpArray)}. After being created
IntArrayCards
becomes one to perform a policy of checking the number of occurrences of every possible value among the constrained variables of IntExpArray using the "cards" array. "cards" is an IntExpArray consisting of (array.max() - array.min() + 1) elements (array is an IntExpArray to be controlled) so that it's i-th element defines the cardinality of i+array.min() value. In other words, the number of occurrences must be within the interval [cards.get(i).min(), cards.get(i).max()]. One can gain the access to the particular card by using {@link #cardAt(int)} method.