Package org.openscience.cdk.group
Class Permutation
java.lang.Object
org.openscience.cdk.group.Permutation
A permutation with some associated methods to multiply, invert, and convert
to cycle strings. Much of the code in this was implemented from the
C.A.G.E.S. book [Kreher, Donald and Stinson, Douglas, Combinatorial Algorithms Generation Enumeration and Search, 1998, CRC Press].
- Author:
- maclean
- Belongs to CDK module:
- group
-
Constructor Summary
ConstructorsConstructorDescriptionPermutation
(int size) Constructs an identity permutation withsize
elements.Permutation
(int... values) Make a permutation from a set of values such that p[i] = x for the value x at position i.Permutation
(Permutation other) Construct a permutation from another one by cloning the values. -
Method Summary
Modifier and TypeMethodDescriptionboolean
int
Find an r such that this[r] != other[r].int
get
(int index) Get the value at this index.getOrbit
(int element) Get all the elements in the same orbit in the permutation (unsorted).int[]
Get all the values as an array.int
hashCode()
invert()
Invert the permutation, so that for all i : inv[p[i]] = i.boolean
Check to see if this permutation is the identity permutation.multiply
(Permutation other) Multiply this permutation by another such that for all i, this[i] = this[other[i]].void
set
(int index, int value) Set the value at the specified index.void
setTo
(Permutation other) Alter a permutation by setting it to the values in the other permutation.int
size()
Get the number of elements in the permutation.An easily-readable version of the permutation as a product of cycles.toString()
-
Constructor Details
-
Permutation
public Permutation(int size) Constructs an identity permutation withsize
elements.- Parameters:
size
- the number of elements in the permutation
-
Permutation
public Permutation(int... values) Make a permutation from a set of values such that p[i] = x for the value x at position i.- Parameters:
values
- the elements of the permutation
-
Permutation
Construct a permutation from another one by cloning the values.- Parameters:
other
- the other permutation
-
-
Method Details
-
equals
-
hashCode
public int hashCode() -
isIdentity
public boolean isIdentity()Check to see if this permutation is the identity permutation.- Returns:
- true if for all i, p[i] = i
-
size
public int size()Get the number of elements in the permutation.- Returns:
- the number of elements
-
get
public int get(int index) Get the value at this index.- Parameters:
index
- the permutation value at this index.- Returns:
- the value at this index
-
getValues
public int[] getValues()Get all the values as an array.- Returns:
- the values of the permutation
-
firstIndexOfDifference
Find an r such that this[r] != other[r].- Parameters:
other
- the other permutation to compare with- Returns:
- the first point at which the two permutations differ
-
getOrbit
Get all the elements in the same orbit in the permutation (unsorted).- Parameters:
element
- any element in the orbit- Returns:
- the list of elements reachable in this permutation
-
set
public void set(int index, int value) Set the value at the specified index.- Parameters:
index
- the index to set the valuevalue
- the value to set at this index
-
setTo
Alter a permutation by setting it to the values in the other permutation.- Parameters:
other
- the other permutation to use- Throws:
IllegalArgumentException
- thrown if the permutations are of different size
-
multiply
Multiply this permutation by another such that for all i, this[i] = this[other[i]].- Parameters:
other
- the other permutation to use- Returns:
- a new permutation with the result of multiplying the permutations
-
invert
Invert the permutation, so that for all i : inv[p[i]] = i.- Returns:
- the inverse of this permutation
-
toCycleString
An easily-readable version of the permutation as a product of cycles.- Returns:
- the cycle form of the permutation as a string
-
toString
-