net.openai.ai.ga.population
Class Population

java.lang.Object
  |
  +--net.openai.ai.ga.population.Population
All Implemented Interfaces:
java.io.Serializable

public class Population
extends java.lang.Object
implements java.io.Serializable

The Population is the encapsulation of the individual solutions ( Cells that are used to solve the problem. Cells may be added and deleted from this collection. This also implements the following functions, which are passed on to the appropriate targets:

Since:
JDK1.3
Version:
%I%, %G%
Author:
Jared Grubb
See Also:
Serialized Form

Field Summary
protected  java.util.Collection cells
          The collection of cells that are in this Population
 boolean toStringQuiet
          Determines whether to display anything on a toString() call.
 boolean toStringUsesCells
          Determines whether to call all the Cells to return something as well.
 boolean toStringUsesSize
          Determines whether to display the size of the Population
 boolean toStringUsesTopCell
          Determines whether the Cell with the highest fitness is displayed.
 
Constructor Summary
Population()
          Creates a population using an ArrayList
Population(java.util.Collection initialCollection)
          Creates a population using a given Collection
Population(Population toClone)
          Creates a partial clone of this Population.
Population(Population toClone, boolean makeEmpty)
          Creates a partial clone of this Population.
 
Method Summary
 void addCell(Cell toAdd)
          Adds a Cell to this Population.
 void addCells(Population toAdd)
          Adds all the Cells in the given Population.
 void cleanse()
          Removes non-Cell objects from the Collection
 void combine(PopulationArray parents)
          Creates new Cells to add into the Population.
static void condemnPopulation(Population toCondemn)
          Condemns all the Cells in the given Population .
 void evaluate(Environment env)
          Tells each Cell in this Population to evaluate its fitness based upon the Environment given to it.
 Cell getCell(int index)
          Returns a Cell from this Population with the given index.
 Cell[] getCellArray()
          Returns a Cell[] array representing all the Cell s in this population.
 java.util.Iterator getCellIterator()
          Returns an Iterator to be used to iterate through all the Cell in this Population.
 java.util.Collection getCells()
          Returns the Collection used internally to represent the members of the population
 int getSize()
          Returns the number of Cells in this Population .
 void mature()
          Matures the population.
static void mutate(Population toMutate)
          Issues a mutate command to each cell in the passed Population .
 void removeAllCellsBut(Population toKeep)
          Removes all the Cells from this Population except those specified in the passed Population.
 void removeAllSameAs(Cell toRemove)
          Removes all instances of Cell from this Population.
 boolean removeCell(Cell toRemove)
          Removes a Cell from this Population.
 void removeCells(Population toRemove)
          Removes a group of Cells from this Population .
 java.lang.String toString()
          Returns a String representation of this Population.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cells

protected java.util.Collection cells
The collection of cells that are in this Population


toStringQuiet

public boolean toStringQuiet
Determines whether to display anything on a toString() call.


toStringUsesSize

public boolean toStringUsesSize
Determines whether to display the size of the Population


toStringUsesCells

public boolean toStringUsesCells
Determines whether to call all the Cells to return something as well.


toStringUsesTopCell

public boolean toStringUsesTopCell
Determines whether the Cell with the highest fitness is displayed.

Constructor Detail

Population

public Population()
Creates a population using an ArrayList


Population

public Population(java.util.Collection initialCollection)
Creates a population using a given Collection

Parameters:
initialCollection - a Collection to initialize with

Population

public Population(Population toClone)
Creates a partial clone of this Population. This is not a complete clone, in which each of the Cells would also be cloned; this instead creates a copy of the collection of Cells to which additions and removals do not affect the original population. Equilivant to Population(toClone,false) .


Population

public Population(Population toClone,
                  boolean makeEmpty)
Creates a partial clone of this Population. This is not a complete clone, in which each of the Cells would also be cloned; this instead creates a copy of the collection of Cells to which additions and removals do not affect the original population.

Method Detail

mature

public void mature()
Matures the population. Calls the mature() method of each of the Cells contained in this Population.


evaluate

public void evaluate(Environment env)
Tells each Cell in this Population to evaluate its fitness based upon the Environment given to it.

Parameters:
env - Environment to evaluate against

combine

public void combine(PopulationArray parents)
Creates new Cells to add into the Population. The groups of cells to combine are passed as a PopulationArray . The first Cell in each Population in the group is issued the combine method to return a new Cell which is then added into this Population.

Parameters:
parents - a PopulationArray containing sets of parents

mutate

public static void mutate(Population toMutate)
Issues a mutate command to each cell in the passed Population .

Parameters:
toMutate - the target Population for the mutation

getCellIterator

public java.util.Iterator getCellIterator()
Returns an Iterator to be used to iterate through all the Cell in this Population.

Returns:
an Iterator on the Cell collection

addCell

public void addCell(Cell toAdd)
Adds a Cell to this Population. Does nothing when given null.

Parameters:
toAdd - the Cell to add

addCells

public void addCells(Population toAdd)
Adds all the Cells in the given Population. Does nothing on null or an empty Population.


removeCell

public boolean removeCell(Cell toRemove)
Removes a Cell from this Population. Returns whether the removal was successful or not. Does nothing when given a null.

Parameters:
toRemove - the Cell to remove
Returns:
true on success; false otherwise;

removeCells

public void removeCells(Population toRemove)
Removes a group of Cells from this Population . Does not indicate whether the removal was successful or not. Does nothing when given a null or an empty Population.


removeAllCellsBut

public void removeAllCellsBut(Population toKeep)
Removes all the Cells from this Population except those specified in the passed Population. Does not indicate whether the removal was successful or not. Does nothing when given a null or an empty Population.


removeAllSameAs

public void removeAllSameAs(Cell toRemove)
Removes all instances of Cell from this Population. Does not indicate whether any removal took place. Does nothing when given a null or a non-existant Cell.

Parameters:
toRemove - the Cell to remove

getCell

public Cell getCell(int index)
Returns a Cell from this Population with the given index.

This method is not recommended since access to the collection via an index is highly unreliable. This method is provided only to provide a way for mutation selection algorithm to access random elements of the Cell array without having to do constant array conversions.

Parameters:
index - the index of the Cell to return
Returns:
Cell at the given index
Throws:
java.lang.IndexOutOfBoundsException

getCellArray

public Cell[] getCellArray()
Returns a Cell[] array representing all the Cell s in this population. Returns an empty array when empty.

Returns:
Cell[] of all Cells

getCells

public java.util.Collection getCells()
Returns the Collection used internally to represent the members of the population

Returns:
Collection of all Cells

condemnPopulation

public static void condemnPopulation(Population toCondemn)
Condemns all the Cells in the given Population . Each Cell in the Population has its condemn() called. A null passed returns immediately.

Parameters:
toCondemn - the Population to condemn

getSize

public int getSize()
Returns the number of Cells in this Population .

Returns:
the number of Cells

cleanse

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


toString

public java.lang.String toString()
Returns a String representation of this Population. Uses the following boolean values to create the return String:

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


Copyright - 2001 OpenAI Labs. All Rights Reserved.