pub trait FitnessFunction<const N: usize, const NSYMS: usize> {
    fn run(&self, chromosone: &[Gene; N]) -> Vec<f64>;
    fn nscores(&self) -> usize;

    fn names(&self) -> Vec<FitnessName> { ... }
    fn weights(&self) -> Vec<f64> { ... }
}
Expand description
  • A FitnessFunction returns a set of fitness scores when passed a chromosone.

  • This is implemented as an enum rather than a trait so that we can store them

  • inside a const FitnessConfig

  • Fitness scores are floating point numbers where a higher number is considered

  • better. Negative numbers are allowed, so if you wish to optimize to zero you

  • may simply return the negative of the absolute value.

  • NaN values are valid scores, and indicate that the score cannot be

  • calculated. When comparing scores, any number compared to a NaN is considered

  • a tie.

  • Implementations: color_count::ColorCount, distance::Distance, weighted_count::WeightedCount

Required Methods

returns a vector of floats where bigger numbers are better. If your fitness function optimizes to 0, remember that 0 is the biggest negative number. NaN is also a valid score, and means that the score cannot be compared and is considered a tie with any other number.

Provided Methods

provides an [FitnessFunction.nscores] length human readable name for the scores returned. Optional, but useful for debugging

not all games take weights into account, but some do. The vector must be [FitnessFunction.nscores] long. Scores with higher weights are worth weight times as much as nominal scores. Note that the value of the score is irrelevant – scores are never compared with scores in a different position, scores are only compared with the same score on a different candidate. The weight signifies how valuable it is that this particular score on one candidate is higher or lower than the same score on a different candidate.

Implementors