adams.optimise
Class GeneticAlgorithm

java.lang.Object
  extended by adams.core.ConsoleObject
      extended by adams.core.option.AbstractOptionHandler
          extended by adams.optimise.AbstractOptimiser
              extended by adams.optimise.genetic.AbstractGeneticAlgorithm
                  extended by adams.optimise.genetic.PackDataGeneticAlgorithm
                      extended by adams.optimise.GeneticAlgorithm
All Implemented Interfaces:
CleanUpHandler, Debuggable, Destroyable, OptionHandler, SizeOfHandler, Serializable, Comparable

public class GeneticAlgorithm
extends PackDataGeneticAlgorithm

Morticia (GEX).

Valid options are:

-D (property: debug)
         If set to true, scheme may output additional info to the console.
 
-num-chrom <int> (property: numChrom)
         The number of chromosomes, ie, the population size.
         default: 50
 
-num-iter <int> (property: numIterations)
         The number of iterations to perform.
         default: 10000000
 
-seed <int> (property: seed)
         The seed value for the random number generator.
         default: 1
 
-favor-zeroes (property: favorZeroes)
         Whether to favor 0s instead of 1s.
 
-best <java.lang.String> (property: bestRange)
         The range of the best attributes.
         default: -none-
 
-max-train <int> (property: maxTrainTime)
         The maximum number of seconds to training time (0 = unlimited time).
         default: 0
 
-notify <int> (property: notificationInterval)
         The time interval in seconds after which notification events about changes
          in the fitness can be sent (-1 = never send notifications; 0 = whenever
          a change occurs).
         default: -1
 

Version:
$Revision: 4584 $
Author:
Dale (dale at cs dot waikato dot ac dot nz), FracPete (fracpete at waikato dot ac dot nz)
See Also:
Serialized Form

Nested Class Summary
static class GeneticAlgorithm.GAJob
          Class for multithreading the ga.
 
Field Summary
protected  int m_bits
           
protected  FitnessFunction m_fitnessfn
           
protected  Long m_LastNotificationTime
          the timestamp the last notification got sent.
protected  PackDataDef m_pdd
           
 Hashtable<String,Double> m_StoredResults
          the cache for results.
protected  int m_zerocount
           
 
Fields inherited from class adams.optimise.genetic.AbstractGeneticAlgorithm
m_BestRange, m_FavorZeroes, m_Fitness, m_Genes, m_Iterations, m_MaxTrainTime, m_NumChrom, m_NumGenes, m_Random, m_Running, m_Seed, m_TrainStart, PROPS_FILTER, PROPS_MASK, PROPS_RELATION
 
Fields inherited from class adams.optimise.AbstractOptimiser
m_bestf, m_bestv
 
Fields inherited from class adams.core.option.AbstractOptionHandler
m_DebugLevel, m_OptionManager
 
Constructor Summary
GeneticAlgorithm()
          The default constructor.
 
Method Summary
protected  void addResult(String key, Double val)
          Adds a result to the cache.
 String bitsTipText()
          Returns the tip text for this property.
 void calcFitness()
          Calculates the fitness of the population.
 double calcNewFitness(FitnessFunction ff, int[] weights)
          Calculates the new fitness.
 void checkBest(Double fitness, OptData vars, FitnessFunction ff, int zerocount)
           
 void cleanUp()
          Cleans up data structures, frees up memory.
protected  void clearResults()
          Clears all currently stored results.
 void defineOptions()
          Adds options to the internal list of options.
 int getBits()
          Gets the number of bits.
 PackDataDef getDataDef()
           
 Vector<PackData> getDataSetups()
           
protected  Double getResult(String key)
          Returns a value from the cache.
 String globalInfo()
          Returns a string describing the object.
protected  void initialize()
          Initializes the members.
static void main(String[] args)
           
 OptData optimise(OptData datadef, FitnessFunction fitness)
           
protected  void preRun()
          Some more initializations.
 void reset()
          Resets the genetic algorihtm.
 void setBits(int value)
          Bits per gene.
 String weightsToString(int[] weights)
          Turns the weights into a string representation.
 
Methods inherited from class adams.optimise.genetic.PackDataGeneticAlgorithm
getInitialSetups, init, print, printBits
 
Methods inherited from class adams.optimise.genetic.AbstractGeneticAlgorithm
bestRangeTipText, copyGene, doCrossovers, doMutations, doMutations2, favorZeroesTipText, forCommandLine, forName, getBestRange, getFavorZeroes, getFitness, getGene, getGeneticAlgorithms, getIterations, getMaxTrainTime, getNumChrom, getNumGenes, getSeed, hasMoreZeroes, init, isRunning, iterationsTipText, maxTrainTimeTipText, numChromTipText, postRun, run, runGeneticAlgorithm, seedTipText, setBestRange, setBestRange, setFavorZeroes, setGene, setGene, setIterations, setMaxTrainTime, setNumChrom, setSeed, sort, stop, storeSetup, updateHeader
 
Methods inherited from class adams.optimise.AbstractOptimiser
checkBest, compareTo, destroy, equals, getOptimisers, shallowCopy, shallowCopy
 
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, debug, debug, debugLevelTipText, finishInit, getDebugLevel, getOptionManager, isDebugOn, newOptionManager, setDebugLevel, toCommandLine, toString
 
Methods inherited from class adams.core.ConsoleObject
getDebugging, getSystemErr, getSystemOut, sizeOf
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_bits

protected int m_bits

m_zerocount

protected int m_zerocount

m_pdd

protected PackDataDef m_pdd

m_fitnessfn

protected FitnessFunction m_fitnessfn

m_LastNotificationTime

protected Long m_LastNotificationTime
the timestamp the last notification got sent.


m_StoredResults

public Hashtable<String,Double> m_StoredResults
the cache for results.

Constructor Detail

GeneticAlgorithm

public GeneticAlgorithm()
The default constructor.

Method Detail

addResult

protected void addResult(String key,
                         Double val)
Adds a result to the cache.

Parameters:
key - the key of the result
val - the value to add

reset

public void reset()
Resets the genetic algorihtm. Derived classes must call this method in set-methods of parameters to assure the invalidation of previously generated data.

Overrides:
reset in class AbstractGeneticAlgorithm

getResult

protected Double getResult(String key)
Returns a value from the cache.

Parameters:
key - the key of the result
Returns:
the result or null if not present

clearResults

protected void clearResults()
Clears all currently stored results.


weightsToString

public String weightsToString(int[] weights)
Turns the weights into a string representation.

Parameters:
weights - the weights to turn into a string
Returns:
the weights as string

calcNewFitness

public double calcNewFitness(FitnessFunction ff,
                             int[] weights)
Calculates the new fitness.


checkBest

public void checkBest(Double fitness,
                      OptData vars,
                      FitnessFunction ff,
                      int zerocount)

globalInfo

public String globalInfo()
Returns a string describing the object.

Specified by:
globalInfo in class AbstractOptionHandler
Returns:
a description suitable for displaying in the gui

initialize

protected void initialize()
Initializes the members.

Overrides:
initialize in class AbstractGeneticAlgorithm

defineOptions

public void defineOptions()
Adds options to the internal list of options.

Specified by:
defineOptions in interface OptionHandler
Overrides:
defineOptions in class AbstractGeneticAlgorithm

setBits

public void setBits(int value)
Bits per gene.

Parameters:
value - the number of bits.

getBits

public int getBits()
Gets the number of bits.

Returns:
the number of bits

bitsTipText

public String bitsTipText()
Returns the tip text for this property.

Returns:
tip text for this property suitable for displaying in the GUI or for listing the options.

calcFitness

public void calcFitness()
Calculates the fitness of the population.

Specified by:
calcFitness in class AbstractGeneticAlgorithm

preRun

protected void preRun()
Some more initializations.

Overrides:
preRun in class AbstractGeneticAlgorithm

getDataDef

public PackDataDef getDataDef()
Specified by:
getDataDef in class PackDataGeneticAlgorithm

getDataSetups

public Vector<PackData> getDataSetups()
Specified by:
getDataSetups in class PackDataGeneticAlgorithm

optimise

public OptData optimise(OptData datadef,
                        FitnessFunction fitness)
Specified by:
optimise in class AbstractOptimiser

cleanUp

public void cleanUp()
Cleans up data structures, frees up memory.

Specified by:
cleanUp in interface CleanUpHandler
Overrides:
cleanUp in class AbstractOptimiser

main

public static void main(String[] args)


Copyright © 2012 University of Waikato, Hamilton, NZ. All Rights Reserved.