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 pathtour.hpp
More file actions
99 lines (83 loc) · 2.07 KB
/
Copy pathtour.hpp
File metadata and controls
99 lines (83 loc) · 2.07 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// Created by Amy Hong on 2018-11-11.
//
#ifndef GENETICALGORITHM_TOUR_HPP
#define GENETICALGORITHM_TOUR_HPP
#define CITIES_IN_TOUR 32
#define MUTATION_RATE 15
#include <iomanip>
#include <numeric>
#include <vector>
#include "city.hpp"
/**
* A list of cities to travel.
*/
class tour : std::vector<city *> {
public:
/**
* Constructor of this tour.
*/
tour() = default;
/**
* Constructor of this tour.
*
* @param cities cities to travel.
*/
explicit tour(std::vector<city *> cities);
/**
* Adds a city at the end of this tour.
*
* @param c city to travel.
*/
void add_city(city *c);
/**
* Shuffles the cities in this tour.
*/
void shuffle_cities();
/**
* Reports the distance between the cities as they are listed in this tour.
*
* @return distance between the cities as they are listed in this tour.
*/
double get_tour_distance() const;
/**
* Determines the fitness of this tour.
*
* @return
*/
double determine_fitness() const;
/**
* Mutates this tour.
*/
void mutate();
/**
* Creates a new tour from a given set of parent tours.
*
* @return new tour from a given set of parent tours.
*/
tour crossover(tour parent);
/**
* Checks if this tour contains a specified city.
*
* @param c city to check.
* @return true if this tour contains the specified city.
*/
bool contains_city(city *c) const;
/**
* Beautifies output text.
*
* @param os ostream.
* @param t tour to beautify output text.
* @return beautified output text.
*/
friend std::ostream &operator<<(std::ostream &os, const tour &t);
/**
* Returns true if l's total tour distance is shorter than r's distance.
*
* @param l tour to compare.
* @param r tour to compare.
* @return true if l's total tour distance is shorter than r's distance.
*/
friend bool operator<(const tour &l, const tour &r);
};
#endif //GENETICALGORITHM_TOUR_HPP