net.openai.ai.ga
Class GeneticAlgorithm

java.lang.Object
  |
  +--net.openai.ai.ga.GeneticAlgorithm

public class GeneticAlgorithm
extends java.lang.Object

GeneticAlgorithm is the top-level class for the Genetic Algorithm Java implementation of the OpenAI Toolkit. It provides the handling of multiple worlds (isolated genetic algorithm implementations) and making the algorithms run.

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

Constructor Summary
GeneticAlgorithm()
          Initializes the GeneticAlgorithm with an ArrayList
GeneticAlgorithm(java.util.Collection initialCollection)
          Initializes the GeneticAlgorithm with the specified Collection
 
Method Summary
 void addWorld(World toAdd)
          Adds a given World onto the end of all the worlds in this Genetic Algorithm.
 void cleanse()
          Removes non-World objects from the Collection
static boolean getDebug()
           
 int getNumberOfWorlds()
          Returns the number of Worlds stored in this GeneticAlgorithm.
 World getWorld(java.lang.String name)
          Retrieves a World from the list with a given name.
 World[] getWorldArray()
          Retrieves a World[] copy of all the World's in this GeneticAlgorithm.
 java.util.Iterator getWorldIterator()
          Return an Iterator to use to go through all the Worlds in this GeneticAlgorithm.
 java.lang.String[] getWorldNames()
          Retrieves a World from the list with a given name.
 java.util.Collection getWorlds()
          Retrieves the Collection that holds this collection's World objects
 void iterateAllWorlds()
          Tells all World's in this GeneticAlgorithm to iterate through one generation.
 void iterateAllWorlds(int reps, boolean iterateParallel)
          Tells all World's in this GeneticAlgorithm to iterate through multiple generations.
 void iterateWorld(java.lang.String name)
          Tells a World with a given name to iterate through one generation.
 void iterateWorld(java.lang.String name, int reps)
          Tells a World to iterate through multiple generations.
 void iterateWorld(World toIterate)
          Tells a World to iterate through one generation.
 void iterateWorld(World toIterate, int reps)
          Tells a World to iterate through multiple generations.
 void removeAllWorlds(java.lang.String name)
          Removes all World's with the given name out of this GeneticAlgorithm.
 boolean removeWorld(java.lang.String name)
          Removes a World with the given name out of this GeneticAlgorithm.
 boolean removeWorld(World toRemove)
          Removes a given World out of this GeneticAlgorithm.
 java.lang.String toString()
          Calls every World's toString() method and returns a concatenation of all the Strings returned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeneticAlgorithm

public GeneticAlgorithm()
Initializes the GeneticAlgorithm with an ArrayList


GeneticAlgorithm

public GeneticAlgorithm(java.util.Collection initialCollection)
Initializes the GeneticAlgorithm with the specified Collection

Method Detail

addWorld

public void addWorld(World toAdd)
Adds a given World onto the end of all the worlds in this Genetic Algorithm.

Parameters:
toAdd - a World to be added into this GeneticAlgorithm

removeWorld

public boolean removeWorld(World toRemove)
Removes a given World out of this GeneticAlgorithm. Returns true when it can successfully remove the given World. When multiple copies of the given World exist, only the first instance is deleted. This method does not throw an IndexOutOfBoundsException.

Parameters:
toRemove - a World to be deleted from this GeneticAlgorithm
Returns:
true if the World has been found and deleted
false otherwise

removeWorld

public boolean removeWorld(java.lang.String name)
Removes a World with the given name out of this GeneticAlgorithm. Returns true when it can successfully remove the given World. When multiple copies of the given World exist, only the first instance is deleted. This method does not throw an IndexOutOfBoundsException. This method uses getWorld(String) to find the given World.

Parameters:
name - a String specifying the name of the world to be deleted
Returns:
true if the World has been found and deleted
false otherwise

removeAllWorlds

public void removeAllWorlds(java.lang.String name)
Removes all World's with the given name out of this GeneticAlgorithm. This method does not throw an IndexOutOfBoundsException. This method uses removeWorld(String) to delete all World's with the given name and keeps calling until removeWorld(String) returns false. Does not return a value.

Parameters:
name - a String specifying the name of the world to be deleted

getWorld

public World getWorld(java.lang.String name)
Retrieves a World from the list with a given name. Iterates through all the World's in this GeneticAlgorithm until one is found that has the given name. Returns the World when one is found; returns null when the search is unsuccessful.

Parameters:
name - a String specifying the name of the world to be returned
Returns:
Object when a match is found
null when no match can be found

getWorldNames

public java.lang.String[] getWorldNames()
Retrieves a World from the list with a given name. Iterates through all the World's in this GeneticAlgorithm until one is found that has the given name. Returns the World when one is found; returns null when the search is unsuccessful.

Returns:
Object when a match is found
null when no match can be found

getWorldArray

public World[] getWorldArray()
Retrieves a World[] copy of all the World's in this GeneticAlgorithm. The order is not guaranteed to be consistant on every call.

Returns:
World[] of all the World objects

getWorlds

public java.util.Collection getWorlds()
Retrieves the Collection that holds this collection's World objects

Returns:
Collection of all the World objects

iterateWorld

public void iterateWorld(java.lang.String name)
Tells a World with a given name to iterate through one generation. Uses getWorld(String) to find the World with the given name and calls that World's iterate() function.

Parameters:
name - a String specifying the name of the world to iterate()

iterateWorld

public void iterateWorld(World toIterate)
Tells a World to iterate through one generation. Equilivant to calling the iterate() function of the given World. Throws an exception when the World does not belong to its collection.

Parameters:
toIterate - a World to iterate
Throws:
java.util.NoSuchElementException - thrown if the specified World does not belong to this GeneticAlgorithm

iterateWorld

public void iterateWorld(java.lang.String name,
                         int reps)
Tells a World to iterate through multiple generations. Calls getWorld(name) to retrieve the World from the collection and then calls the iterate() function on it a given number of times. Does not iterate when called with a non-positive number. Does no iterations when no world with the given name can be found.

Parameters:
name - a String specifying a world to iterate
reps - the number of times to iterate

iterateWorld

public void iterateWorld(World toIterate,
                         int reps)
Tells a World to iterate through multiple generations. Calls getWorld(name) to retrieve the World from the collection and then calls the iterate() function on it a given number of times. Does not iterate when called with a non-positive number. Throws an exception when the World does not belong to its collection.

Parameters:
toIterate - the World to iterate
reps - the number of times to iterate
Throws:
java.util.NoSuchElementException - thrown if the specified World does not belong to this GeneticAlgorithm

iterateAllWorlds

public void iterateAllWorlds()
Tells all World's in this GeneticAlgorithm to iterate through one generation. Uses getWorldIterator() to iterate through each call, and therefore does not guarantee any order of execution.


iterateAllWorlds

public void iterateAllWorlds(int reps,
                             boolean iterateParallel)
Tells all World's in this GeneticAlgorithm to iterate through multiple generations. There are two methods of iteration:

Parameters:
reps - the number of times to iterate each world
iterateParallel - false specifies serial iteration (all iterations on each world)
true specifies parallel iteration (each iteration simultaneously on all worlds)

getNumberOfWorlds

public int getNumberOfWorlds()
Returns the number of Worlds stored in this GeneticAlgorithm.

Returns:
the number of Worlds

toString

public java.lang.String toString()
Calls every World's toString() method and returns a concatenation of all the Strings returned.

Overrides:
toString in class java.lang.Object
Returns:
a concatenated String of all the Worlds' toString() methods

cleanse

public void cleanse()
Removes non-World objects from the Collection


getWorldIterator

public java.util.Iterator getWorldIterator()
Return an Iterator to use to go through all the Worlds in this GeneticAlgorithm.

Returns:
an Iterator for the collection of Worlds

getDebug

public static boolean getDebug()


Copyright - 2001 OpenAI Labs. All Rights Reserved.