IAtari
Genetic algorithm generating AI capable to play Atari2600 games.
ga Class Reference

Implementation of the genetic algorithm. More...

#include <ga.hpp>

Classes

struct  parameters
 Parameters of the genetic algorithm. More...
 

Public Member Functions

 ga (const parameters &params, const agent::parameters &agent_params)
 Standard constructor. Initializes parameters of the genetic algorithm. Also initializes vectors corresponding to the populations with the agents parameters. More...
 
void run (bool fresh, Fitness fitness)
 Executes the genetic algorithm. More...
 

Private Member Functions

int selection () const
 Select the best agent among a pool of randomly selected agent. More...
 
void init_population ()
 Create whole new population with agents made of random instructions. More...
 
void fill_population ()
 Fill the population with the last population saved. More...
 
void select_population ()
 Create a new population by selecting good agent. More...
 
void crossover_population ()
 Perform crossover on an entire population in accordance with the crossover rate. More...
 
void mutate_population ()
 Perform mutation on an entire population in accordance with the mutation rate. More...
 

Private Attributes

const parameters params
 
std::vector< agentcurrent_population
 
std::vector< agentnew_population
 
std::vector< double > population_fitness
 

Detailed Description

Implementation of the genetic algorithm.

Constructor & Destructor Documentation

◆ ga()

ga::ga ( const parameters params,
const agent::parameters agent_params 
)

Standard constructor. Initializes parameters of the genetic algorithm. Also initializes vectors corresponding to the populations with the agents parameters.

Parameters
paramsParameters of the genetic algorithm
agent_paramsParameters of the agents

Member Function Documentation

◆ crossover_population()

ga::crossover_population ( )
private

Perform crossover on an entire population in accordance with the crossover rate.

◆ fill_population()

ga::fill_population ( )
private

Fill the population with the last population saved.

Remarks
If there is not enough agents to fill the new population, random agents are used.

◆ init_population()

ga::init_population ( )
private

Create whole new population with agents made of random instructions.

◆ mutate_population()

ga::mutate_population ( )
private

Perform mutation on an entire population in accordance with the mutation rate.

◆ run()

void ga::run ( bool  fresh,
Fitness  fitness 
)

Executes the genetic algorithm.

First of all, the algorithm initializes the population with random agents or the last population saved.
Then, the agents are tested and their fitness calculated. If one of them is better than the current best agent, the best agent is saved.
Finally, a new population is generated by selecting best agents among pools of current agents. They are also crossed and mutated. This population is saved.
The algorithm loops on these newly generated populations until all iterations are done.
It also saves information that will be useful to produce stats as .txt file.

Parameters
freshIf true, initializes the population with random agents. If false, initializes the populations with the last population saved.
fitnessTool used to processed results

◆ select_population()

ga::select_population ( )
private

Create a new population by selecting good agent.

See also
selection()

◆ selection()

ga::selection ( ) const
private

Select the best agent among a pool of randomly selected agent.

Returns
Index of a "good" agent, i.e. the best agent in a pool of randomly selected agent.

Member Data Documentation

◆ current_population

std::vector<agent> ga::current_population
private

Current population as a list of agents

◆ new_population

std::vector<agent> ga::new_population
private

Newly generated population as a list of agents

◆ params

const parameters ga::params
private

Structure containing the parameters

◆ population_fitness

std::vector<double> ga::population_fitness
private

Fitness score corresponding to the current population


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