public class Permutor extends Object
0 [0, 1, 2] 1 [0, 2, 1] 2 [1, 0, 2] ...where the number to the left of each permutation is the rank - really just the index in this ordered list. The list is created on demand, by a process called unranking where the rank is converted to the permutation that appears at that point in the list.
The algorithms used are from the book "Combinatorial Generation : Algorithms, Generation, and Search" (or C.A.G.E.S.) by D.L. Kreher and D.R. Stinson. CRC Press (18 Dec 1998). ISBN-13 : 978-0849339882.
Constructor and Description |
---|
Permutor(int size)
Create a permutor that will generate permutations of numbers up to
size . |
Modifier and Type | Method and Description |
---|---|
int |
calculateMaxRank()
Calculate the max possible rank for permutations of N numbers.
|
int[] |
getCurrentPermutation()
Get the permutation that is currently being used.
|
int[] |
getNextPermutation()
Get the next permutation in the list.
|
int[] |
getRandomNextPermutation()
Randomly skip ahead in the list of permutations.
|
int |
getRank()
Get the current rank.
|
boolean |
hasNext() |
void |
setPermutation(int[] permutation)
Set the currently used permutation.
|
void |
setRank(int rank)
Set the permutation to use, given its rank.
|
public Permutor(int size)
size
.size
- the size of the permutations to generatepublic boolean hasNext()
public void setRank(int rank)
rank
- the order of the permutation in the listpublic void setPermutation(int[] permutation)
permutation
- the permutation to use, as an int arraypublic int getRank()
public int[] getRandomNextPermutation()
public int[] getNextPermutation()
public int[] getCurrentPermutation()
public int calculateMaxRank()
Copyright © 2018. All Rights Reserved.