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

EvoScript - a class that holds a collection of EvoParams (through them) is optimizable. There are 2 main ideas of working with them. (1) EvoScript can act as an interface (derive from it to make an EA-optimizable object) or (2) a generator object (store it in your EA-optimizable object). Create your final object in the UserClone() method. More...

#include <EvoScript.hh>

Public Member Functions

void SetFitness (float fitness)
 SetFitness - sets the fitness value (evaluation of how good the particular EvoScript object is). More...
 
float GetFitness () const
 GetFitness - gets the fitness value (evaluation of how good the particular EvoScript object is). More...
 
std::unique_ptr< EvoScriptSystemClone () const
 This method calls userClone() that is responsible for copying everything apart from EvoParams and then synchronizes the values of EvoParams from the original object.
 
virtual std::unique_ptr< EvoScriptUserClone () const =0
 Create your final optimizable object that is based on this EvoScript. In EA such object is often referred to as the phenotype. You do not need to clone the values of EvoParams, because they will be synchronized automatically.
 
void Randomize (std::mt19937_64 &randomGenerator)
 Sets all parameters (EvoParams) of the script to possible random values. More...
 
std::vector< std::unique_ptr< EvoScript > > GetRandomRealizations (std::mt19937_64 &randomGenerator, size_t count) const
 GetRandomRealizations - gets clones of the EvoScript with its EvoParams set to random possible values. More...
 
std::vector< std::reference_wrapper< EvoParam > > & GetEvoParams ()
 GetEvoParams - returns a collection of EvoParams that this EvoScript holds. More...
 
size_t EvoParamsCount () const
 EvoParamsCount - returns the number of EvoParams that this EvoScript holds. More...
 
const EvoParamGetEvoParamAt (size_t index) const
 GetEvoParamAt - returns the i-th EvoParam of the collection of parameters stored in this EvoScript. More...
 
void ExchangeParams (EvoScript &other, size_t inclusiveFrom, size_t exclusiveTo)
 ExchangeParams - swaps the values of selected EvoParams between two EvoScripts. Make sure that the other EvoScript has the same structure as the object on which this function was called. Preferably both instances should be clones of each other. More...
 
float CalculateSimilarity (const EvoScript &other) const
 CalculateSimilarity - this function calculates the similarity between two EvoScripts in the form of a number of corresponding EvoParam pairs that share the same value divided by the total number of such pairs. Thus, the value is normalized to the [0,1] interval. More...
 
virtual std::string ToString () const
 ToString - returns the string representation of the EvoScript object. It contains the assigned fitness value and the values of all EvoParams. More...
 

Protected Member Functions

void CopyEvoParamValuesFrom (const EvoScript &other)
 
void RegisterParam (EvoParam &parameter)
 
void RegisterParamsFromOther (const EvoScript &other)
 

Protected Attributes

std::vector< std::reference_wrapper< EvoParam > > evoParams {}
 

Detailed Description

EvoScript - a class that holds a collection of EvoParams (through them) is optimizable. There are 2 main ideas of working with them. (1) EvoScript can act as an interface (derive from it to make an EA-optimizable object) or (2) a generator object (store it in your EA-optimizable object). Create your final object in the UserClone() method.

Member Function Documentation

◆ CalculateSimilarity()

float grail::evolution::EvoScript::CalculateSimilarity ( const EvoScript other) const

CalculateSimilarity - this function calculates the similarity between two EvoScripts in the form of a number of corresponding EvoParam pairs that share the same value divided by the total number of such pairs. Thus, the value is normalized to the [0,1] interval.

Parameters
other- instance of another EvoScript object to which similarity is computed.
Returns
the computed similarity.

◆ EvoParamsCount()

size_t grail::evolution::EvoScript::EvoParamsCount ( ) const

EvoParamsCount - returns the number of EvoParams that this EvoScript holds.

Returns
the size of collection of EvoParams.

◆ ExchangeParams()

void grail::evolution::EvoScript::ExchangeParams ( EvoScript other,
size_t  inclusiveFrom,
size_t  exclusiveTo 
)

ExchangeParams - swaps the values of selected EvoParams between two EvoScripts. Make sure that the other EvoScript has the same structure as the object on which this function was called. Preferably both instances should be clones of each other.

Parameters
other- EvoScript object with which the parameter values are swapped.
inclusiveFrom- the starting index (inclusive) of the parameter to switch values with.
exclusiveTo- the last index (exclusive) of the parameter to switch values with. In total, (exclusiveTo - inclusiveFrom + 1) values will be exchanged.

◆ GetEvoParamAt()

const EvoParam & grail::evolution::EvoScript::GetEvoParamAt ( size_t  index) const

GetEvoParamAt - returns the i-th EvoParam of the collection of parameters stored in this EvoScript.

Parameters
index- the index of the returned EvoParam.
Returns
EvoParam.

◆ GetEvoParams()

std::vector< std::reference_wrapper< EvoParam > > & grail::evolution::EvoScript::GetEvoParams ( )

GetEvoParams - returns a collection of EvoParams that this EvoScript holds.

Returns
collection of EvoParams.

◆ GetFitness()

float grail::evolution::EvoScript::GetFitness ( ) const

GetFitness - gets the fitness value (evaluation of how good the particular EvoScript object is).

Returns
fitness value.

◆ GetRandomRealizations()

std::vector< std::unique_ptr< EvoScript > > grail::evolution::EvoScript::GetRandomRealizations ( std::mt19937_64 &  randomGenerator,
size_t  count 
) const

GetRandomRealizations - gets clones of the EvoScript with its EvoParams set to random possible values.

Parameters
randomGenerator- random numbers generator to use.
count- the number of realizations to get.
Returns
clones of the EvoScript with its EvoParams set to random possible values

◆ Randomize()

void grail::evolution::EvoScript::Randomize ( std::mt19937_64 &  randomGenerator)

Sets all parameters (EvoParams) of the script to possible random values.

Parameters
randomGenerator- random numbers generator to use.

◆ SetFitness()

void grail::evolution::EvoScript::SetFitness ( float  fitness)

SetFitness - sets the fitness value (evaluation of how good the particular EvoScript object is).

Parameters
fitness- the fitness value.

◆ ToString()

std::string grail::evolution::EvoScript::ToString ( ) const
virtual

ToString - returns the string representation of the EvoScript object. It contains the assigned fitness value and the values of all EvoParams.


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