Implementation of the genetic algorithm.
More...
#include <ga.hpp>
|
| ga (const parameters ¶ms, 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...
|
|
Implementation of the genetic algorithm.
◆ ga()
Standard constructor. Initializes parameters of the genetic algorithm. Also initializes vectors corresponding to the populations with the agents parameters.
- Parameters
-
params | Parameters of the genetic algorithm |
agent_params | Parameters of the agents |
◆ crossover_population()
ga::crossover_population |
( |
| ) |
|
|
private |
Perform crossover on an entire population in accordance with the crossover rate.
◆ fill_population()
Fill the population with the last population saved.
◆ init_population()
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
-
fresh | If true, initializes the population with random agents. If false, initializes the populations with the last population saved. |
fitness | Tool used to processed results |
◆ select_population()
ga::select_population |
( |
| ) |
|
|
private |
Create a new population by selecting good agent.
- See also
- selection()
◆ selection()
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.
◆ 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
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: