ec
Class EvolutionState

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

public 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)
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 or = 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

Version:
1.0
Author:
Sean Luke
See Also:
Serialized Form

Field Summary
 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.
 StateExecutionContext context_
          Used for Frontier remote task execution context.
 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.
 int generation
          The current generation of the population in the run.
 Initializer initializer
          The population initializer, a singleton object.
 java.lang.Object[] job
          Current job iteration variables, set by Evolve.
 int numGenerations
          The number of generations the evolutionary computation system will run until it ends.
 IOutput output
          The output and logging facility (threadsafe).
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_GENERATIONS
           
static java.lang.String P_INITIALIZER
           
static java.lang.String P_QUITONRUNCOMPLETE
           
static java.lang.String P_STATISTICS
           
 IParameterDatabase 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_NOTDONE
          "The evolution run has not quit
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).
 int randomSeedOffset
          An amount to add to each random number generator seed to "offset" it -- often this is simply the job number.
 java.lang.String[] runtimeArguments
          The original runtime arguments passed to the Java process.
 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
 int evolve()
           
 void finish(int result)
           
protected  void performCheckpoint()
          Perform checkpointing if enabled.
 void resetFromCheckpoint()
          This method is called after a checkpoint is restored from but before the run starts up again.
 void run(int condition)
          Starts the run.
 void setup(EvolutionState state, Parameter base)
          Sets up the object by reading it from the parameters stored in state, built off of the parameter base base.
 void startFresh()
           
 void startFromCheckpoint()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parameters

public IParameterDatabase 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 IOutput 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.


randomSeedOffset

public int randomSeedOffset
An amount to add to each random number generator seed to "offset" it -- often this is simply the job number. If you are using more random number generators internally than the ones initially created for you in the EvolutionState, you might want to create them with the seed value of seedParameter+randomSeedOffset. At present the only such class creating additional generators is ec.eval.MasterProblem.


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.


job

public java.lang.Object[] job
Current job iteration variables, set by Evolve. The default version simply sets this to a single Object[1] containing the current job iteration number as an Integer (for a single job, it's 0). You probably should not modify this inside an evolutionary run.


runtimeArguments

public java.lang.String[] runtimeArguments
The original runtime arguments passed to the Java process. You probably should not modify this inside an evolutionary run.


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.


context_

public StateExecutionContext context_
Used for Frontier remote task execution context.


C_STARTED_FRESH

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

See Also:
Constant Field Values

C_STARTED_FROM_CHECKPOINT

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

See Also:
Constant Field Values

R_SUCCESS

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

See Also:
Constant Field Values

R_FAILURE

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

See Also:
Constant Field Values

R_NOTDONE

public static final int R_NOTDONE
"The evolution run has not quit

See Also:
Constant Field Values

P_INITIALIZER

public static final java.lang.String P_INITIALIZER
See Also:
Constant Field Values

P_FINISHER

public static final java.lang.String P_FINISHER
See Also:
Constant Field Values

P_BREEDER

public static final java.lang.String P_BREEDER
See Also:
Constant Field Values

P_EVALUATOR

public static final java.lang.String P_EVALUATOR
See Also:
Constant Field Values

P_STATISTICS

public static final java.lang.String P_STATISTICS
See Also:
Constant Field Values

P_EXCHANGER

public static final java.lang.String P_EXCHANGER
See Also:
Constant Field Values

P_GENERATIONS

public static final java.lang.String P_GENERATIONS
See Also:
Constant Field Values

P_QUITONRUNCOMPLETE

public static final java.lang.String P_QUITONRUNCOMPLETE
See Also:
Constant Field Values

P_CHECKPOINTPREFIX

public static final java.lang.String P_CHECKPOINTPREFIX
See Also:
Constant Field Values

P_CHECKPOINTMODULO

public static final java.lang.String P_CHECKPOINTMODULO
See Also:
Constant Field Values

P_CHECKPOINT

public static final java.lang.String P_CHECKPOINT
See Also:
Constant Field Values
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)
Description copied from interface: Setup
Sets up the object by reading it from the parameters stored in state, built off of the parameter base base. If an ancestor implements this method, be sure to call super.setup(state,base); before you do anything else.

Specified by:
setup in interface Setup

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.

Throws:
java.io.IOException

finish

public void finish(int result)

startFromCheckpoint

public void startFromCheckpoint()

startFresh

public void startFresh()

evolve

public int evolve()
           throws java.lang.InternalError
Throws:
java.lang.InternalError

run

public void run(int condition)
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.


performCheckpoint

protected void performCheckpoint()
Perform checkpointing if enabled.