Documentation of 'ec.EvolutionState' Java class
EvolutionState
ec

Class 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:

    • Objects you may safely manipulate during the multithreaded sections of a run:
      • MersenneTwisterFast random number generators (one for each evaluation or breeding thread -- use the thread number you were provided to determine which random number generator to use)
      • The ParameterDatabase
      • The Output facility for writing messages and logging
    • Singleton objects:
      • The Initializer.
      • The Finisher.
      • The Breeder.
      • The Evaluator.
      • The Statistics facility.
      • The Exchanger.
    • The current evolution state:
      • The generation number.
      • The population.
      • The maximal number of generations.
    • Auxillary read-only information:
      • The prefix to begin checkpoint file names with.
      • Whether to quit upon finding a perfect individual.
      • The number of breeding threads to spawn.
      • The number of evaluation threads to spawn.
    • A place to stash pointers to static variables so they'll get serialized:
      • Statics

    Parameters

    generations
    int >= 1 or undefined
    (maximal number of generations to run. Either this or evaluations must be set, but not both.)
    evaluations
    int >= 1 or undefined
    (maximal number of evaluations to run (in subpopulation 0). Either this or generations must be set, but not both.)
    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)
    checkpoint-directory
    File (default is empty)
    (directory where the checkpoint files should be located)
    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
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      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?
      java.io.File checkpointDirectory
      The requested directory where checkpoints should be located.
      int checkpointModulo
      The requested number of generations that should pass before we write out a checkpoint file.
      java.lang.String checkpointPrefix
      The requested prefix to start checkpoint 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.
      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.
      long numEvaluations
      How many evaluations should we run for? If set to UNDEFINED (0), we run for the number of generations instead.
      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_BREEDER 
      static java.lang.String P_CHECKPOINT 
      static java.lang.String P_CHECKPOINTDIRECTORY 
      static java.lang.String P_CHECKPOINTMODULO 
      static java.lang.String P_CHECKPOINTPREFIX 
      static java.lang.String P_EVALUATIONS 
      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 
      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_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.
      static int UNDEFINED 
    • Constructor Summary

      Constructors 
      Constructor and Description
      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.
    • Field Detail

      • 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?
      • checkpointDirectory

        public java.io.File checkpointDirectory
        The requested directory where checkpoints should be located. This must be a directory, not a file. You probably shouldn't modify this during a run.
      • checkpointPrefix

        public java.lang.String checkpointPrefix
        The requested prefix to start checkpoint 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 the user has specified a desired number of evaluations instead of generations, then this value will not be valid until after the first generation has been created (but before it has bene evaluated). 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.
      • numEvaluations

        public long numEvaluations
        How many evaluations should we run for? If set to UNDEFINED (0), we run for the number of generations instead.
      • 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)."
        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_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_CHECKPOINTDIRECTORY

        public static final java.lang.String P_CHECKPOINTDIRECTORY
        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

      • 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.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.