-
Notifications
You must be signed in to change notification settings - Fork 0
/
population.hpp
33 lines (28 loc) · 930 Bytes
/
population.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#include "config.hpp"
#include <vector>
#include <memory>
class Chromosome;
// Class representing a population of chromosomes in a specific generation
class Population {
public:
Population(int populationSize); // create random population
std::vector<std::shared_ptr<Chromosome>>
getOffsprings(std::shared_ptr<Chromosome> parent1,
std::shared_ptr<Chromosome> parent2);
std::shared_ptr<Chromosome> createChromosome();
void mutation(double mutationRate);
void crossover();
void calculateTotalScore();
void selection(double selectionPressure,
void (*selectionFunction)(
std::vector<std::shared_ptr<Chromosome>> &chromosomes,
int survivorsSize));
int populationSize;
int totalFitnessScore;
int totalScore;
int generation;
std::vector<std::shared_ptr<Chromosome>> chromosomes;
std::shared_ptr<Chromosome> bestChromosome;
std::shared_ptr<Chromosome> worstChromosome;
};