org.openscience.cdk.group

## Class Permutation

• ```public final class Permutation
extends Object```
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

Constructors
Constructor and Description
`Permutation(int... values)`
Make a permutation from a set of values such that p[i] = x for the value x at position i.
`Permutation(int size)`
Constructs an identity permutation with `size` elements.
`Permutation(Permutation other)`
Construct a permutation from another one by cloning the values.
• ### Method Summary

Methods
Modifier and Type Method and Description
`boolean` `equals(Object other)`
`int` `firstIndexOfDifference(Permutation other)`
Find an r such that this[r] != other[r].
`int` `get(int index)`
Get the value at this index.
`List<Integer>` `getOrbit(int element)`
Get all the elements in the same orbit in the permutation (unsorted).
`int[]` `getValues()`
Get all the values as an array.
`int` `hashCode()`
`Permutation` `invert()`
Invert the permutation, so that for all i : inv[p[i]] = i.
`boolean` `isIdentity()`
Check to see if this permutation is the identity permutation.
`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.
`String` `toCycleString()`
An easily-readable version of the permutation as a product of cycles.
`String` `toString()`
• ### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### Permutation

`public Permutation(int size)`
Constructs an identity permutation with `size` 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

`public Permutation(Permutation other)`
Construct a permutation from another one by cloning the values.
Parameters:
`other` - the other permutation
• ### Method Detail

• #### equals

`public boolean equals(Object other)`
Overrides:
`equals` in class `Object`
• #### hashCode

`public int hashCode()`
Overrides:
`hashCode` in class `Object`
• #### 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

`public int firstIndexOfDifference(Permutation other)`
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

`public List<Integer> getOrbit(int element)`
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 value
`value` - the value to set at this index
• #### setTo

`public void setTo(Permutation other)`
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

`public Permutation multiply(Permutation other)`
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

`public Permutation invert()`
Invert the permutation, so that for all i : inv[p[i]] = i.
Returns:
the inverse of this permutation
• #### toCycleString

`public String toCycleString()`
An easily-readable version of the permutation as a product of cycles.
Returns:
the cycle form of the permutation as a string
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`