Grail (C++)  1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
grail::evolution::FitnessRepository Class Referencefinal

This class provides a functionality of assigning fitness values as averages from the previous evaluations.
It can be used to minimize the effects of variance when fitness calculation is non-deterministic.
Use 'AddSampleWithFitnessUpdate' method to store the current fitness and update it based on past evaluations. More...

#include <FitnessRepository.h>

Public Member Functions

 FitnessRepository (size_t maxSamplesPerIndividual=100)
 Constructs a new FitnessRepository instance. More...
 
std::size_t GetSampleCount (const Individual &individual) const
 Returns the number of fitness values currently stored for a given individual. More...
 
bool TryGetFitness (const Individual &individual, double &fitness) const
 
void AddSampleWithFitnessUpdate (Individual &individual)
 
void Serialize (const std::string &filename) const
 Serializes contents of the FitnessRepository so it can be loaded in another session using Deserialize().
. More...
 
bool Deserialize (const std::string &filename, const Individual &populationRepresentative)
 Loads previously saved contents of the FitnessRepository using the Serialize() method.
. More...
 

Detailed Description

This class provides a functionality of assigning fitness values as averages from the previous evaluations.
It can be used to minimize the effects of variance when fitness calculation is non-deterministic.
Use 'AddSampleWithFitnessUpdate' method to store the current fitness and update it based on past evaluations.

Constructor & Destructor Documentation

◆ FitnessRepository()

grail::evolution::FitnessRepository::FitnessRepository ( size_t  maxSamplesPerIndividual = 100)

Constructs a new FitnessRepository instance.

Parameters
maxSamplesPerIndividual- the number of fitness values to be stored per each individual.

Member Function Documentation

◆ Deserialize()

bool grail::evolution::FitnessRepository::Deserialize ( const std::string &  filename,
const Individual populationRepresentative 
)

Loads previously saved contents of the FitnessRepository using the Serialize() method.
.

Parameters
filename- the path where the state has been saved.
populationRepresentative- an individual with the same structure (exact derived type) as the ones saved. It will be used for cloning purposes.
Returns
- a boolean value that tells if the deserialization was successful.

◆ GetSampleCount()

std::size_t grail::evolution::FitnessRepository::GetSampleCount ( const Individual individual) const

Returns the number of fitness values currently stored for a given individual.

Parameters
individual= the given individual.
Returns
the number of fitness values currently stored for a given individual.

◆ Serialize()

void grail::evolution::FitnessRepository::Serialize ( const std::string &  filename) const

Serializes contents of the FitnessRepository so it can be loaded in another session using Deserialize().
.

Parameters
filename- the path where the state will be saved. If the file exists, it will be overridden.

◆ TryGetFitness()

bool grail::evolution::FitnessRepository::TryGetFitness ( const Individual individual,
double &  fitness 
) const

Attempts to calculate the fitness value of an individual equal to the average value of the stored samples.

Parameters
individual- the individual for which the fitness should be returned.
fitness- the calculated fitness value or -1.0 if the method returns false.
Returns
- A boolean value stating whether fitness could have been computed (there was at least one stored sample).

The documentation for this class was generated from the following files: