gpsys
Class GPParameters

java.lang.Object
  |
  +--gpsys.GPParameters
Direct Known Subclasses:
LawnMowerGPParameters, SymRegGPParameters

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

This class is used to parameterise the GP system. Use this class as is or extend it for your problem, but in either case fill in the instance variables to specify your problem.

The class supports methods enabling loading and saving of a GPParameters object. The object may be written/read to/from either a file or a stream. These methods use Java Serialisable Objects and hence if you extend the class to include new instance variables, ensure that they are Serializable so that they can be saved. If any instance variables you introduce are temporary variables, declare them transient to ensure they are not saved.

There are also methods enabling a generation report to be sent to a file or an OutputStream.

Version:
$Revision: 1.1 $, $Date: 2000/07/05 16:21:25 $
Author:
Adil Qureshi
Department of Computer Science,
University College London,
Gower St,
London WC1E 6BT,
UK.
See Also:
Serialized Form

Field Summary
 ChromosomeParameters[] adf
          Parameters for each ADF to be evolved.
protected  int creationIndex
          Used during the generation of the initial popupation.
 int engine
          The engine to be used for evolution.
static int ENGINE_GENERATIONAL
          Used for selecting the generational engine type.
static int ENGINE_STEADYSTATE
          Used for selecting the steady state engine type.
 Fitness fitness
          The Fitness definition for the problem.
 int generations
          The number of generations to evolve.
 GPObserver observer
          The object monitoring the GP system.
 double pMutation
          The probability of mutation.
 Population population
          The population.
 int populationSize
          How many Individuals there are in the population.
 double pReproduction
          The probability of Reproduction.
 java.util.Random rng
          The random number generator.
 long rngSeed
          The random number generator seed.
 int tournamentSize
          The tournament size to be used for tournament selection during crossover and mutation.
 
Constructor Summary
GPParameters()
           
 
Method Summary
static GPParameters load(java.io.InputStream is)
          Load a GPParameters object from the InputStream.
static GPParameters load(java.lang.String filePrefix)
          Loads a previously saved GPParameters object from the file specified.
 void save(java.io.OutputStream os)
          Write this object to an OutputStream compressing it using gzip as it is written.
 void save(java.lang.String filePrefix)
          Save this object to a file compressing it using gzip during the save.
 void writeReport(java.io.PrintWriter pw, boolean firstReport)
          Write a report of the current generation to the PrintWriter.
 void writeReport(java.lang.String filePrefix, boolean firstReport)
          Write a report of the current generation to a file.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

observer

public transient GPObserver observer
The object monitoring the GP system.

engine

public int engine
The engine to be used for evolution. The value of this variable must be set to one of the class constants beggining with ENGINE_ such as ENGINE_STEADYSTATE.

ENGINE_STEADYSTATE

public static final int ENGINE_STEADYSTATE
Used for selecting the steady state engine type. A Steady State engine is useful if you are low on memory. Each new individual created via mutation or xover immediately replaces an individual in the population and is hence immediately available for creating the next individual. The concept of a generation is when an entire population of new Individuals have been created. In a Steady State engine the best individual of the generation is also the best individual of the run.

ENGINE_GENERATIONAL

public static final int ENGINE_GENERATIONAL
Used for selecting the generational engine type. A Generational engine is useful if the application requires that each generation is given a different set of test cases for fitness evaluation. A Generational engine creates an entire new population using xover and mutation which replaces the old population. In a Generational engine the best individual of generation need not be the best of the run.

rngSeed

public long rngSeed
The random number generator seed.

rng

public java.util.Random rng
The random number generator. This should have been created with the above seed.

pMutation

public double pMutation
The probability of mutation. This needs to be a number between 0 and 1.

pReproduction

public double pReproduction
The probability of Reproduction. This needs to be a number between 0 and 1.

tournamentSize

public int tournamentSize
The tournament size to be used for tournament selection during crossover and mutation.

populationSize

public int populationSize
How many Individuals there are in the population.

generations

public int generations
The number of generations to evolve.

adf

public ChromosomeParameters[] adf
Parameters for each ADF to be evolved. The length of this array is effectively the number of ADFs required.

fitness

public Fitness fitness
The Fitness definition for the problem.

population

public Population population
The population. This field is filled in automatically by the GP system.

creationIndex

protected int creationIndex
Used during the generation of the initial popupation. It is the index of the current Individual being created.
Constructor Detail

GPParameters

public GPParameters()
Method Detail

save

public void save(java.lang.String filePrefix)
          throws java.io.IOException
Save this object to a file compressing it using gzip during the save. This method is typically called by GPObservers after every generation to enable restarting from the last saved point in the event of system failure.
Parameters:
filePrefix - the file prefix to be used for save files. Two files may be created :- filePrefix.p1.gzip and filePrefix.p2.gzip

save

public void save(java.io.OutputStream os)
          throws java.io.IOException
Write this object to an OutputStream compressing it using gzip as it is written.
Parameters:
os - the output stream to be written to.

load

public static GPParameters load(java.lang.String filePrefix)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Loads a previously saved GPParameters object from the file specified. The GPParameters object must previously have been saved by the save() method. The save file is assumed to be gzipped and hence is decompressed during the read.
Parameters:
filePrefix - the file prefix used by the save files.
Returns:
the GPParameters object read from the file.
Throws:
java.lang.ClassNotFoundException - if the class definition for one of the objects being read cannot be found.

load

public static GPParameters load(java.io.InputStream is)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Load a GPParameters object from the InputStream. The stream is assumed to be gzipped and is hence unzipped during the load.
Parameters:
is - the input stream to read from.
Returns:
the GPParameters object read from the stream.
Throws:
java.lang.ClassNotFoundException - if the class definition for one of the objects being read cannot be found.

writeReport

public void writeReport(java.io.PrintWriter pw,
                        boolean firstReport)
Write a report of the current generation to the PrintWriter. The first report also contains the random number generator seed, the population size and the number of generations to be evolved.
Parameters:
pw - the PrintWriter to use to print the report.
firstReport - specifies whether this the first report.

writeReport

public void writeReport(java.lang.String filePrefix,
                        boolean firstReport)
                 throws java.io.IOException
Write a report of the current generation to a file. The first report also contains the random number generator seed, the population size and the number of generations to be evolved.
Parameters:
filePrefix - the filename prefix to use for the file to which the report is written. The file created is named : filePrefix.txt
firstReport - specifies whether this the first report.