Creating an IFitnessMeasure Subclass

Function/Role

A fitness measure class is responsible for two tasks.

It firstly provides a way of tracking the fitness of some entity (e.g. an individual program) and thus is a member of the IProgram class. The methods implemented in the abstract base class IFitnessMeasure all treat a lower fitness as better and a fitness of 0 as best.

Secondly, an instance of IFitnessMeasure is also responsible for calculating by how much a program's fitness should be increased based on its response to some IFitnessCase. This is another place the error-based or lower-is-fitter assumption manifests itself. This functionality is represented by the UpdateError method, which must be implemented by some subclass.


virtual void UpdateError(const RegisterCollection& fRV, const IFitnessCase* fc) = 0

How this method will work in detail depends on the type of problem the subclass of IFitnessMeasure is designed to be used with, however the general overall structure of an implementation of this method is as follows:

  1. Cast fc to the expected type of fitness case.
  2. If the result of the cast is null, report an error.
  3. Otherwise use the problem-dependent methods of the IFitnessCase fc subclass, the final register values of the program (stored in fRV) and the methods of this subclass of IFitnessMeasure to update the stored fitness measure in this.


virtual std::string ToString() const = 0

Because different measures of fitness will store different extra data in addition to the base measure of overall fitness (a single double) the conversion of a fitness measure to a string representation will be different for each class. Thus each subclass of IFitnessMeasure needs to implement its own ToString method, which will print out a raw string representation of the fitness of this fitness measure (i.e. by "raw string" we mean not prefixed by any // or other comment indicator, as this should be prepended as needed by the caller).



Christopher Fogelberg
fogelbchri@mcs.vuw.ac.nz or cgf.unimail@syntilect.com