org.generation5.demos
Class EvoHelloWorld

java.lang.Object
  extended byorg.generation5.bio.EvolveStandard
      extended byorg.generation5.demos.EvoHelloWorld
All Implemented Interfaces:
java.lang.Comparable, Evolvable

public class EvoHelloWorld
extends EvolveStandard

Attempts to evolve a target string, defaulting to "Hello World!". All valid digits are acceptable inputs for the string.


Field Summary
protected  java.lang.StringBuffer dataString
          The mutable data string.
protected static java.lang.String targetString
          The target string to evolve.
 
Fields inherited from class org.generation5.bio.EvolveStandard
fitnessValue, minimizeFitness, random
 
Constructor Summary
EvoHelloWorld()
          Creates a new instance of EvoHelloWorld
 
Method Summary
 void calculateFitness()
          The fitness is calculated as the sum of the differences between the data string and the target string.
static java.lang.String getTargetString()
          Return the target string being evolved.
static void main(java.lang.String[] args)
          Run the genetic algorithm with a target string.
 Evolvable mate(Evolvable partner)
          Mate two strings with a simple one-point crossover.
 void mutate()
          Mutate this string between -2 and +2 characters.
 void randomInitialize()
          Initialize the string to a random collection of characters.
static void setTargetString(java.lang.String ts)
          Set the target string.
 java.lang.String toString()
          Return an immutable version of dataString.
 
Methods inherited from class org.generation5.bio.EvolveStandard
compareTo, getFitness
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dataString

protected java.lang.StringBuffer dataString
The mutable data string.


targetString

protected static java.lang.String targetString
The target string to evolve.

Constructor Detail

EvoHelloWorld

public EvoHelloWorld()
Creates a new instance of EvoHelloWorld

Method Detail

main

public static void main(java.lang.String[] args)
Run the genetic algorithm with a target string. The best population member is printed for every iteration.

Parameters:
args - the command line arguments

calculateFitness

public void calculateFitness()
The fitness is calculated as the sum of the differences between the data string and the target string.

Specified by:
calculateFitness in interface Evolvable
Specified by:
calculateFitness in class EvolveStandard

mate

public Evolvable mate(Evolvable partner)
Mate two strings with a simple one-point crossover.

Specified by:
mate in interface Evolvable
Specified by:
mate in class EvolveStandard
Parameters:
partner - the partner string to mate with.
Returns:
the new child string.

mutate

public void mutate()
Mutate this string between -2 and +2 characters.

Specified by:
mutate in interface Evolvable
Specified by:
mutate in class EvolveStandard

randomInitialize

public void randomInitialize()
Initialize the string to a random collection of characters. The size of the string is fixed to that of the target string.

Specified by:
randomInitialize in interface Evolvable
Specified by:
randomInitialize in class EvolveStandard

toString

public java.lang.String toString()
Return an immutable version of dataString.

Returns:
the data string.
See Also:
dataString

getTargetString

public static java.lang.String getTargetString()
Return the target string being evolved. This defaults to "Hello World!".

Returns:
the target string.

setTargetString

public static void setTargetString(java.lang.String ts)
Set the target string.

Parameters:
ts - the new target string.

This documentation is part of the Generation5 JDK.