Introduction to Evolutionary Algorithms

"He is one of those people who would be enormously improved by death"

-- H H Munro (1870 - 1916)

7. The Killer

The killer is responsible for killing off unfit members of the population. The killer is passed a reference to the population every generation, when the "Kill" function is called. This function should delete a given number of individuals from the population and return the number killed. Listing 6 shows the class declaration for TKiller...

TKiller = class(TComponent)
    // Function to kill off some unfit population members
    // should delete them from the list and return the number killed
    function Kill(Pop : TPopulation) : Integer; virtual; abstract;
  end;

listing 6: TKiller - base class for killing unfit population members

The TKillerPercentage implements a very basic killing scheme, simply killing a fixed percentage of the population each generation. The percentage to be killed is set in the property "Percentage". The individuals killed are selected from the bottom of the population after it has been sorted into fitness order. This means that less fit individuals will be killed and fitter ones will survive. Killing off the least fit members of the population gives us the Natural Selection aspect of the Evolutionary Algorithm.

interface

type
  TKillerPercentage = class(TKiller)
  private
    FPer: Double;
    procedure SetPercentage(const Value: Double);
  public
    function Kill(Pop : TPopulation) : Integer; override;
  published
    // Percentage of population to be killed
    property Percentage : Double read FPer write SetPercentage;
  end;


implementation

function TKillerPercentage.Kill(Pop: TPopulation): Integer;
var
  KillCount, i : Integer;
begin
  // Work out the number we have to kill
  KillCount := Floor(Pop.Count * (FPer / 100));

  // Delete the worst individuals - assuming the population is sorted
  for i := 1 to KillCount do
    Pop.Delete(Pop.Count - 1);

  // Return the number killed
  Result := KillCount;
end;

listing 7: TKillerPercentage - class for killing the worst x% of the population

Back
Contents
Next