ec
Class EvolutionState

java.lang.Object
  |
  +--ec.EvolutionState
All Implemented Interfaces:
java.io.Serializable, Setup, Singleton
Direct Known Subclasses:
SimpleEvolutionState, SteadyStateEvolutionState

public abstract class EvolutionState
extends java.lang.Object
implements Singleton

An EvolutionState object is a singleton object which holds the entire state of an evolutionary run. By serializing EvolutionState, the entire run can be checkpointed out to a file.

The EvolutionState instance is passed around in a lot of methods, so objects can read from the parameter database, pick random numbers, and write to the output facility.

EvolutionState is a unique object in that it calls its own setup(...) method, from run(...).

An EvolutionState object contains quite a few objects, including:

Parameters
generations
int >= 1
(maximal number of generations to run.)
checkpoint-modulo
int >= 1
(how many generations should pass before we do a checkpoint? The definition of "generations" depends on the particular EvolutionState implementation you're using)
checkpoint
bool = true or false (default)
(should we checkpoint?)
prefix
String
(the prefix to prepend to checkpoint files -- see ec.util.Checkpoint)
gc
bool = true or false (default)
(should we force GC?)
gc-modulo
int >= 1
(how many generations should pass before we do garbage collection? The definition of "generations" depends on the particular EvolutionState implementation you're using)
aggressive
bool = true or false (default)
(if we force GC (see gc), should it be aggressive?)
quit-on-run-complete
bool = true or false (default)
(do we prematurely quit the run when we find a perfect individual?)
init
classname, inherits and != ec.Initializer
(the class for initializer)
finish
classname, inherits and != ec.Finisher
(the class for finisher)
breed
classname, inherits and != ec.Breeder
(the class for breeder)
eval
classname, inherits and != ec.Evaluator
(the class for evaluator)
stat
classname, inherits and != ec.Statistics
(the class for statistics)
exch
classname, inherits and != ec.Exchanger
(the class for exchanger)

Parameter bases
init initializer
finish finisher
breed breeder
eval evaluator
stat statistics
exch exchanger

See Also:
Serialized Form

Field Summary
 boolean aggressivegc
          Whether or not the system should be doing aggressive forced garbage collection after each generation.
 Breeder breeder
          The population breeder, a singleton object.
 int breedthreads
          The requested number of threads to be used in breeding, excepting perhaps a "parent" thread which gathers the other threads.
static int C_STARTED_FRESH
          "The population has started fresh (not from a checkpoint)."
static int C_STARTED_FROM_CHECKPOINT
          "The population started from a checkpoint."
 boolean checkpoint
          Should we checkpoint at all?
 int checkpointModulo
          The requested number of generations that should pass before we write out a checkpoint file.
 java.lang.String checkpointPrefix
          The requested prefix start filenames, not including a following period.
 int evalthreads
          The requested number of threads to be used in evaluation, excepting perhaps a "parent" thread which gathers the other threads.
 Evaluator evaluator
          The population evaluator, a singleton object.
 Exchanger exchanger
          The population exchanger, a singleton object.
 Finisher finisher
          The population finisher, a singleton object.
 boolean gc
          Whether or not the system should be doing forced garbage collection after each generation.
 int gcModulo
          The requested number of generations that should pass before we force a garbage collection.
 int generation
          The current generation of the population in the run.
 Initializer initializer
          The population initializer, a singleton object.
 int numGenerations
          The number of generations the evolutionary computation system will run until it ends.
 Output output
          The output and logging facility (threadsafe).
static java.lang.String P_AGGRESSIVEGC
           
static java.lang.String P_BREEDER
           
static java.lang.String P_CHECKPOINT
           
static java.lang.String P_CHECKPOINTMODULO
           
static java.lang.String P_CHECKPOINTPREFIX
           
static java.lang.String P_EVALUATOR
           
static java.lang.String P_EXCHANGER
           
static java.lang.String P_FINISHER
           
static java.lang.String P_GC
           
static java.lang.String P_GCMODULO
           
static java.lang.String P_GENERATIONS
           
static java.lang.String P_INITIALIZER
           
static java.lang.String P_QUITONRUNCOMPLETE
           
static java.lang.String P_STATISTICS
           
 ParameterDatabase parameters
          The parameter database (threadsafe).
 Population population
          The current population.
 boolean quitOnRunComplete
          Whether or not the system should prematurely quit when Evaluator returns true for runComplete(...) (that is, when the system found an ideal individual.
static int R_FAILURE
          "The evolution run has quit, failing to find a perfect individual."
static int R_SUCCESS
          "The evolution run has quit, finding a perfect individual."
 MersenneTwisterFast[] random
          An array of random number generators, indexed by the thread number you were given (or, if you're not in a multithreaded area, use 0).
 java.util.Vector statics
          A place for you to stash pointers to static objects so that they'll get serialized.
 Statistics statistics
          The population statistics, a singleton object.
 
Constructor Summary
EvolutionState()
          This will be called to create your evolution state; immediately after the constructor is called, the parameters, random, and output fields will be set for you.
 
Method Summary
 void aggressiveGC()
          Performs aggressive garbage collection.
 void gc()
          Performs nonagressive garbage collection.
 void go()
          Steps through a run for debugging purposes.
 void go(int n)
          Steps through a run n times for debugging purposes.
 void resetFromCheckpoint()
          This method is called after a checkpoint is restored from but before the run starts up again.
abstract  void run(int condition)
          Starts the run.
 void setup(EvolutionState state, Parameter base)
          Unlike for other setup() methods, ignore the base; it will always be null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

statics

public java.util.Vector statics
A place for you to stash pointers to static objects so that they'll get serialized. Java doesn't serialize static objects by default; you have to write them yourself. ECJ does this for its Clique objects (for example, GPType or GPNodeConstraints). However, some of these objects (like GPNodeConstraints) are typically only pointed to by bytes, not pointers. This means that if they're all stored in a static hash table, they never get serialized. So we stash one of them here, in statics, and it gets serialized, and is responsible for serializing the rest of 'em.

parameters

public ParameterDatabase parameters
The parameter database (threadsafe). Parameter objects are also threadsafe. Nonetheless, you should generally try to treat this database as read-only.

random

public MersenneTwisterFast[] random
An array of random number generators, indexed by the thread number you were given (or, if you're not in a multithreaded area, use 0). These generators are not threadsafe in and of themselves, but if you only use the random number generator assigned to your thread, as was intended, then you get random numbers in a threadsafe way. These generators must each have a different seed, of course.v

output

public Output output
The output and logging facility (threadsafe). Keep in mind that output in Java is expensive.

breedthreads

public int breedthreads
The requested number of threads to be used in breeding, excepting perhaps a "parent" thread which gathers the other threads. If breedthreads = 1, then the system should not be multithreaded during breeding. Don't modify this during a run.

evalthreads

public int evalthreads
The requested number of threads to be used in evaluation, excepting perhaps a "parent" thread which gathers the other threads. If evalthreads = 1, then the system should not be multithreaded during evaluation. Don't modify this during a run.

checkpoint

public boolean checkpoint
Should we checkpoint at all?

checkpointPrefix

public java.lang.String checkpointPrefix
The requested prefix start filenames, not including a following period. You probably shouldn't modify this during a run.

checkpointModulo

public int checkpointModulo
The requested number of generations that should pass before we write out a checkpoint file.

gc

public boolean gc
Whether or not the system should be doing forced garbage collection after each generation. You probably shouldn't modify this during a run.

gcModulo

public int gcModulo
The requested number of generations that should pass before we force a garbage collection. For this to have any effect, gc must be true.

aggressivegc

public boolean aggressivegc
Whether or not the system should be doing aggressive forced garbage collection after each generation. "Aggressive" means that garbage collection is repeatedly performed until there is absolutely no memory left to reclaim. This flag has no effect unless gc is also set to true. You probably shouldn't modify this during a run.

quitOnRunComplete

public boolean quitOnRunComplete
Whether or not the system should prematurely quit when Evaluator returns true for runComplete(...) (that is, when the system found an ideal individual.

generation

public int generation
The current generation of the population in the run. For non-generational approaches, this probably should represent some kind of incrementing value, perhaps the number of individuals evaluated so far. You probably shouldn't modify this.

numGenerations

public int numGenerations
The number of generations the evolutionary computation system will run until it ends. If after the population has been evaluated the Evaluator returns true for runComplete(...), and quitOnRunComplete is true, then the system will quit. You probably shouldn't modify this.

population

public Population population
The current population. This is not a singleton object, and may be replaced after every generation in a generational approach. You should only access this in a read-only fashion.

initializer

public Initializer initializer
The population initializer, a singleton object. You should only access this in a read-only fashion.

finisher

public Finisher finisher
The population finisher, a singleton object. You should only access this in a read-only fashion.

breeder

public Breeder breeder
The population breeder, a singleton object. You should only access this in a read-only fashion.

evaluator

public Evaluator evaluator
The population evaluator, a singleton object. You should only access this in a read-only fashion.

statistics

public Statistics statistics
The population statistics, a singleton object. You should generally only access this in a read-only fashion.

exchanger

public Exchanger exchanger
The population exchanger, a singleton object. You should only access this in a read-only fashion.

C_STARTED_FRESH

public static final int C_STARTED_FRESH
"The population has started fresh (not from a checkpoint)."

C_STARTED_FROM_CHECKPOINT

public static final int C_STARTED_FROM_CHECKPOINT
"The population started from a checkpoint."

R_SUCCESS

public static final int R_SUCCESS
"The evolution run has quit, finding a perfect individual."

R_FAILURE

public static final int R_FAILURE
"The evolution run has quit, failing to find a perfect individual."

P_INITIALIZER

public static final java.lang.String P_INITIALIZER

P_FINISHER

public static final java.lang.String P_FINISHER

P_BREEDER

public static final java.lang.String P_BREEDER

P_EVALUATOR

public static final java.lang.String P_EVALUATOR

P_STATISTICS

public static final java.lang.String P_STATISTICS

P_EXCHANGER

public static final java.lang.String P_EXCHANGER

P_GENERATIONS

public static final java.lang.String P_GENERATIONS

P_GC

public static final java.lang.String P_GC

P_AGGRESSIVEGC

public static final java.lang.String P_AGGRESSIVEGC

P_QUITONRUNCOMPLETE

public static final java.lang.String P_QUITONRUNCOMPLETE

P_CHECKPOINTPREFIX

public static final java.lang.String P_CHECKPOINTPREFIX

P_CHECKPOINTMODULO

public static final java.lang.String P_CHECKPOINTMODULO

P_GCMODULO

public static final java.lang.String P_GCMODULO

P_CHECKPOINT

public static final java.lang.String P_CHECKPOINT
Constructor Detail

EvolutionState

public EvolutionState()
This will be called to create your evolution state; immediately after the constructor is called, the parameters, random, and output fields will be set for you. The constructor probably won't be called ever if restoring (deserializing) from a checkpoint.
Method Detail

setup

public void setup(EvolutionState state,
                  Parameter base)
Unlike for other setup() methods, ignore the base; it will always be null.
Specified by:
setup in interface Setup
See Also:
Prototype.setup(EvolutionState,Parameter)

run

public abstract void run(int condition)
                  throws java.io.IOException
Starts the run. condition indicates whether or not the run was restarted from a checkpoint (C_STARTED_FRESH vs C_STARTED_FROM_CHECKPOINT). At the point that run(...) has been called, the parameter database has already been set up, as have the random number generators, the number of threads, and the Output facility. This method should call this.setup(...) to set up the EvolutionState object if condition equals C_STARTED_FRESH.

go

public void go(int n)
Steps through a run n times for debugging purposes. A debug-run is done by repeatedly pulsing the go() method. The default form prints a message saying that nothing happens.

go

public void go()
Steps through a run for debugging purposes. A debug-run is done by repeatedly pulsing the go() method. The default form prints a message saying that nothing happens.

gc

public final void gc()
Performs nonagressive garbage collection. A convenience function.

aggressiveGC

public final void aggressiveGC()
Performs aggressive garbage collection. A convenience function.

resetFromCheckpoint

public void resetFromCheckpoint()
                         throws java.io.IOException
This method is called after a checkpoint is restored from but before the run starts up again. You might use this to set up file pointers that were lost, etc.