This repository was archived by the owner on Dec 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm.hpp
More file actions
83 lines (65 loc) · 1.38 KB
/
algorithm.hpp
File metadata and controls
83 lines (65 loc) · 1.38 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// Created by Amy Hong on 2018-11-24.
//
#ifndef GENETICALGORITHM_ALGORITHM_HPP
#define GENETICALGORITHM_ALGORITHM_HPP
#include <iostream>
#include "randomizer.hpp"
#define POPULATION_SIZE 32
#define ITERATIONS 1000
#define PARENT_POOL_SIZE 5
#define NUMBER_OF_ELITES 1
#define NUMBER_OF_PARENTS 2
#define IMPROVEMENT_FACTOR 0.1
class algorithm {
private:
/** Randomizer. */
randomizer rand;
/** List of tours. */
std::vector<tour> population;
public:
/**
* Runs this algorithm.
*/
void run();
/**
* Initializes population.
*/
void init();
/**
* Makes children tours by crossover.
*/
void crossover();
/**
* Mutates some tours in population.
*/
void mutate();
/**
* Evaluates progression.
*
* @param prev previous tour to compare.
* @return progression rate.
*/
double evaluate(tour prev);
/**
* Reports progress by std::cout.
*
* @param improvement improvement rate to print.
*/
void report(double improvement);
/**
* Sorts population.
*/
void sort();
/**
* Prints the entire list of tours in population.
*/
void print();
/**
* Returns a tour to use as a parent.
*
* @return tour to use as a parent tour.
*/
tour choose_parent();
};
#endif //GENETICALGORITHM_ALGORITHM_HPP