-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPEA1.cpp
More file actions
138 lines (98 loc) · 3.29 KB
/
PEA1.cpp
File metadata and controls
138 lines (98 loc) · 3.29 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
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
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>
#include "Graph.h"
#include "FileHandler.h"
#include "BruteForce.h"
#include "Dynamic.h"
#include "BranchBound.h"
#include <cstdlib>
#include <chrono>
using namespace std;
string decide_load() {
cout << "\ndo you want to load data from file, or generate random data? <file, random>: ";
string dataPick;
cin >> dataPick;
if (!(dataPick == "file" || dataPick == "random"))
exit(-1);
return dataPick;
}
int get_size() {
cout << "\nchoose number of vertices (cities) in random graph ";
int dataPick;
cin >> dataPick;
if (dataPick < 0)
exit(-1);
return dataPick;
}
string get_path() {
cout << "\nprovide absolute path for the file: ";
string dataPick;
cin >> dataPick;
return dataPick;
}
void loadData(Graph*& data, int& size) {
string dataLoad = decide_load();
if (dataLoad == "random") {
size = get_size();
data = new Graph(size);
}
else if (dataLoad == "file") {
string path = get_path();
data = FileHandler::load_graph(path);
}
data->print();
}
void measure() {
int* vertices_lenghts = new int[]{ 17 };
for (int v_l = 0; v_l < 1; v_l++) {
cout << "\n\n-------------------------------------------------------------\n";
cout << "vertices number: " << vertices_lenghts[v_l] << endl;
if (vertices_lenghts[v_l] <= 13)
BruteForce::measure(50, vertices_lenghts[v_l]);
Dynamic::measure(50, vertices_lenghts[v_l]);
BranchBound::measure_lower(50, vertices_lenghts[v_l]);
}
}
int main() {
Graph* data = nullptr;
int size = 0;
bool exitProgram = false;
bool hasLastLoadedData = false;
string choose = "";
while (!exitProgram) {
cout << "\033[2J\033[1;1H";
cout << "=====================================================================================\n";
cout << "Measuring ATSP\n";
cout << "=====================================================================================\n\n";
if (hasLastLoadedData) {
std::cout << "You have loaded data";
data->print();
std::cout << "Do you wish to operate on it? <y,n>: ";
cin >> choose;
}
if (choose != "y" || choose == "") {
loadData(data, size);
hasLastLoadedData = true;
}
cout << "Pick one of the algorithms to measure <bruteforce, BB_lower, dynamic>: ";
string algorithm;
cin >> algorithm;
while (!(algorithm == "bruteforce" || algorithm == "BB_lower" || algorithm == "dynamic")) {
cout << "\nPlease provide legal option: ";
cin >> algorithm;
}
if (algorithm == "bruteforce") {
BruteForce::solve(data);
}
else if (algorithm == "dynamic") {
Dynamic::solve(data);
}
else if (algorithm == "BB_lower") {
BranchBound::solve_lower(data);
}
cout << "Continue program? <y,n>: ";
string continueChoose;
cin >> continueChoose;
if (continueChoose != "y")
exitProgram = true;
}
}