Package org.xcsp.common.enumerations
Class EnumerationCartesian
- java.lang.Object
-
- org.xcsp.common.enumerations.EnumerationAbstract
-
- org.xcsp.common.enumerations.EnumerationCartesian
-
- All Implemented Interfaces:
Iterator<int[]>
- Direct Known Subclasses:
EnumerationOfCombinations
public class EnumerationCartesian extends EnumerationAbstract
This class allows iterating over all tuples of a given length from a given set of numbers (of possibilities at each position). Execute the main method for an illustration.
-
-
Field Summary
Fields Modifier and Type Field Description protected int[][]valuesGives the sets of values on which the tuples will be built.-
Fields inherited from class org.xcsp.common.enumerations.EnumerationAbstract
currTupleOfIdxs, indexesMatchValues, nextTuple
-
-
Constructor Summary
Constructors Constructor Description EnumerationCartesian(int... nValues)Builds an object that can be used for enumerating tuples, using the specified numbers of values.EnumerationCartesian(int[][] values)Builds an object that can be used for enumerating tuples, using the specified sets of values.EnumerationCartesian(int[][] values, boolean clone)Builds an object that can be used for enumerating tuples, using the specified sets of values.EnumerationCartesian(int nValues, int tupleLength)Builds an object that can be used for enumerating tuples, using the specified numbers of values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcomputeFirstTuple()Computes the first tuple (called at reset time).booleanhasNext()static voidmain(String[] args)static int[][]tuplesWithDiffValuesSummingTo(int limit, int nValues, int tupleLength, int offset)Returns an array with all tuples of the specified length such that for each tuple: at each position, a value is between 0 (inclusive) andnValues(exclusive) all values are all different the sum of the values in the tuple is equal to the specified limitprotected intvalAt(int i)Returns the value of the current tuple at the specified position.-
Methods inherited from class org.xcsp.common.enumerations.EnumerationAbstract
displayAllTuples, execute, next, reset, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Constructor Detail
-
EnumerationCartesian
public EnumerationCartesian(int[][] values, boolean clone)Builds an object that can be used for enumerating tuples, using the specified sets of values. If the specified Boolean istruethe specified 2-dimensional array is cloned.- Parameters:
values- the sets of values on which the tuples will be builtclone- iftruethe specified 2-dimensional array is cloned
-
EnumerationCartesian
public EnumerationCartesian(int[][] values)
Builds an object that can be used for enumerating tuples, using the specified sets of values.- Parameters:
values- the sets of values on which the tuples will be built
-
EnumerationCartesian
public EnumerationCartesian(int... nValues)
Builds an object that can be used for enumerating tuples, using the specified numbers of values. Each tuple will contain a value at positioniin the range 0 tonValues[i].length-1.- Parameters:
nValues- indicates how many values are possible at each position
-
EnumerationCartesian
public EnumerationCartesian(int nValues, int tupleLength)Builds an object that can be used for enumerating tuples, using the specified numbers of values. Each tuple has the specified length and will contain a value at positioniin the range 0 tonValues-1.- Parameters:
nValues- the number of values used to form tuplestupleLength- the length of each tuple
-
-
Method Detail
-
tuplesWithDiffValuesSummingTo
public static int[][] tuplesWithDiffValuesSummingTo(int limit, int nValues, int tupleLength, int offset)Returns an array with all tuples of the specified length such that for each tuple:- at each position, a value is between 0 (inclusive) and
nValues(exclusive) - all values are all different
- the sum of the values in the tuple is equal to the specified limit
- Parameters:
limit- the integer denoting the limit of the sumnValues- indicates how many values are possible at each positiontupleLength- the length of each tuple in the enumerationoffset- the value that must be systematically added to each value of each tuple- Returns:
- an array with all tuples of the specified length that respect a sum equality and an allDifferent restriction
- at each position, a value is between 0 (inclusive) and
-
valAt
protected int valAt(int i)
Description copied from class:EnumerationAbstractReturns the value of the current tuple at the specified position.- Specified by:
valAtin classEnumerationAbstract- Parameters:
i- the position of an integer in the tuple- Returns:
- the value of the current tuple at the specified position
-
computeFirstTuple
protected void computeFirstTuple()
Description copied from class:EnumerationAbstractComputes the first tuple (called at reset time).- Specified by:
computeFirstTuplein classEnumerationAbstract
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfaceIterator<int[]>- Specified by:
hasNextin classEnumerationAbstract
-
main
public static void main(String[] args)
-
-