Package org.moeaframework.core.variable
Class Permutation
java.lang.Object
org.moeaframework.core.variable.AbstractVariable
org.moeaframework.core.variable.Permutation
Decision variable for permutations.
- See Also:
 
- 
Nested Class Summary
Nested classes/interfaces inherited from interface org.moeaframework.core.Defined
Defined.ConstructorComparator - 
Field Summary
Fields inherited from class org.moeaframework.core.variable.AbstractVariable
name - 
Constructor Summary
ConstructorsConstructorDescriptionPermutation(int size) Constructs a permutation variable with the specified number of elements.Permutation(String name, int size) Constructs a permutation variable with the specified number of elements. - 
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates and returns a copy of this object.voidParses and loads the value of this variable from a string.encode()Encodes the value of this variable as a string.booleanvoidfromArray(int[] permutation) Sets the permutation array.intget(int index) Returns the value of the permutation at the specified index.Returns the string representation, or definition, of this object.static int[]getPermutation(Variable variable) Returns the value stored in a permutation decision variable.inthashCode()voidinsert(int i, int j) Removes thei-th element and inserts it at thej-th position.static booleanisPermutation(int[] permutation) Returnstrueif the specified permutation is valid;falseotherwise.voidRandomly assign the value of this variable.static voidsetPermutation(Variable variable, int[] values) Sets the value of a permutation decision variable.intsize()Returns the number of elements in this permutation.voidswap(int i, int j) Swaps thei-th andj-th elements in this permutation.int[]toArray()Returns a copy of the permutation array.toString()Returns a human-readable representation of this value.protected static voidvalidatePermutation(int[] permutation) Validate the given array is a permutation.Methods inherited from class org.moeaframework.core.variable.AbstractVariable
getName 
- 
Constructor Details
- 
Permutation
public Permutation(int size) Constructs a permutation variable with the specified number of elements.- Parameters:
 size- the number of elements in the permutation
 - 
Permutation
Constructs a permutation variable with the specified number of elements.- Parameters:
 name- the name of this decision variablesize- the number of elements in the permutation
 
 - 
 - 
Method Details
- 
copy
Description copied from interface:CopyableCreates and returns a copy of this object. It is required thatx.copy()is completely independent fromx. This means any method invoked onx.copy()in no way alters the state ofxand vice versa. It is typically the case thatx.copy().getClass() == x.getClass()andx.copy().equals(x).- Returns:
 - the copy
 
 - 
size
public int size()Returns the number of elements in this permutation.- Returns:
 - the number of elements in this permutation
 
 - 
get
public int get(int index) Returns the value of the permutation at the specified index.- Parameters:
 index- the index of the permutation value to be returned- Returns:
 - the permutation element at the specified index
 - Throws:
 ArrayIndexOutOfBoundsException- if the index is out of range[0, size()-1]
 - 
swap
public void swap(int i, int j) Swaps thei-th andj-th elements in this permutation.- Parameters:
 i- the first indexj- the second index- Throws:
 ArrayIndexOutOfBoundsException- ifiorjis out or range @{code [0, size()-1]}
 - 
insert
public void insert(int i, int j) Removes thei-th element and inserts it at thej-th position.- Parameters:
 i- the first indexj- the second index- Throws:
 ArrayIndexOutOfBoundsException- ifiorjis out or range @{code [0, size()-1]}
 - 
toArray
public int[] toArray()Returns a copy of the permutation array.- Returns:
 - a copy of the permutation array
 
 - 
fromArray
public void fromArray(int[] permutation) Sets the permutation array.- Parameters:
 permutation- the permutation array- Throws:
 IllegalArgumentException- if the permutation array is not a valid permutation
 - 
validatePermutation
protected static void validatePermutation(int[] permutation) Validate the given array is a permutation.- Parameters:
 permutation- the permutation array- Throws:
 IllegalArgumentException- if the permutation array is not a valid permutation
 - 
isPermutation
public static boolean isPermutation(int[] permutation) Returnstrueif the specified permutation is valid;falseotherwise.- Parameters:
 permutation- the permutation array- Returns:
 trueif the specified permutation is valid;falseotherwise
 - 
hashCode
public int hashCode()- Overrides:
 hashCodein classAbstractVariable
 - 
equals
- Overrides:
 equalsin classAbstractVariable
 - 
randomize
public void randomize()Description copied from interface:VariableRandomly assign the value of this variable. - 
getDefinition
Description copied from interface:DefinedReturns the string representation, or definition, of this object.- Returns:
 - the definition
 
 - 
toString
Description copied from interface:VariableReturns a human-readable representation of this value. - 
encode
Description copied from interface:VariableEncodes the value of this variable as a string. This should reflect the internal representation of the value and not necessarily the actual value. For example, a binary-encoded integer should display the bits and not the integer value.Implementations should make an effort to display the value in a meaningful format, but that is not required. Instead, use
Variable.toString()if a human-readable format is required.This method along with
Variable.decode(String)are used primarily for storing values in text files. To make parsing easier, the resulting string must:- Only contain ASCII characters
 - Contain no whitespace (no spaces, tabs, newlines, etc.)
 
- Returns:
 - the encoded value as a string
 
 - 
decode
Description copied from interface:VariableParses and loads the value of this variable from a string. This must be able to process any string produced byVariable.encode().- Parameters:
 value- the value as a string
 - 
getPermutation
Returns the value stored in a permutation decision variable.- Parameters:
 variable- the decision variable- Returns:
 - the value stored in a permutation decision variable
 - Throws:
 IllegalArgumentException- if the decision variable is not of typePermutation
 - 
setPermutation
Sets the value of a permutation decision variable.- Parameters:
 variable- the decision variablevalues- the permutation to assign the permutation decision variable- Throws:
 IllegalArgumentException- if the decision variable is not of typePermutationIllegalArgumentException- ifvaluesis not a valid permutation
 
 -