Package net.sf.colossus.util
Class PermGen
- java.lang.Object
-
- net.sf.colossus.util.PermGen
-
class PermGen extends java.lang.Object
This class is a permutation generator. The permutations are generated using Dershowitz's method, meaning that a permutation only differs by the previous permutation by a single interchange of two adjacent elements. In many problem domains this allows a efficient dynamic update of a permutation function.- Author:
- Peter Unold
- See Also:
- Dershowitz's Permutation Generator
-
-
Constructor Summary
Constructors Constructor Description PermGen(int size)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int[]
getCurrent()
get the current permutationint
getNext()
generates the next permutation.static void
main(java.lang.String[] args)
Unit test for PermGen.
-
-
-
Method Detail
-
getNext
public int getNext()
generates the next permutation. If the function returns n, then the elements at position n and n + 1 in the previous permutation were interchanged to get the new permutation.- Returns:
- the index of the lower element which was interchanged or - 1 if the last permutation has been reached.
-
getCurrent
public int[] getCurrent()
get the current permutation
-
main
public static void main(java.lang.String[] args)
Unit test for PermGen.
-
-