-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexec.cpp
115 lines (104 loc) · 3.44 KB
/
exec.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
#include <getopt.h>
#include <iostream>
#include <fstream>
#include <regex>
#include <problem.hpp>
#include <execution.hpp>
void printHelp();
int main(int argc, char* argv[])
{
std::string instance_file = "";
std::string plan_file = "";
std::string output_file = DEFAULT_EXEC_OUTPUT_FILE;
int seed = DEFAULT_SEED;
float ub_delay_prob = DEFAULT_UB_DELAY_PROB;
bool verbose = false;
bool log_short = false;
enum PROBLEM_TYPE { P_MAPF_DP, P_PRIMITIVE };
PROBLEM_TYPE problem_type = PROBLEM_TYPE::P_MAPF_DP;
struct option longopts[] = {
{"instance", required_argument, 0, 'i'},
{"plan", required_argument, 0, 'p'},
{"output", required_argument, 0, 'o'},
{"seed", required_argument, 0, 's'},
{"ub-delay-prob", required_argument, 0, 'u'},
{"verbose", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{"problem-type", required_argument, 0, 'P'},
{"log-short", required_argument, 0, 'l'},
{0, 0, 0, 0},
};
// command line args
int opt, longindex;
opterr = 0; // ignore getopt error
while ((opt = getopt_long(argc, argv, "i:p:o:s:u:vhP:l", longopts, &longindex)) != -1) {
switch (opt) {
case 'i':
instance_file = std::string(optarg);
break;
case 'p':
plan_file = std::string(optarg);
break;
case 'o':
output_file = std::string(optarg);
break;
case 's':
seed = std::stoi(optarg);
break;
case 'u':
ub_delay_prob = std::stof(optarg);
break;
case 'v':
verbose = true;
break;
case 'l':
log_short = true;
break;
case 'P':
if (std::string(optarg) == "PRIMITIVE") problem_type = PROBLEM_TYPE::P_PRIMITIVE;
break;
case 'h':
printHelp();
return 0;
default:
break;
}
}
if (instance_file.length() == 0 || plan_file.length() == 0) {
std::cout << "specify instance and plan file using -i and -p, e.g.,"
<< std::endl;
std::cout << "> ./app -i ../instance/sample.txt -p ./plan.txt" << std::endl;
return 0;
}
// read original problem
Problem P = Problem(instance_file);
// emulate execution
std::unique_ptr<Execution> exec;
if (problem_type == PROBLEM_TYPE::P_PRIMITIVE) {
exec = std::make_unique<PrimitiveExecution>(&P, plan_file, seed, verbose, log_short);
} else {
exec = std::make_unique<MAPF_DP_Execution>(&P, plan_file, seed, ub_delay_prob, verbose, log_short);
}
exec->run();
exec->printResult();
exec->makeLog(output_file);
if (verbose) {
std::cout << "save execution result as " << output_file << std::endl;
}
return 0;
}
void printHelp()
{
std::cout << "\nUsage: ./exec [OPTIONS]\n"
<< "\n**instance and planning files are necessary to run execution simulator**\n\n"
<< " -i --instance [FILE_PATH] instance file path\n"
<< " -p --plan [FILE_PATH] plan file path\n"
<< " -o --output [FILE_PATH] ouptut file path\n"
<< " -s --seed seed\n"
<< " -u --ub-delay-prob upper bound of delay probabilities\n"
<< " -v --verbose print additional info\n"
<< " -l --log-short simple log, unable to visualize\n"
<< " -P --problem-type { MAPF_DP, PRIMITIVE }\n"
<< " -h --help help"
<< std::endl;
}