Grail (C#)  1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
Grail.Evolution.Individual Class Referenceabstract

Represents an individual for evolutionary algorithms (EA).
It stores the encoding consisting of optimizable parameters (represented by BaseEvoParam and specialized EvoParam<Type>).
The members (fields or properties) should be registered for optimization using SetMemberParameterOptimizable methods in your implementation of the constructor.
In the optimization process, the EA will require assigning the fitness evaluation to the individual. Calculate it in your game environment based on the current values of Individual's parameters. More...

Inheritance diagram for Grail.Evolution.Individual:
Collaboration diagram for Grail.Evolution.Individual:

Public Member Functions

abstract Individual Instantiate ()
 Creates a new instance of the derived type from Individual. Do not forget to call SetMemberParameterOptimizable() in the constructor that will be called in this method. More...
 
Individual Clone ()
 Performs a deep copy of the individual. More...
 
List< IndividualCloneMany (int cloneCount)
 Performs a given number of copies of the individual. More...
 
void Randomize (Random random)
 Changes the values of each parameter in the encoding of the individual to random available ones. More...
 
ulong GetPossibleRealizationsCount ()
 
Returns
The maximum number of distinct parameterizations the individual may have.

 
List< IndividualGetRandomRealizations (Random random, int count)
 Returns count number of copies of the individuals with randomized parameter values. More...
 
override string ToString ()
 
int CompareTo (Individual other)
 
int Compare (Individual x, Individual y)
 
override bool Equals (object obj)
 
bool Equals (Individual other)
 
override int GetHashCode ()
 
float CalculateSimilarity (Individual other)
 This function calculates the similarity between two Individuals 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...
 

Public Attributes

const double FITNESS_NOT_INITIALIZED = -1.0
 Fitness score assigned to Individual before its evaluation. More...
 
int EvoParamsCount => parameters.Count
 Returns the number of parameters set as optimizable for evolutionary algorithms. More...
 

Protected Member Functions

void SetMemberParameterOptimizable (BaseEvoParam parameter)
 Call this method in a constructor and pass references to fields or properties stored in this object.
Marks a certain stored parameter as optimizable allowing it to be manipulated by the evolutionary algorithm (EA).
This operation essentially binds your class member with the object used by EA. During optimization, EA might change its value. You can then read the value of your field or property using memberName.Value.
More...
 
void SetMemberParameterOptimizable (IEnumerable< BaseEvoParam > parameter)
 Call this method in a constructor and pass references to fields or properties stored in this object.
Marks a certain stored parameter as optimizable allowing it to be manipulated by the evolutionary algorithm (EA).
This operation essentially binds your class member with the object used by EA. During optimization, EA might change its value. You can then read the value of your field or property using memberName.Value.
More...
 

Properties

double Fitness [get, set]
 Gets or sets the fitness value (evaluation of how good the particular Individual is).
You will typically adjust the state of the game based on the current Individual's encoding, perform a simulation and then assign the value to Fitness. More...
 
BaseEvoParam this[int index] [get]
 
- Properties inherited from Grail.Evolution.IFitnessProvider
double Fitness [get, set]
 

Detailed Description

Represents an individual for evolutionary algorithms (EA).
It stores the encoding consisting of optimizable parameters (represented by BaseEvoParam and specialized EvoParam<Type>).
The members (fields or properties) should be registered for optimization using SetMemberParameterOptimizable methods in your implementation of the constructor.
In the optimization process, the EA will require assigning the fitness evaluation to the individual. Calculate it in your game environment based on the current values of Individual's parameters.

Member Function Documentation

◆ CalculateSimilarity()

float Grail.Evolution.Individual.CalculateSimilarity ( Individual  other)
inline

This function calculates the similarity between two Individuals 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
otherInstance of another Individual object to which similarity is computed
Returns
The computed similarity.

◆ Clone()

Individual Grail.Evolution.Individual.Clone ( )
inline

Performs a deep copy of the individual.

Returns
A copy of the individual that holds the same parameter values.

◆ CloneMany()

List<Individual> Grail.Evolution.Individual.CloneMany ( int  cloneCount)
inline

Performs a given number of copies of the individual.

Parameters
cloneCount
Returns
A list of copies of the individual. For example, you can use this method to create the initial population.

◆ GetRandomRealizations()

List<Individual> Grail.Evolution.Individual.GetRandomRealizations ( Random  random,
int  count 
)
inline

Returns count number of copies of the individuals with randomized parameter values.

Parameters
randomA random number generator.
countThe number of individuals to return.

◆ Instantiate()

abstract Individual Grail.Evolution.Individual.Instantiate ( )
pure virtual

Creates a new instance of the derived type from Individual. Do not forget to call SetMemberParameterOptimizable() in the constructor that will be called in this method.

Returns
A new instance of an object that inherits from the Individual class.

◆ Randomize()

void Grail.Evolution.Individual.Randomize ( Random  random)
inline

Changes the values of each parameter in the encoding of the individual to random available ones.

Parameters
randomA random number generator.

◆ SetMemberParameterOptimizable() [1/2]

void Grail.Evolution.Individual.SetMemberParameterOptimizable ( BaseEvoParam  parameter)
inlineprotected

Call this method in a constructor and pass references to fields or properties stored in this object.
Marks a certain stored parameter as optimizable allowing it to be manipulated by the evolutionary algorithm (EA).
This operation essentially binds your class member with the object used by EA. During optimization, EA might change its value. You can then read the value of your field or property using memberName.Value.

Parameters
parameterA member stored in your Individual class of type BaseEvoParam. Typically, you will be using the EvoParam<Type>specialization.

◆ SetMemberParameterOptimizable() [2/2]

void Grail.Evolution.Individual.SetMemberParameterOptimizable ( IEnumerable< BaseEvoParam parameter)
inlineprotected

Call this method in a constructor and pass references to fields or properties stored in this object.
Marks a certain stored parameter as optimizable allowing it to be manipulated by the evolutionary algorithm (EA).
This operation essentially binds your class member with the object used by EA. During optimization, EA might change its value. You can then read the value of your field or property using memberName.Value.

Parameters
parameterA member of a collection type stored in your Individual class. Typically, you will be using the EvoParam<Type>specialization

Member Data Documentation

◆ EvoParamsCount

int Grail.Evolution.Individual.EvoParamsCount => parameters.Count

Returns the number of parameters set as optimizable for evolutionary algorithms.

◆ FITNESS_NOT_INITIALIZED

const double Grail.Evolution.Individual.FITNESS_NOT_INITIALIZED = -1.0

Fitness score assigned to Individual before its evaluation.

Property Documentation

◆ Fitness

double Grail.Evolution.Individual.Fitness
getset

Gets or sets the fitness value (evaluation of how good the particular Individual is).
You will typically adjust the state of the game based on the current Individual's encoding, perform a simulation and then assign the value to Fitness.


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