-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
126 lines (108 loc) · 3.29 KB
/
main.cpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "TSP.hpp"
#include <iostream>
int main() {
cost_matrix_t cm = {{INF, 10, 8, 19, 12},
{10, INF, 20, 6, 3},
{8, 20, INF, 4, 2},
{19, 6, 4, INF, 7},
{12, 3, 2, 7, INF}};
// StageState SS1(cm);
//
// //redukcja macierzy
// std::cout << SS1.reduce_cost_matrix() << std::endl;
// std::cout << SS1.get_matrix() << std::endl;
//
// //wybór nowego wierzchołka
// NewVertex new_vert = SS1.choose_new_vertex();
// //dodanie wierzch. do sciezki (unsorted)
// SS1.append_to_path(new_vert.coordinates);
// std::cout << new_vert.coordinates.row + 1<< ", " << new_vert.coordinates.col +1 << std::endl;
// std::cout << std::endl;
//
// //aktualizacja macierzy kosztów
// SS1.update_cost_matrix(new_vert.coordinates);
//
// std::cout << SS1.get_matrix() << std::endl;
//
// std::cout << SS1.reduce_cost_matrix() << std::endl;
// std::cout << SS1.get_matrix() << std::endl;
//
// new_vert = SS1.choose_new_vertex();
// SS1.append_to_path(new_vert.coordinates);
// std::cout << new_vert.coordinates.row + 1<< ", " << new_vert.coordinates.col +1 << std::endl;
// SS1.update_cost_matrix(new_vert.coordinates);
//
//
//
// std::cout << SS1.get_matrix() << std::endl;
// std::cout << SS1.reduce_cost_matrix() << std::endl;
// std::cout << SS1.get_matrix() << std::endl;
//
//
// new_vert = SS1.choose_new_vertex();
// SS1.append_to_path(new_vert.coordinates);
// SS1.update_cost_matrix(new_vert.coordinates);
// std::cout << new_vert.coordinates.row + 1<< ", " << new_vert.coordinates.col +1 << std::endl;
//
// std::cout << SS1.get_matrix() << std::endl;
//
// for(auto i : SS1.get_unsorted_path()){
// std::cout << i.row + 1 <<i.col + 1 <<std::endl;
// }
//
// auto a = SS1.get_path();
//
//
// std::cout << SS1.get_matrix() << std::endl;
tsp_solutions_t result = solve_tsp(cm);
for (auto elem : result) {
std::cout << elem.lower_bound << " : ";
for (auto pelem : elem.path) {
std::cout << pelem << " ";
}
std::cout << "\n";
}
std::cout << "\n";
/* Rozwiązania:
* 32 : 3 4 5 2 1
* 32 : 2 5 4 3 1
*/
cost_matrix_t cm_2 {
{INF, 12, 3, 45, 6},
{78, INF, 90, 21, 3},
{ 5, 56, INF, 23, 98},
{12, 6, 8, INF, 34},
{ 3, 98, 3, 2, INF}
};
tsp_solutions_t result2 = solve_tsp(cm_2);
for (auto elem : result2) {
std::cout << elem.lower_bound << " : ";
for (auto pelem : elem.path) {
std::cout << pelem << " ";
}
std::cout << "\n";
}
/* Rozwiązanie:
* 30 : 4 3 2 0 1
*/
cost_matrix_t cm3 {
{INF, 3, 4, 2, 7},
{3, INF, 4, 6, 3},
{4, 4, INF, 5, 8},
{2, 6, 5, INF, 6},
{7, 3, 8, 6, INF},
};
/* Rozwiązania:
* 19 : 4 3 0 2 1
* 19 : 1 2 0 3 4
*/
tsp_solutions_t solutions = solve_tsp(cm3);
for (auto elem : solutions) {
std::cout << elem.lower_bound << " : ";
for (auto pelem : elem.path) {
std::cout << pelem << " ";
}
std::cout << "\n";
}
return EXIT_SUCCESS;
}