-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
417 lines (385 loc) · 15.9 KB
/
main.cpp
File metadata and controls
417 lines (385 loc) · 15.9 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#include <argparse/argparse.hpp>
#include <lacam.hpp>
#include <planner.hpp>
namespace {
struct HelpEntry {
const char* names;
const char* description;
};
bool wants_custom_help(int argc, char* argv[])
{
for (auto i = 1; i < argc; ++i) {
const std::string arg(argv[i]);
if (arg == "-h" || arg == "--help") return true;
}
return false;
}
void print_help_section(const char* title,
std::initializer_list<HelpEntry> entries)
{
constexpr size_t kHelpNameWidth = 34;
std::cout << "\n" << title << ":\n";
for (const auto& entry : entries) {
const auto names = std::string(entry.names);
std::cout << " " << names;
if (names.size() < kHelpNameWidth) {
std::cout << std::string(kHelpNameWidth - names.size(), ' ');
} else {
std::cout << " ";
}
std::cout << entry.description << "\n";
}
}
void print_custom_help()
{
std::cout
<< "Usage: lacam [options]\n\n"
<< "Continuous multi-agent path finding solver.\n";
print_help_section(
"I/O and Execution",
{
{"-h, --help", "show this categorized help and exit"},
{"-v, --verbose", "logging verbosity (default: 0)"},
{"-s, --seed", "random seed (default: 0)"},
{"--output", "output file path (default: ./build/result.txt)"},
{"--no_validation", "skip solution validation"},
});
print_help_section(
"Solver Parameters",
{
{"--action_model",
"learned action model prefix or .pt/.jit.pt path; when set, "
"--length_past_locs is inferred from the model"},
{"--speed_default", "fallback speed without learned model (default: 1.0)"},
{"--time_deviation_var_default",
"fallback time deviation variance (default: 0.0)"},
{"--space_deviation_mu_default",
"fallback space deviation mean (default: 0.0)"},
{"--space_deviation_var_default",
"fallback space deviation variance (default: 0.0)"},
{"-f, --Hz", "state discretization frequency (default: 4)"},
{"-l, --length_past_locs",
"action-model history length when --action_model is not set "
"(default: 1)"},
{"--time_sigma_level", "time uncertainty sigma level (default: 0.5)"},
{"--space_sigma_level",
"space uncertainty sigma level (default: 0.5)"},
{"-t, --time_limit_sec", "search time limit in seconds (default: 3.0)"},
{"-O, --objective",
"0=first feasible, 1=flowtime, 2=makespan, 3=total distance"},
{"--num_planners", "number of parallel LaCAM workers (default: 1)"},
{"--random_insert_prob_init",
"probability of reinserting the initial node"},
{"--random_insert_prob_random",
"probability of reinserting a random solution-path node"},
{"--restart_prob", "probability of restarting from the initial node"},
{"--num_monte_calro_sampling",
"number of low-level Monte Carlo samples"},
{"--max_space_deviation",
"maximum allowed space deviation during planning"},
{"--no_sort_low_level", "disable low-level successor sorting"},
});
print_help_section(
"Problem Parameters",
{
{"-N, --num", "number of agents (default: 1)"},
{"-a, --agent", "explicit start_id,goal_id pair; may be repeated"},
{"-r, --agent_rad", "agent radius (default: 0.25)"},
{"--graph_type", "synthetic graph type: grid or random"},
{"--graph_file", "load a graph from file instead of generating one"},
{"-o, --obstacle", "manual obstacle as x,y,z,r; may be repeated"},
{"--num_random_obstacles",
"number of randomly generated obstacles (default: 0)"},
{"--obstacle_rad_min",
"minimum random obstacle radius (default: 0.2)"},
{"--obstacle_rad_max",
"maximum random obstacle radius (default: 0.5)"},
{"--x_min", "workspace minimum x (default: -2.0)"},
{"--x_max", "workspace maximum x (default: 2.0)"},
{"--y_min", "workspace minimum y (default: -1.5)"},
{"--y_max", "workspace maximum y (default: 1.5)"},
{"--z_min", "workspace minimum z (default: 0.0)"},
{"--z_max", "workspace maximum z (default: 0.0)"},
{"--num_vertices", "number of vertices for random graphs (default: 50)"},
{"--step_size", "lattice spacing for grid graphs (default: 0.75)"},
{"--connection_rad", "edge connection radius (default: 1.75)"},
});
}
} // namespace
int main(int argc, char* argv[])
{
if (wants_custom_help(argc, argv)) {
print_custom_help();
return 0;
}
auto deadline = Deadline();
constexpr const char* kIoPrefix = "[io] ";
constexpr const char* kSolverPrefix = "[solver] ";
constexpr const char* kProblemPrefix = "[problem] ";
constexpr const char* kObjectiveHelp =
"[solver] optimization target: 0=first feasible solution (stop on first "
"goal), 1=flowtime, 2=makespan, 3=total distance";
constexpr const char* kTimeLimitHelp =
"[solver] search time limit in seconds; with objectives 1-3 the solver "
"keeps the best solution found so far until this limit or until the "
"search space is exhausted";
constexpr const char* kActionModelHelp =
"[solver] learned action model prefix or .pt/.jit.pt path; when set, "
"--length_past_locs is inferred from the model definition";
constexpr const char* kLengthPastLocsHelp =
"[solver] action-model history length; effective only when "
"--action_model is not set";
constexpr const char* kHelpEpilog =
"Option categories: [io] input/output and execution control, "
"[solver] search and action-model parameters, [problem] graph and "
"instance generation.";
argparse::ArgumentParser program("lacam", "0.1.0");
program.add_epilog(kHelpEpilog);
program.add_argument("-v", "--verbose")
.help("[io] logging verbosity")
.default_value(0)
.scan<'i', int>();
program.add_argument("-s", "--seed")
.help("[io] random seed")
.default_value(0)
.scan<'i', int>();
program.add_argument("-N", "--num")
.help("[problem] number of agents")
.default_value(1)
.scan<'i', int>();
program.add_argument("--output")
.help("[io] output file")
.default_value(std::string("./build/result.txt"));
program.add_argument("-a", "--agent")
.default_value(std::vector<std::string>({}))
.append()
.help("[problem] explicit start_id,goal_id");
program.add_argument("--no_validation")
.help("[io] skip solution validation")
.flag();
program.add_argument("--action_model")
.help(kActionModelHelp)
.default_value(std::string(""));
program.add_argument("--speed_default")
.help("[solver] fallback speed when no learned action model is used")
.default_value(1.0f)
.scan<'g', float>();
program.add_argument("--time_deviation_var_default")
.help("[solver] fallback time deviation variance without learned model")
.default_value(0.0f)
.scan<'g', float>();
program.add_argument("--space_deviation_mu_default")
.help("[solver] fallback space deviation mean without learned model")
.default_value(0.0f)
.scan<'g', float>();
program.add_argument("--space_deviation_var_default")
.help("[solver] fallback space deviation variance without learned model")
.default_value(0.0f)
.scan<'g', float>();
program.add_argument("-f", "--Hz")
.help("[solver] state discretization frequency")
.default_value(4)
.scan<'i', int>();
program.add_argument("-r", "--agent_rad")
.help("[problem] agent radius")
.default_value(0.25f)
.scan<'g', float>();
program.add_argument("-l", "--length_past_locs")
.help(kLengthPastLocsHelp)
.default_value(1)
.scan<'i', int>();
program.add_argument("--time_sigma_level")
.help("[solver] time uncertainty sigma level")
.default_value(0.5f)
.scan<'g', float>();
program.add_argument("--space_sigma_level")
.help("[solver] space uncertainty sigma level")
.default_value(0.5f)
.scan<'g', float>();
program.add_argument("-t", "--time_limit_sec")
.help(kTimeLimitHelp)
.default_value(3.0f)
.scan<'g', float>();
program.add_argument("-O", "--objective")
.help(kObjectiveHelp)
.default_value(0)
.scan<'i', int>();
program.add_argument("--num_planners")
.help("[solver] number of parallel LaCAM workers")
.default_value(1)
.scan<'i', int>();
program.add_argument("--random_insert_prob_init")
.help("[solver] probability of reinserting the initial node")
.default_value(0.0025f)
.scan<'g', float>();
program.add_argument("--random_insert_prob_random")
.help("[solver] probability of reinserting a random solution-path node")
.default_value(0.0025f)
.scan<'g', float>();
program.add_argument("--restart_prob")
.help("[solver] probability of restarting from the initial node")
.default_value(0.001f)
.scan<'g', float>();
program.add_argument("--num_monte_calro_sampling")
.help("[solver] number of low-level Monte Carlo samples")
.default_value(10)
.scan<'i', int>();
program.add_argument("--max_space_deviation")
.help("[solver] maximum allowed space deviation during planning")
.default_value(10.0f)
.scan<'g', float>();
program.add_argument("--no_sort_low_level")
.help("[solver] disable low-level successor sorting")
.flag();
program.add_argument("--graph_type")
.help("[problem] synthetic graph type: grid or random")
.default_value(std::string("grid"));
program.add_argument("--graph_file")
.help("[problem] load a graph from file instead of generating one")
.default_value(std::string(""));
program.add_argument("-o", "--obstacle")
.default_value(std::vector<std::string>({}))
.append()
.help("[problem] manual obstacle as x,y,z,r");
program.add_argument("--num_random_obstacles")
.help("[problem] number of randomly generated obstacles")
.default_value(0)
.scan<'i', int>();
program.add_argument("--obstacle_rad_min")
.help("[problem] minimum random obstacle radius")
.default_value(0.2f)
.scan<'g', float>();
program.add_argument("--obstacle_rad_max")
.help("[problem] maximum random obstacle radius")
.default_value(0.5f)
.scan<'g', float>();
program.add_argument("--x_min")
.help("[problem] workspace minimum x")
.default_value(-2.0f)
.scan<'g', float>();
program.add_argument("--x_max")
.help("[problem] workspace maximum x")
.default_value(2.0f)
.scan<'g', float>();
program.add_argument("--y_min")
.help("[problem] workspace minimum y")
.default_value(-1.5f)
.scan<'g', float>();
program.add_argument("--y_max")
.help("[problem] workspace maximum y")
.default_value(1.5f)
.scan<'g', float>();
program.add_argument("--z_min")
.help("[problem] workspace minimum z")
.default_value(0.0f)
.scan<'g', float>();
program.add_argument("--z_max")
.help("[problem] workspace maximum z")
.default_value(0.0f)
.scan<'g', float>();
program.add_argument("--num_vertices")
.help("[problem] number of vertices for random graphs")
.default_value(50)
.scan<'i', int>();
program.add_argument("--step_size")
.help("[problem] lattice spacing for grid graphs")
.default_value(0.75f)
.scan<'g', float>();
program.add_argument("--connection_rad")
.help("[problem] edge connection radius")
.default_value(1.75f)
.scan<'g', float>();
try {
program.parse_args(argc, argv);
} catch (const std::runtime_error& err) {
std::cerr << err.what() << std::endl;
std::cerr << program;
std::exit(1);
}
const auto verbose = program.get<int>("--verbose");
const auto seed = program.get<int>("--seed");
const auto agents_raw = program.get<std::vector<std::string>>("--agent");
const auto model_fpath = program.get<std::string>("--action_model");
const auto speed_default = program.get<float>("--speed_default");
const auto time_deviation_var_default =
program.get<float>("--time_deviation_var_default");
const auto space_deviation_mu_default =
program.get<float>("--space_deviation_mu_default");
const auto space_deviation_var_default =
program.get<float>("--space_deviation_var_default");
const auto Hz = program.get<int>("--Hz");
const auto agent_rad = program.get<float>("--agent_rad");
const auto length_past_locs = program.get<int>("--length_past_locs");
const auto time_limit_sec = program.get<float>("--time_limit_sec");
const auto num_planners = program.get<int>("--num_planners");
const auto no_sort_low_level = program.get<bool>("--no_sort_low_level");
const auto graph_file = program.get<std::string>("--graph_file");
const auto obstacles_raw = program.get<std::vector<std::string>>("--obstacle");
const auto problem_options = ProblemBuilderOptions{
.seed = seed,
.num_agents = program.get<int>("--num"),
.agent_rad = agent_rad,
.graph_type = program.get<std::string>("--graph_type"),
.graph_file = graph_file,
.obstacles_raw = obstacles_raw,
.num_random_obstacles = program.get<int>("--num_random_obstacles"),
.obstacle_rad_min = program.get<float>("--obstacle_rad_min"),
.obstacle_rad_max = program.get<float>("--obstacle_rad_max"),
.x_min = program.get<float>("--x_min"),
.x_max = program.get<float>("--x_max"),
.y_min = program.get<float>("--y_min"),
.y_max = program.get<float>("--y_max"),
.z_min = program.get<float>("--z_min"),
.z_max = program.get<float>("--z_max"),
.num_vertices = program.get<int>("--num_vertices"),
.step_size = program.get<float>("--step_size"),
.connection_rad = program.get<float>("--connection_rad"),
.agents_raw = agents_raw,
};
Graph G = build_graph(problem_options);
Instance ins = build_instance(&G, problem_options);
auto planner_options = PlannerOptions{
.model_fpath = model_fpath,
.verbose = verbose,
.seed = seed,
.speed_default = speed_default,
.time_deviation_var_default = time_deviation_var_default,
.space_deviation_mu_default = space_deviation_mu_default,
.space_deviation_var_default = space_deviation_var_default,
.Hz = Hz,
.agent_rad = agent_rad,
.length_past_locs = length_past_locs,
.time_sigma_level = program.get<float>("--time_sigma_level"),
.space_sigma_level = program.get<float>("--space_sigma_level"),
.time_limit_sec = time_limit_sec,
.objective = static_cast<Objective>(program.get<int>("--objective")),
.num_planners = num_planners,
.random_insert_prob_init =
program.get<float>("--random_insert_prob_init"),
.random_insert_prob_random =
program.get<float>("--random_insert_prob_random"),
.restart_prob = program.get<float>("--restart_prob"),
.num_monte_calro_sampling =
program.get<int>("--num_monte_calro_sampling"),
.max_space_deviation = program.get<float>("--max_space_deviation"),
.sort_low_level = !no_sort_low_level,
};
auto planner = Planner(&ins, planner_options);
synchronized_info(1, verbose, format_elapsed_ms(deadline.elapsed_ms()),
", setup done");
planner.solve();
// save results
planner.save(program.get<std::string>("--output"), deadline.elapsed_ms());
synchronized_info(1, verbose, format_elapsed_ms(deadline.elapsed_ms()),
", save result");
if (planner.solved()) {
synchronized_info(1, verbose, "best_score=", planner.solution_cost());
}
// validation
if (!program.get<bool>("--no_validation")) {
synchronized_info(1, verbose, "validation: ", planner.validate_solution());
}
synchronized_info(1, verbose, format_elapsed_ms(deadline.elapsed_ms()),
", success");
return 0;
}