com.groovyj.jgprog
Class World

java.lang.Object
  |
  +--com.groovyj.jgprog.World
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MultiplexerWorld, SymbolicRegressionWorld

public abstract class World
extends java.lang.Object
implements java.io.Serializable

World is the main engine class of the Groovy Java Genetic Programming system. This class is abstract and should be subclassed so that you can provide specifics about your own genetic programming problem (or "world").

In the constructor of your subclass, you should set the values of the various genetic programming runtime parameters. The defaults are:

Once you have determined your world's parameters, you must provide a function which evaluates the absolute fitness of a given Individual. The adjusted fitness of an individual is a value between 0 and 1 inclusive, with larger values indicating fitter individuals. Koza[1992] uses the adjusted fitness formula 1/(1+s), where s is the standardized fitness whose value is between 0 and infinity, with smaller values indicating fitter individuals, and 0 indicating a perfect individual. While the use of the Koza formula is not required, it does have the advantage of exaggerating the difference between highly and closely fit individuals. If you do not use the Koza formula, some other fitness function must be used such that higher values indicate fitter individuals.

The next step is to create the world. You will need to know the population size, the number of chromosomes per individual, the return type of each chromosome, the number of arguments and their types for each chromosome, and the types of nodes (functions and terminals) each chromosome is allowed to have.

With this release of JGProg, the only types allowed are Boolean, Integer, Long, Float, Double, and Void.

Also with this release of JGProg, the following terminals are available (note, this list is currently out of date -- there are more functions):

and the following functions are available:

ADF could actually be a terminal if it refers to a chromosome which takes no arguments.

Creating the world will generate the initial population according to the ramped half-and-half method described in Koza[1992]. The create method evaluates each individual by calling your fitness method.

After create returns, you can evolve the population by calling nextGeneration. This method performs the reproduce and crossover operations described in Koza[1992]. The individuals chosen for these operations are selected using the selectionMethod you chose. The default selection method is fitness-proportionate.

You can call nextGeneration as many times as you want. A new run can be started by calling the create method again.

Got a comment about this class? Found a bug? Got an enhancement? Just want to say hi? Visit the Groovy Java Genetic Programming Project Home Page.

Visit the Groovy Java Home Page for information about other Groovy Java open source projects.

Copyright (c) 2000 Robert Baruch. This code is released under the GNU General Public License (GPL).

Version:
$Id: World.java,v 1.4 2000/10/12 15:22:55 groovyjava Exp $
Author:
Robert Baruch (jgprog@sourceforge.net)
See Also:
Serialized Form

Field Summary
protected static CrossMethod crossMethod
           
protected static float crossoverProb
          The probability that a crossover operation is chosen during evolution.
protected static int maxChromosomes
           
protected static int maxCrossoverDepth
          The maximum depth of an individual resulting from crossover.
protected static int maxInitDepth
          The maximum depth of an individual when the world is created.
protected static int maxSize
           
static java.util.Random random
          The random number generator used by every random event.
protected static float reproductionProb
          The probability that a reproduction operation is chosen during evolution.
protected static SelectionMethod selectionMethod
          The method of choosing an individual to perform an evolution operation on.
 
Constructor Summary
World()
          Constructs a world.
 
Method Summary
 void addGPListener(GPListener l)
           
abstract  float computeFitness(Individual individual)
          Computes the adjusted fitness of the given individual.
 void create(int popSize, Type[] types, Type[][] argTypes, Function[][] nodeSets)
          Creates the initial population for the world and computes the fitnesses of all the individuals in the initial population.
 Individual getBestIndividual()
          Gets the most fit individual from the current population.
 Population getPopulation()
          Gets the population.
 float getTotalFitness()
          Gets the sum of the adjusted fitnesses of all individuals in the population.
 Individual getWorstIndividual()
          Gets the least fit individual from the current population.
 void nextGeneration()
          Evolve the population by one generation.
 void removeGPListener(GPListener l)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

selectionMethod

protected static SelectionMethod selectionMethod
The method of choosing an individual to perform an evolution operation on. The default value is FitnessProportionateSelection.
Since:
1.0

crossMethod

protected static CrossMethod crossMethod

crossoverProb

protected static float crossoverProb
The probability that a crossover operation is chosen during evolution. Must be between 0.0f and 1.0f, inclusive. The default value is 0.9f.
Since:
1.0

reproductionProb

protected static float reproductionProb
The probability that a reproduction operation is chosen during evolution. Must be between 0.0f and 1.0f, inclusive. The default value is 0.1f. In the current version of JGProg, crossoverProb + reproductionProb must equal 1.0f. Other operations may be added in the future.
Since:
1.0

maxCrossoverDepth

protected static int maxCrossoverDepth
The maximum depth of an individual resulting from crossover. The default value is 17.
Since:
1.0

maxInitDepth

protected static int maxInitDepth
The maximum depth of an individual when the world is created. The default value is 6.
Since:
1.0

maxChromosomes

protected static int maxChromosomes

maxSize

protected static int maxSize

random

public static java.util.Random random
The random number generator used by every random event. The default value is Random (the default constructor which bases the seed on the current time).
Since:
1.0
Constructor Detail

World

public World()
      throws java.io.IOException
Constructs a world.
Since:
1.0
Method Detail

create

public void create(int popSize,
                   Type[] types,
                   Type[][] argTypes,
                   Function[][] nodeSets)
Creates the initial population for the world and computes the fitnesses of all the individuals in the initial population.

Implementation note: the arguments of a chromosome, if any, are treated as Variables of name "ARG"+argnum (ARG0, ARG1, etc). These variables are automatically saved, loaded before a call to the chromosome (via ADF), and restored after the call.

Parameters:
popSize - the number of individuals in the population
types - the type of each chromosome, the length is the number of chromosomes
argTypes - the types of the arguments to each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of arguments to the chromosome.
nodeSets - the nodes which are allowed to be used by each chromosome, must be an array of arrays, the first dimension of which is the number of chromosomes and the second dimension of which is the number of nodes. Note that it is not necessary to include the arguments of a chromosome as terminals in the chromosome's node set. This is done automatically for you.
Since:
1.0

computeFitness

public abstract float computeFitness(Individual individual)
Computes the adjusted fitness of the given individual. The subclass must provide an implementation of this method.
Parameters:
individual - the Individual to evaulate
Returns:
the adjusted fitness, where bigger numbers are better. Does not necessarily have to have a maximum value.
Since:
1.0

getTotalFitness

public float getTotalFitness()
Gets the sum of the adjusted fitnesses of all individuals in the population. Used by selection methods as a convenience.
Returns:
the sum of the population's adjusted fitnesses.
Since:
1.0

getPopulation

public Population getPopulation()
Gets the population.
Returns:
the population
Since:
1.0

nextGeneration

public void nextGeneration()
Evolve the population by one generation. Probabilistically reproduces and crosses individuals into a new population which then overwrites the original population. Computes the population's fitnesses before returning.
Since:
1.0

getBestIndividual

public Individual getBestIndividual()
Gets the most fit individual from the current population.
Returns:
the most fit individual
Since:
1.0

getWorstIndividual

public Individual getWorstIndividual()
Gets the least fit individual from the current population.
Returns:
the least fit individual
Since:
1.0

addGPListener

public void addGPListener(GPListener l)

removeGPListener

public void removeGPListener(GPListener l)