-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCGeneticAlgorithm.h
More file actions
62 lines (38 loc) · 1.11 KB
/
CGeneticAlgorithm.h
File metadata and controls
62 lines (38 loc) · 1.11 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include <vector>
#include "CIndividual.h"
#include "GAProblem.h"
class CGeneticAlgorithm
{
public:
CGeneticAlgorithm();
~CGeneticAlgorithm();
bool configureRun(int populationSize, double mutationProbability, double crossOverProbability, GAProblem* GAProblem);
void run(int numberOfIterations);
std::vector<bool> getBestGenotype();
double getBestQuality();
void printBestResult();
bool isConfigured();
private:
void generatePopulation();
void resetPopulation();
void processSingleGeneration();
bool crossOverDraw();
CIndividual* getRandomIndiv();
CIndividual* drawAndSelectFitterIndiv();
static std::random_device rd;
static std::mt19937 gen;
static std::uniform_int_distribution<> disTF;
static std::uniform_int_distribution<> disRand;
double _mutationProbability;
double _crossOverProbability;
int _genotypeLength;
int _populationSize;
GAProblem* _GAProblem;
std::vector<CIndividual*> _population;
std::pair<CIndividual*, CIndividual*> _parents;
std::pair<CIndividual*, CIndividual*> _children;
double _bestQuality;
std::vector<bool> _bestGenotype;
bool _configured;
};