net.openai.ai.ga.cell.encoding
Class StrictPermutation

java.lang.Object
  |
  +--net.openai.ai.ga.cell.encoding.StrictPermutation

public class StrictPermutation
extends java.lang.Object

The StrictPermutation class stores a permutation of values from 0 to (length-1). All values are represented, however it is their order that is of interest. This class supports cross-over and mutation. the maximum for the list in

Since:
JDK1.3
Version:
%I%, %G%
Author:
Jared Grubb

Constructor Summary
StrictPermutation(StrictPermutation toClone)
          Creates and returns a clone of the given StrictPermutation.
StrictPermutation(java.lang.String name, int length)
          Creates a new StrictPermutation with the specified length and given name.
StrictPermutation(java.lang.String name, int length, int[] vals)
          Creates a new StrictPermutation initialized with the specified capacity and starting with the values in the passed integer array so far as is possible using setListLoosely.
 
Method Summary
static StrictPermutation cross(StrictPermutation first, StrictPermutation second)
          Returns a new StrictPermutation based on two other permutations of the same length.
 int getElement(int element)
          Returns the value of a certain element in the permutation
 int getLength()
          Returns the length of this permutation list
 int[] getList()
          Returns this permutation as a int[].
 java.lang.String getName()
          Returns the name of this permutation list
 void mutate(int amount)
          Mutates a given number of elements in the permutation.
 void setLength(int size)
          Sets the length of this permutation.
 void setList(int[] list)
          Sets the permutation to the values in the given list.
 void setListLoosely(int[] list)
          Sets the permutation to the values in the given list when possible.
 void setListLoosely(int[] list, int start)
          Sets the permutation to the values in the given list when possible starting from a given position.
 void setName(java.lang.String name)
          Sets the name of this permutation
 java.lang.String toString()
          Method declaration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StrictPermutation

public StrictPermutation(java.lang.String name,
                         int length)
Creates a new StrictPermutation with the specified length and given name.

Parameters:
name - a String representing the string's name
length - the number of elements in this list

StrictPermutation

public StrictPermutation(java.lang.String name,
                         int length,
                         int[] vals)
Creates a new StrictPermutation initialized with the specified capacity and starting with the values in the passed integer array so far as is possible using setListLoosely.

Parameters:
name - a String representing the string's name

StrictPermutation

public StrictPermutation(StrictPermutation toClone)
Creates and returns a clone of the given StrictPermutation. Throws NullPointerException when passed null.

Parameters:
toClone - the binary string to clone
Method Detail

getLength

public int getLength()
Returns the length of this permutation list


setLength

public void setLength(int size)
Sets the length of this permutation. Destroys any previous list and initializes a new one.


getName

public java.lang.String getName()
Returns the name of this permutation list


setName

public void setName(java.lang.String name)
Sets the name of this permutation

Parameters:
name - the String for the new name of this list

getList

public int[] getList()
Returns this permutation as a int[].


setList

public void setList(int[] list)
Sets the permutation to the values in the given list.

Parameters:
list - an int[] value to duplicate

setListLoosely

public void setListLoosely(int[] list)
Sets the permutation to the values in the given list when possible. Calls setListLoosely(list, 0);

Parameters:
list - an int[] value to try to duplicate

setListLoosely

public void setListLoosely(int[] list,
                           int start)
Sets the permutation to the values in the given list when possible starting from a given position. All elements before this position are left alone. If a duplicate is found, it is skipped and not added a second time. If not all values have been added into the list, then they are added sequentially to fill the list. When (start<0) or (start>length) an exception is thrown.

Parameters:
list - an int[] value to try to duplicate
start - the position to start from

getElement

public int getElement(int element)
Returns the value of a certain element in the permutation

Parameters:
element - the element to return

cross

public static StrictPermutation cross(StrictPermutation first,
                                      StrictPermutation second)
Returns a new StrictPermutation based on two other permutations of the same length. A cross-over point is picked at random and all elements before this point are the same as the first parent's and all all other elements are added in the same order as they are in the second permutation when possible. Neither parent is altered during this call.

Parameters:
first - the first StrictPermutation
second - the second StrictPermutation

mutate

public void mutate(int amount)
Mutates a given number of elements in the permutation. The mutation is the exchange of two elements in the list. A non-positive argument results in no change in the string.

Parameters:
amount - the number of elements to exchange ("mutate")

toString

public java.lang.String toString()
Method declaration

Overrides:
toString in class java.lang.Object
Returns:
A String representation of the Object


Copyright - 2001 OpenAI Labs. All Rights Reserved.