Class RandomPermutationCycle
java.lang.Object
org.uma.jmetal.util.sequencegenerator.impl.RandomPermutationCycle
- All Implemented Interfaces:
SequenceGenerator<Integer>
A sequence generator that produces random permutations of integers from 0 (inclusive) to the
specified size (exclusive). Each time the sequence is exhausted, a new random permutation is
generated.
This implementation uses an efficient algorithm to generate random permutations without repetition until all elements have been used, at which point a new random permutation is created.
Example usage:
// Will generate sequences like: [2,0,1,3,4], [1,3,2,0,4], [4,2,0,1,3], ...
SequenceGenerator<Integer> generator = new RandomPermutationCycle(5);
- Author:
- Antonio J. Nebro
-
Constructor Summary
ConstructorsConstructorDescriptionRandomPermutationCycle(int size) Creates a new random permutation cycle generator. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdvances the sequence to the next value.intReturns the length of the sequence before it repeats or resets.getValue()Returns the current value in the sequence.
-
Constructor Details
-
RandomPermutationCycle
public RandomPermutationCycle(int size) Creates a new random permutation cycle generator.- Parameters:
size- the size of the permutation (must be positive)- Throws:
IllegalArgumentException- if size is not positive
-
-
Method Details
-
getValue
Description copied from interface:SequenceGeneratorReturns the current value in the sequence.- Specified by:
getValuein interfaceSequenceGenerator<Integer>- Returns:
- the current value in the sequence
-
generateNext
public void generateNext()Description copied from interface:SequenceGeneratorAdvances the sequence to the next value. The behavior when called after reaching the end of the sequence is implementation-dependent. Some implementations may cycle back to the beginning, while others may generate new sequences.- Specified by:
generateNextin interfaceSequenceGenerator<Integer>
-
getSequenceLength
public int getSequenceLength()Description copied from interface:SequenceGeneratorReturns the length of the sequence before it repeats or resets.- Specified by:
getSequenceLengthin interfaceSequenceGenerator<Integer>- Returns:
- the number of unique values in the sequence before it repeats
-