Package org.xcsp.common.enumerations
Class EnumerationOfPermutations
- java.lang.Object
-
- org.xcsp.common.enumerations.EnumerationAbstract
-
- org.xcsp.common.enumerations.EnumerationOfPermutations
-
- All Implemented Interfaces:
Iterator<int[]>
public class EnumerationOfPermutations extends EnumerationAbstract
This class allows us to iterate over all permutations of a given set of integer values. See the Johnson-Trotter algorithm (H. F. Trotter[1962], S. M. Johnson[1963]). Execute the main method for an illustration.
-
-
Field Summary
-
Fields inherited from class org.xcsp.common.enumerations.EnumerationAbstract
currTupleOfIdxs, indexesMatchValues, nextTuple
-
-
Constructor Summary
Constructors Constructor Description EnumerationOfPermutations(int nValues)
Builds an object that can be used for enumerating permutations, using the specified number of values.EnumerationOfPermutations(int... values)
Builds an object that can be used for enumerating permutations, using the specified array of values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
computeFirstTuple()
Computes the first tuple (called at reset time).boolean
hasNext()
static void
main(String[] args)
protected int
valAt(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
-
EnumerationOfPermutations
public EnumerationOfPermutations(int... values)
Builds an object that can be used for enumerating permutations, using the specified array of values.- Parameters:
values
- the values used to form permutations
-
EnumerationOfPermutations
public EnumerationOfPermutations(int nValues)
Builds an object that can be used for enumerating permutations, using the specified number of values. All values are taken in the range 0 tonValues-1
.- Parameters:
nValues
- the number of values used to form permutations
-
-
Method Detail
-
valAt
protected int valAt(int i)
Description copied from class:EnumerationAbstract
Returns the value of the current tuple at the specified position.- Specified by:
valAt
in 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:EnumerationAbstract
Computes the first tuple (called at reset time).- Specified by:
computeFirstTuple
in classEnumerationAbstract
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfaceIterator<int[]>
- Specified by:
hasNext
in classEnumerationAbstract
-
main
public static void main(String[] args)
-
-