MOEA Framework 2.5
API Specification

org.moeaframework.core.variable
Class Permutation

java.lang.Object
  extended by org.moeaframework.core.variable.Permutation
All Implemented Interfaces:
Serializable, Variable

public class Permutation
extends Object
implements Variable

Decision variable for permutations.

See Also:
Serialized Form

Constructor Summary
Permutation(int size)
          Constructs a permutation variable with the specified number of elements.
Permutation(int[] permutation)
          Constructs a permutation variable using the specified permutation array.
 
Method Summary
 Permutation copy()
          Returns an independent copy of this decision variable.
 boolean equals(Object obj)
          Indicates whether some other object is "equal to" this one.
 void fromArray(int[] permutation)
          Sets the permutation array.
 int get(int index)
          Returns the value of the permutation at the specified index.
 int hashCode()
          Returns a hash code value for the object.
 void insert(int i, int j)
          Removes the ith element and inserts it at the jth position.
static boolean isPermutation(int[] permutation)
          Returns true if the specified permutation is valid; false otherwise.
 int size()
          Returns the number of elements in this permutation.
 void swap(int i, int j)
          Swaps the ith and jth elements in this permutation.
 int[] toArray()
          Returns a copy of the permutation array.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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

public Permutation(int[] permutation)
Constructs a permutation variable using the specified permutation array.

Parameters:
permutation - the permutation array
Throws:
IllegalArgumentException - if the permutation array is not a valid permutation
Method Detail

copy

public Permutation copy()
Description copied from interface: Variable
Returns an independent copy of this decision variable. It is required that x.copy() is completely independent from x. This means any method invoked on x.copy() in no way alters the state of x and vice versa. It is typically the case that x.copy().getClass() == x.getClass() and x.copy().equals(x).

Specified by:
copy in interface Variable
Returns:
an independent copy of this decision variable

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:
ArrayOutOfBoundsException - if the index is out of range [0, size()-1]

swap

public void swap(int i,
                 int j)
Swaps the ith and jth elements in this permutation.

Parameters:
i - the first index
j - the second index
Throws:
ArrayIndexOutOfBoundsException - if i or j is out or range @{code [0, size()-1]}

insert

public void insert(int i,
                   int j)
Removes the ith element and inserts it at the jth position.

Parameters:
i - the first index
j - the second index
Throws:
ArrayIndexOutOfBoundsException - if i or j is 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

isPermutation

public static boolean isPermutation(int[] permutation)
Returns true if the specified permutation is valid; false otherwise.

Parameters:
permutation - the permutation array
Returns:
true if the specified permutation is valid; false otherwise

hashCode

public int hashCode()
Description copied from class: java.lang.Object
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

The general contract of hashCode is:

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), Hashtable

equals

public boolean equals(Object obj)
Description copied from class: java.lang.Object
Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
Object.hashCode(), Hashtable

MOEA Framework 2.5
API Specification

Copyright 2009-2015 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Hosted by Get MOEA Framework at SourceForge.net. Fast, secure and Free Open Source software downloads