Main
Class AbstractRun

java.lang.Object
  extended by Main.State
      extended by Main.AbstractRun
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Run, Tutorial4, Tutorial5, Tutorial6, Tutorial7

public abstract class AbstractRun
extends State

AbstractRun class. Read the parameters. Some classes are dynamically loaded.

Author:
erik
See Also:
Serialized Form

Field Summary
protected  Collector collector
           
protected  Initialiser initialiser
           
protected  java.util.Properties properties
           
protected  java.lang.String propertiesFilePath
           
protected  java.lang.String stdErr
           
protected  java.lang.String stdOut
           
 
Fields inherited from class Main.State
algorithm, rng
 
Constructor Summary
AbstractRun()
          Creates a new instance of AbstractRun
 
Method Summary
protected  boolean commandLineArgs(java.lang.String[] args)
          Read the commandline arguments.
protected  boolean foundOptimum(boolean stopWhenSolved, StatCatcher stats)
          Check if the global optimum value has been found
protected  IndividualCatcher getBestIndiv()
           
protected  Collector getCollector()
          helper method for getting the StatisticsCollectionOperation
protected  CrossoverOperation getCrossoverOperation(RandomNumberGenerator rng, java.util.Properties p)
           
protected  FitnessFunction getFitnessFunction(java.util.Properties p)
          Load the fitness class according to the parameters
protected  GEGrammar getGEGrammar(java.util.Properties p)
          Load a GEGrammar.
protected  Initialiser getInitialiser(GEGrammar g, RandomNumberGenerator rng, java.util.Properties p)
          Load and initialise the initialiser class according to the parameters Defualt initialiser is the RandomInitialiser.
protected  JoinOperator getJoinOperator(java.util.Properties p, RandomNumberGenerator rng, Population incPop, ReplacementOperation rO)
          Load the fitness class according to the parameters
protected  MutationOperation getMutationOperation(RandomNumberGenerator rng, java.util.Properties p)
           
protected  SelectionOperation getSelectionOperation(java.util.Properties p, RandomNumberGenerator rng)
          Load the fitness class according to the parameters
protected  void init()
          Runs the init pipeline.
protected  void printStuff()
          Prints the collected statistics
protected  void readProperties(java.lang.String[] args)
          Read the default properties.
protected  int run()
          Run the loop pipeline.
protected  void setOutput()
           
abstract  void setup(java.lang.String[] args)
          Setup the algorithm.
 
Methods inherited from class Main.State
experiment, getAlgorithm, load, save
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

propertiesFilePath

protected java.lang.String propertiesFilePath

initialiser

protected Initialiser initialiser

properties

protected java.util.Properties properties

stdOut

protected java.lang.String stdOut

stdErr

protected java.lang.String stdErr

collector

protected Collector collector
Constructor Detail

AbstractRun

public AbstractRun()
Creates a new instance of AbstractRun

Method Detail

setup

public abstract void setup(java.lang.String[] args)
Setup the algorithm. Read the properties. Create the modules(Operators) and operations

Specified by:
setup in class State
Parameters:
args - arguments

getFitnessFunction

protected FitnessFunction getFitnessFunction(java.util.Properties p)
Load the fitness class according to the parameters

Parameters:
p - Properties
Returns:
FitnessFunction

getGEGrammar

protected GEGrammar getGEGrammar(java.util.Properties p)
Load a GEGrammar. Default is Mapper.GEGrammar

Parameters:
p - properties file
Returns:
GEGrammar, null if getProperty failed

getInitialiser

protected Initialiser getInitialiser(GEGrammar g,
                                     RandomNumberGenerator rng,
                                     java.util.Properties p)
Load and initialise the initialiser class according to the parameters Defualt initialiser is the RandomInitialiser. To add other initialisers expand the if-statement with another clause

Parameters:
g - GEGrammar
rng - RandomNumberGenerator
p - Properties
Returns:
Intialiser

getSelectionOperation

protected SelectionOperation getSelectionOperation(java.util.Properties p,
                                                   RandomNumberGenerator rng)
Load the fitness class according to the parameters

Parameters:
rng - RandomNumberGenerator
p - Properties
Returns:
SelectionOperation

getJoinOperator

protected JoinOperator getJoinOperator(java.util.Properties p,
                                       RandomNumberGenerator rng,
                                       Population incPop,
                                       ReplacementOperation rO)
Load the fitness class according to the parameters

Parameters:
p - Properties
rng - RandomNumberGenerator
incPop - incomming population
rO - replacement operation
Returns:
SelectionOperation

init

protected void init()
Runs the init pipeline. Prints statistics from the init pipeline


printStuff

protected void printStuff()
Prints the collected statistics


getBestIndiv

protected IndividualCatcher getBestIndiv()

run

protected int run()
Run the loop pipeline.

Returns:
int number of iterations

foundOptimum

protected boolean foundOptimum(boolean stopWhenSolved,
                               StatCatcher stats)
Check if the global optimum value has been found

Parameters:
stopWhenSolved - if algorithm should terminate when the global optimum is found
stats - stataistics collection
Returns:
if global optimum has been found

getMutationOperation

protected MutationOperation getMutationOperation(RandomNumberGenerator rng,
                                                 java.util.Properties p)

getCrossoverOperation

protected CrossoverOperation getCrossoverOperation(RandomNumberGenerator rng,
                                                   java.util.Properties p)

getCollector

protected Collector getCollector()
helper method for getting the StatisticsCollectionOperation

Returns:
Collector collector module

commandLineArgs

protected boolean commandLineArgs(java.lang.String[] args)
Read the commandline arguments. Find if -h is called. Find if properties field is given Prints the usage help

Parameters:
args - Command-line arguments
Returns:
booelan value of success

readProperties

protected void readProperties(java.lang.String[] args)
Read the default properties. Replace or add properties from the command line. If the file is not found on the file system class loading from the jar is tried

Parameters:
args - arguments

setOutput

protected void setOutput()