Add Generation
Some more complex algorithms are not yet implemented.
This commit is contained in:
parent
0d686b2008
commit
2c37b90ad8
3 changed files with 156 additions and 1 deletions
57
src/Generation.hpp
Normal file
57
src/Generation.hpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#pragma once
|
||||
|
||||
#include <random>
|
||||
#include <vector>
|
||||
#include "Chromosome.hpp"
|
||||
#include "Fitness.hpp"
|
||||
|
||||
|
||||
|
||||
class Generation
|
||||
{
|
||||
public:
|
||||
static size_t size;
|
||||
static size_t living;
|
||||
static Fitness* fitness;
|
||||
static std::mt19937_64* re;
|
||||
|
||||
Generation();
|
||||
|
||||
enum CullType
|
||||
{
|
||||
CUTOFF,
|
||||
ROULETTE
|
||||
};
|
||||
|
||||
void updateFitness();
|
||||
void cull(CullType algorithm=Generation::ROULETTE);
|
||||
void reproduce(float crossover=0.5); // how often a child is the result of two parents,
|
||||
// and not simply mutation.
|
||||
|
||||
struct Individual
|
||||
{
|
||||
// Individual(Chromosome& father, Chromosome& mother) : chromosome(father, mother) {}
|
||||
|
||||
Chromosome chromosome;
|
||||
unsigned long long fitness = 0;
|
||||
bool fitnessEvaluated = false;
|
||||
bool alive = true;
|
||||
};
|
||||
|
||||
std::vector<Individual> individuals;
|
||||
|
||||
private:
|
||||
// all of the culling algorithms can assume:
|
||||
// - sorted array
|
||||
// - alive flag set to true on all individuals
|
||||
void cullCutoff();
|
||||
void cullRoulette();
|
||||
|
||||
// pool of Chromosomes
|
||||
// sort pool?
|
||||
// min/max/median
|
||||
// extract stats
|
||||
// calculate fitness
|
||||
// cull/selection
|
||||
// render full generation? No
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue