Package org.ejml.dense.row.misc
Class PermuteArray
- java.lang.Object
-
- org.ejml.dense.row.misc.PermuteArray
-
public class PermuteArray extends java.lang.ObjectGenerates a permutations of an integer set from 0 to N-1. This can either be generated all at once as a list of one at a time.
-
-
Constructor Summary
Constructors Constructor Description PermuteArray(int N)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.List<int[]>createList(int N)Creates a list of all permutations for a set with N elements.static intfact(int N)Computes N factorialint[]next()Creates the next permutation in the sequence.intsgn()Returns signature of the permutation.
-
-
-
Method Detail
-
sgn
public int sgn()
Returns signature of the permutation. This is the sgn() operator and returns -1 or 1 depending on it being odd or even.
sgn(σ) = ( − 1)m
where m is the number of inversions.NOTE: This implementation is painfully slow O(N!). There is probably another algorithm out there which is much faster.
- Returns:
- -1 or 1 for odd or even permutations.
-
fact
public static int fact(int N)
Computes N factorial
-
createList
public static java.util.List<int[]> createList(int N)
Creates a list of all permutations for a set with N elements.- Parameters:
N- Number of elements in the list being permuted.- Returns:
- A list containing all the permutations.
-
next
public int[] next()
Creates the next permutation in the sequence.- Returns:
- An array containing the permutation. The returned array is modified each time this function is called.
-
-