Rename GenerationLimit to GenerationLimitCondition. Add test for this class.
[genetic.git] / src / main.cpp
1 #include <iostream>
2 #include <vector>
3 #include <map>
4 #include <string>
5
6 #include "gene.h"
7 #include "chromosome.h"
8 #include "generation.h"
9 #include "generator/bitGenerator.h"
10
11 #include "selection/rouletteSelection.h"
12 #include "selection/linearRankSelection.h"
13 #include "crossover/crossover.h"
14 #include "mutation/mutation.h"
15 #include "fitness/wsti.h"
16
17 #include "algorithm.h"
18 #include "condition/condition.h"
19 #include "condition/generationLimitCondition.h"
20
21 using namespace std;
22 using namespace genetic;
23
24 int main() {
25     typedef Gene<bool> _Gene;
26     typedef Chromosome<_Gene> _Chromosome;
27
28     typedef WSTI<_Chromosome> _Fitness;
29     typedef LinearRankSelection<_Chromosome> _Selection;
30     typedef Crossover<_Chromosome> _Crossover;
31     typedef Mutation<_Chromosome> _Mutation;
32
33     typedef generator::BitGenerator<_Chromosome> _Generator;
34     typedef Algorithm<_Chromosome, _Selection, _Crossover, _Mutation, _Fitness> _Algorithm;
35     typedef GenerationLimitCondition<_Chromosome> _Condition;
36
37     const int chromosomeSize = 10;
38     const int generationSize = 200;
39     const double crossoverChance = 0.75;
40     const double mutationChance = 0.01;
41
42     _Fitness fitness(0.5, 2.5);
43     _Generator generationGenerator(generationSize, chromosomeSize);
44
45     _Algorithm algorithm(generationGenerator, fitness, crossoverChance, mutationChance);
46     _Condition condition(1000);
47
48     algorithm.searchForResult(condition);
49
50     return 0;
51 }