-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGASolver.hpp
58 lines (44 loc) · 1.39 KB
/
GASolver.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// GASolver.hpp
// uloha1
//
// Created by David Ungurean on 28/12/2016.
// Copyright © 2016 ungurean. All rights reserved.
//
#ifndef GAProblem_hpp
#define GAProblem_hpp
#include <stdio.h>
#include "Problem.hpp"
#include "Chromosome.hpp"
#include "GASettings.hpp"
class Chromosome;
class GASolver {
public:
GASolver(GASettings settings, Problem problem);
// main
double solveGeneticAlgorithm();
// process
void initPopulation();
void crossOver(std::vector<Chromosome> & newPopulation);
void mutation(std::vector<Chromosome> & newPopulation);
void keepElitists(std::vector<Chromosome> & newPopulation);
// selection
Chromosome tournamentSelection(int tournamentSize);
Chromosome rouletteSelection(int participantsCount);
Chromosome rankBasedSelection(int participantsCount);
// crossover
Chromosome uniformCrossover(const Chromosome & a, const Chromosome &b);
Chromosome randomCrossover(const Chromosome & a, const Chromosome &b);
Chromosome singlePointCrossover(const Chromosome & a, const Chromosome &b);
// info
double maxFitness() const;
double averageFitness() const;
private:
const GASettings settings;
const Problem problem;
std::vector<Chromosome> population;
// debugging helpers
public:
void printPopulation(int generation);
};
#endif /* GAProblem_hpp */