Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
209 lines (163 loc) · 6.15 KB
/
Copy pathmain.cpp
File metadata and controls
209 lines (163 loc) · 6.15 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include "ui/labelrotation.h"
#include "map/mapreader.h"
#include <QApplication>
#include "app.h"
#include "cli/clirunner.h"
#include "config.h"
#include <time.h>
#include <QTimer>
#include <QDebug>
#include "optionparser.h"
option::ArgStatus ArgMandatory( const option::Option & option, bool) {
if (option.arg)
return option::ARG_OK;
else
std::cout << "You must specify an argument to the " << option.name << " option\n";
return option::ARG_ILLEGAL;
}
enum optionIndex { MAP, PYCGR, SEED, GUI, ITERATIONS, THREADS, GRAPH, OUTPUT, ILPOUT, INTERVALS, FIXSEED, KRESTRICT, SCREENSHOT, SCREENSHOTPOS, SCREENSHOTHEU, SCREENSHOTMODEL, SCREENSHOTK, HELP};
const option::Descriptor usage[] =
{
{MAP, 0,"m" , "map" ,ArgMandatory, "Set the OSM map file\n" },
{PYCGR, 0,"p" , "pycgr" ,ArgMandatory, "Set the PYCGR map file\n" },
{OUTPUT, 0,"o" , "out" ,ArgMandatory, "Output file\n" },
{SEED, 0,"s" , "seed",ArgMandatory, "Set the seed. YOU SHOULD ALWAYS DO THIS!\n" },
{KRESTRICT, 0,"k" , "k-restriction",ArgMandatory, "Set the k restriction value\n" },
{GRAPH, 0,"g" , "graph" ,ArgMandatory, "Set the graph output file\n" },
{ILPOUT, 0,"d" , "ilpout" ,ArgMandatory, "Set the ILP output file\n" },
{INTERVALS, 0,"v" , "intervals" ,ArgMandatory, "Set the intervals output file prefix\n" },
{GUI, 0,"" , "gui",option::Arg::None, "Run in GUI mode\n" },
{FIXSEED, 0,"f" , "fixseed",option::Arg::None, "Fix to only one seed\n" },
{THREADS, 0,"t" , "threads",ArgMandatory, "Set the number of threads\n" },
{ITERATIONS, 0,"i" , "iterations",ArgMandatory, "Set the number of iterations\n" },
{SCREENSHOT, 0, "", "screenshot" ,ArgMandatory, "Go into screenshot mode, set screenshot output file\n" },
{SCREENSHOTHEU, 0, "", "screenshot-heuristic" ,ArgMandatory, "set screenshot heuristic\n" },
{SCREENSHOTMODEL, 0, "", "screenshot-model" ,ArgMandatory, "set screenshot model\n" },
{SCREENSHOTPOS, 0, "", "screenshot-position" ,ArgMandatory, "set screenshot position\n" },
{SCREENSHOTK, 0, "", "screenshot-k" ,ArgMandatory, "set screenshot k\n" },
{HELP, 0,"h" , "help",option::Arg::None, "print this help\n" },
{0,0,0,0,0,0}
};
int main(int argc, char *argv[])
{
App a(argc, argv);
int parser_argc = argc;
auto parser_argv = argv;
parser_argc-=(parser_argc>0); parser_argv+=(parser_argc>0); // skip program name argv[0] if present
option::Stats stats(usage, parser_argc, parser_argv);
option::Option options[stats.options_max], buffer[stats.buffer_max];
option::Parser parse(usage, parser_argc, parser_argv, options, buffer);
if (parse.error())
return 1;
if (options[HELP] || argc == 0) {
option::printUsage(std::cout, usage);
return 0;
}
if (options[MAP].count() != 1) {
std::cout << "You must specify a map.\n";
}
if (options[PYCGR].count() != 1) {
std::cout << "You must specify a pycgr map.\n";
}
if (options[THREADS].count() == 1) {
num_threads = std::atoi(options[THREADS].arg);
}
MapReader mapreader(options[MAP].arg, options[PYCGR].arg);
mapreader.run();
Map * map = &(mapreader.get_map());
//int seed = 4; // chosen by fair xkcd
int seed = time(nullptr);
if (options[SEED].count() > 0) {
seed = std::atoi(options[SEED].arg);
}
int k = -1;
if (options[KRESTRICT].count() > 0) {
k = std::atoi(options[KRESTRICT].arg);
}
std::map<std::string, std::set<std::string>> filter = POI_DEFAULT;
map->set_poi_filter(filter);
screenshot_info *sinfo = nullptr;
if (options[SCREENSHOT].count() > 0) {
sinfo = new screenshot_info();
sinfo->filename = options[SCREENSHOT].arg;
if (options[SCREENSHOTPOS].count() != 1) {
std::cout << "You must specify a screenshot position.\n";
exit(-1);
}
sinfo->position = atoi(options[SCREENSHOTPOS].arg);
if (options[SCREENSHOTK].count() != 1) {
sinfo->k = -1;
}
sinfo->k = atoi(options[SCREENSHOTK].arg);
if (options[SEED].count() != 1) {
std::cout << "You must specify a screenshot seed.\n";
exit(-1);
}
sinfo->seed = atoi(options[SEED].arg);
if (options[SCREENSHOTHEU].count() != 1) {
std::cout << "You must specify a screenshot heuristic.\n";
exit(-1);
}
const char *heuristic = options[SCREENSHOTHEU].arg;
if (options[SCREENSHOTMODEL].count() != 1) {
std::cout << "You must specify a screenshot model.\n";
exit(-1);
}
int model = atoi(options[SCREENSHOTMODEL].arg);
if ((model < 1) || (model > 3)) {
std::cout << "UNKNOWN MODEL\n";
exit(-1);
}
int tag = (model - 1) * 3;
if (std::strcmp(heuristic, "ilp") == 0) {
tag += 0;
} else if (std::strcmp(heuristic, "greedy") == 0) {
tag += 1;
} else if (std::strcmp(heuristic, "ig") == 0) {
tag += 2;
} else {
std::cout << "UNKNOWN HEURISTIC\n";
exit(-1);
}
sinfo->heuristic = tag;
}
if (options[GUI].count() > 0) {
std::cout << "Running in GUI mode.";
LabelRotation w(map, sinfo);
w.show();
return a.exec();
} else {
std::cout << "Running in CLI mode.";
int iterations = 1;
if (options[OUTPUT].count() != 1) {
std::cout << "You must specify an output file.\n";
}
const char *outputFile = options[OUTPUT].arg;
if (options[ITERATIONS].count() == 1) {
iterations = std::atoi(options[ITERATIONS].arg);
}
const char *graphOutFile = nullptr;
if (options[GRAPH].count() > 0) {
graphOutFile = options[GRAPH].arg;
}
const char *ilpOutputFile = nullptr;
if (options[ILPOUT].count() > 0) {
ilpOutputFile = options[ILPOUT].arg;
}
const char *intervalsOutputFile = nullptr;
if (options[INTERVALS].count() > 0) {
intervalsOutputFile = options[INTERVALS].arg;
}
bool fixseed = false;
if (options[FIXSEED].count() > 0) {
fixseed = true;
}
CLIRunner *cli = new CLIRunner(map, seed, iterations, graphOutFile, outputFile, ilpOutputFile, intervalsOutputFile, fixseed, k);
cli->run();
/*
QObject::connect(cli, SIGNAL(finished()), &a, SLOT(quit()));
QTimer::singleShot(0, cli, SLOT(run()));
*/
}
//
}