-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
75 lines (66 loc) · 1.57 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
#include <iostream>
#include <iomanip>
#include <getopt.h>
#include "PartC.h"
using namespace std;
void printHelp() {
cout << "This program has three modes: MST, FASTTSP, and OSTTSP\n";
cout << "To run this program, use -m or --mode followed by MST/FASTTSP/OPTTSP\n";
cout << "For example, to run in MST, use -m MST\n";
return;
}
void getOptions(int argc, char *argv[], string &mode) {
struct option long_options[] = {
{ "mode", required_argument, nullptr, 'm' },
{ "help", no_argument, nullptr, 'h'},
{ nullptr, 0, nullptr, '\0' }
};
int choice;
int option_index = 0;
while ((choice = getopt_long(argc, argv, "m:h", long_options, &option_index)) != -1) {
switch (choice) {
case 'm': {
mode = optarg;
if (mode != "MST" && mode != "FASTTSP" && mode != "OPTTSP") {
cerr << "ERROR: invalid mode specified";
}
break;
}
case 'h': {
printHelp();
exit(0);
}
}
}
}
int main(int argc, char* argv[]) {
std::ios_base::sync_with_stdio(false);
cout << setprecision(2);
cout << fixed;
string mode;
getOptions(argc, argv, mode);
switch (mode[0]) {
case 'M': {
vector<Pokemon> graph;
readFile(graph);
double weight = findMST(graph);
cout << weight << "\n";
printMST(graph);
break;
}
case 'F': {
vector<Point> nodes;
vector<int> path;
cout << arbitraryInsertion(nodes, path) << "\n";
printPath(path);
break;
}
case 'O': {
OPTTSP solution;
solution.genPerms(1, 0);
solution.printBestPath();
break;
}
}
return 0;
}