Introduction to Evolutionary Algorithms

"I have not failed, I have just found 10,000 ways that don't work"

-- Thomas Edison (1847 - 1931)

5. The Individual

As mentioned in section 3, to implement an evolutionary algorithm to solve a problem we need to have a means to represent the solution. The TIndividual class (shown in listing 2) defines the interface which all individuals must implement.

TIndividual = class(TInterfacedObject)
  private
    // The fitness value
    FFitness: Double;
  published
    property Fitness : Double read FFitness write FFitness;
  end;

listing 2: TIndividual - base class for representing EA population members

As the calculation of fitness is often the most time consuming task in EAs, the TIndividual class has a property "Fitness" which is used to cache the fitness value of the individual. The calculation of this value and it's interpretation are dealt with by the Examiner and other classes detailed in the following sections.

The TTSPIndividual class is a representation of a solution to the travelling salesman problem. The class stores a list of the cities to be visited. Each city is represented by an integer in the range 0 .. n - 1, where n is the number of cities on the map. Each city must be visited exactly once and so must appear exactly once in the "Route" array.

TTSPIndividual = class(TIndividual)
  private
    // The route we travel
    FRoute : array of Integer;
    // The number of steps on the route
    FSteps: Integer;
    // The internally stored fitness value
    FFitness: Double;
    // Getters...
    function GetRoute(I: Integer): Integer;
    // Setters...
    procedure SetRoute(I: Integer; const Value: Integer);
    procedure SetSteps(const Value: Integer);
  public
    // Constructor, called with initial route size
    constructor Create(Size : Integer); reintroduce;
    // Destructor
    destructor Destroy; override;
    // Properties
    property Route[I : Integer] : Integer read GetRoute write SetRoute;
    property Steps : Integer read FSteps write SetSteps;
    property Fitness : Double read FFitness write FFitness;
  end;

listing 3: TTSPIndividual class for representing a salesman's route

Back
Contents
Next