org.generation5.demos
Class EvoTravellingSalesman

java.lang.Object
  extended byorg.generation5.util.TravellingSalesman
      extended byorg.generation5.demos.EvoTravellingSalesman
All Implemented Interfaces:
java.lang.Comparable, Evolvable, Visualizable

public class EvoTravellingSalesman
extends TravellingSalesman
implements Evolvable

This class implements a simple evolvable solution to the travelling salesman problem.


Field Summary
protected  double fitnessValue
          The fitness value.
protected static java.util.Random random
          An instance of java.util.Random, useful for generating a range of random numbers.
 
Fields inherited from class org.generation5.util.TravellingSalesman
cityCoordinates, maximumCities, maximumX, maximumY, nodeLabels, numberCities, route, routeGradient
 
Constructor Summary
EvoTravellingSalesman()
          Creates a new instance of EvoTravellingSalesman
 
Method Summary
 void calculateFitness()
          Calculate the fitness of this route.
 int compareTo(java.lang.Object o)
          Implementation for the Comparable interface.
protected  void flip(int i1, int i2)
          Flip two route positions.
 double getFitness()
          Return the fitness of this route.
static void main(java.lang.String[] args)
          A basic test function.
 Evolvable mate(Evolvable partner)
          Mate two routes together.
 void mutate()
          Mutates a route.
 void randomInitialize()
          Initialize the route randomly.
 java.lang.String toString()
          Returns the route as a string.
 
Methods inherited from class org.generation5.util.TravellingSalesman
addCity, addCity, getCity, getCityDistance, getDimensionX, getDimensionY, render, resetCities, routeLength, routeLength, setDimension, setMaximumCities, writeImage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fitnessValue

protected double fitnessValue
The fitness value.


random

protected static java.util.Random random
An instance of java.util.Random, useful for generating a range of random numbers.

Constructor Detail

EvoTravellingSalesman

public EvoTravellingSalesman()
Creates a new instance of EvoTravellingSalesman

Method Detail

main

public static void main(java.lang.String[] args)
Description copied from class: TravellingSalesman
A basic test function.

Parameters:
args - the command line arguments

toString

public java.lang.String toString()
Returns the route as a string.

Returns:
the route being used.

calculateFitness

public void calculateFitness()
Calculate the fitness of this route. This is simply done by return the route length.

Specified by:
calculateFitness in interface Evolvable

mate

public Evolvable mate(Evolvable partner)
Mate two routes together.

Specified by:
mate in interface Evolvable
Parameters:
partner - Partner object.
Returns:
the child route.

mutate

public void mutate()
Mutates a route.

Specified by:
mutate in interface Evolvable

randomInitialize

public void randomInitialize()
Initialize the route randomly.

Specified by:
randomInitialize in interface Evolvable

flip

protected void flip(int i1,
                    int i2)
Flip two route positions. Used by initializing and mutation routines.

Parameters:
i1 - the first index.
i2 - the second index.

compareTo

public int compareTo(java.lang.Object o)
Implementation for the Comparable interface. Compares two route's length.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - object to compare to.
Returns:
fitnessValue < o.fitnessValue

getFitness

public double getFitness()
Return the fitness of this route.

Specified by:
getFitness in interface Evolvable
Returns:
the fitness of the route (route length).

This documentation is part of the Generation5 JDK.