1 #include <gtest/gtest.h>
26 auto v0 = boost::add_vertex(g);
27 auto v1 = boost::add_vertex(g);
28 auto v2 = boost::add_vertex(g);
29 auto v3 = boost::add_vertex(g);
30 auto v4 = boost::add_vertex(g);
31 auto v5 = boost::add_vertex(g);
32 auto addEdge = [](
auto v0,
auto v1,
auto& g,
double c) {
33 auto e = boost::add_edge(v0, v1, g);
34 g[e.first].routingCost =
c;
36 addEdge(v0, v1, g, 1);
37 addEdge(v0, v2, g, 2);
38 addEdge(v1, v3, g, 3);
39 addEdge(v1, v4, g, 1);
40 addEdge(v2, v3, g, 1);
41 addEdge(v2, v4, g, 3);
42 addEdge(v3, v5, g, 3);
43 addEdge(v4, v5, g, 1);
47 TEST(DijkstraSearch, onSimpleGraph) {
50 std::vector<double> expCost{0, 1, 2, 3, 2, 6};
51 std::vector<size_t> length{1, 2, 2, 3, 3, 4};
52 std::vector<GraphType::vertex_descriptor> predecessors{0, 0, 0, 2, 1, 3};
60 EXPECT_EQ(searcher.
getMap().size(), boost::num_vertices(g));
61 for (
const auto& v : searcher.
getMap()) {
62 EXPECT_EQ(v.second.predicate, v.first != 4) << v.first;
63 EXPECT_EQ(v.second.isLeaf, v.first == 5 || v.first == 4) << v.first;
68 EXPECT_EQ(graph->passableSubmap()->laneletLayer.size(), 5ul);
69 EXPECT_TRUE(graph->passableSubmap()->laneletLayer.exists(2031));
70 EXPECT_TRUE(graph->passableSubmap()->laneletLayer.exists(2050));
71 EXPECT_EQ(graph->passableSubmap()->areaLayer.size(), 3ul);
72 EXPECT_TRUE(graph->passableSubmap()->areaLayer.exists(3000));
73 EXPECT_TRUE(graph->passableSubmap()->areaLayer.exists(3001));
74 EXPECT_TRUE(graph->passableSubmap()->areaLayer.exists(3002));
78 EXPECT_TRUE(graph->passableSubmap()->laneletLayer.exists(2013));
79 EXPECT_FALSE(graph->passableSubmap()->laneletLayer.exists(2022));
84 auto shortestPath = graph->shortestPath(lanelets.at(2001), lanelets.at(2004), 0);
85 ASSERT_TRUE(!!shortestPath);
86 EXPECT_EQ(shortestPath->size(), 3ul);
87 EXPECT_EQ((*shortestPath)[0], lanelets.at(2001));
88 EXPECT_EQ((*shortestPath)[1], lanelets.at(2003));
89 EXPECT_EQ((*shortestPath)[2], lanelets.at(2004));
91 shortestPath = graph->shortestPath(lanelets.at(2003), lanelets.at(2002), 0);
92 ASSERT_TRUE(!!shortestPath);
93 EXPECT_EQ(shortestPath->size(), 3ul);
94 EXPECT_EQ((*shortestPath)[0], lanelets.at(2003));
95 EXPECT_EQ((*shortestPath)[1], lanelets.at(2001));
96 EXPECT_EQ((*shortestPath)[2], lanelets.at(2002));
98 shortestPath = graph->shortestPath(lanelets.at(2003), lanelets.at(2001), 0);
99 ASSERT_TRUE(!!shortestPath);
100 EXPECT_EQ(shortestPath->size(), 2ul);
101 EXPECT_EQ((*shortestPath)[0], lanelets.at(2003));
102 EXPECT_EQ((*shortestPath)[1], lanelets.at(2001));
104 shortestPath = graph->shortestPath(lanelets.at(2003), lanelets.at(2004), 0);
105 ASSERT_TRUE(!!shortestPath);
106 EXPECT_EQ(shortestPath->size(), 2ul);
107 EXPECT_EQ((*shortestPath)[0], lanelets.at(2003));
108 EXPECT_EQ((*shortestPath)[1], lanelets.at(2004));
110 shortestPath = graph->shortestPath(lanelets.at(2001), lanelets.at(2002), 0);
111 ASSERT_TRUE(!!shortestPath);
112 EXPECT_EQ(shortestPath->size(), 2ul);
113 EXPECT_EQ((*shortestPath)[0], lanelets.at(2001));
114 EXPECT_EQ((*shortestPath)[1], lanelets.at(2002));
116 shortestPath = graph->shortestPath(lanelets.at(2004), lanelets.at(2002), 0);
117 EXPECT_FALSE(!!shortestPath);
119 shortestPath = graph->shortestPath(lanelets.at(2002), lanelets.at(2004), 0);
120 EXPECT_FALSE(!!shortestPath);
124 auto shortestPath = graph->shortestPath(lanelets.at(2019), lanelets.at(2022), 0);
125 ASSERT_TRUE(!!shortestPath);
126 EXPECT_EQ(shortestPath->size(), 3ul);
127 EXPECT_EQ((*shortestPath)[0], lanelets.at(2019));
128 EXPECT_EQ((*shortestPath)[1], lanelets.at(2020));
129 EXPECT_EQ((*shortestPath)[2], lanelets.at(2022));
131 shortestPath = graph->shortestPath(lanelets.at(2021), lanelets.at(2018), 0);
132 ASSERT_TRUE(!!shortestPath);
133 EXPECT_EQ(shortestPath->size(), 3ul);
134 EXPECT_EQ((*shortestPath)[0], lanelets.at(2021));
135 EXPECT_EQ((*shortestPath)[1], lanelets.at(2020).invert());
136 EXPECT_EQ((*shortestPath)[2], lanelets.at(2018));
138 shortestPath = graph->shortestPath(lanelets.at(2019), lanelets.at(2018), 0);
139 EXPECT_FALSE(!!shortestPath);
144 auto shortestPath = graph->shortestPath(invalidLanelet, lanelets.at(2004), 0);
145 EXPECT_FALSE(!!shortestPath);
147 EXPECT_THROW(graph->shortestPath(lanelets.at(2001), lanelets.at(2004), numCostModules),
InvalidInputError);
153 interm.push_back(
static_cast<ConstLanelet>(lanelets.at(2003)));
154 auto shortestPath = graph->shortestPathVia(lanelets.at(2001), interm, lanelets.at(2004), 0);
155 ASSERT_TRUE(!!shortestPath);
156 EXPECT_EQ(shortestPath->size(), 3ul);
157 EXPECT_EQ((*shortestPath)[0], lanelets.at(2001));
158 EXPECT_EQ((*shortestPath)[1], lanelets.at(2003));
159 EXPECT_EQ((*shortestPath)[2], lanelets.at(2004));
161 shortestPath = graph->shortestPathVia(lanelets.at(2001), interm, lanelets.at(2002), 0);
162 ASSERT_TRUE(!!shortestPath);
163 EXPECT_EQ(shortestPath->size(), 4ul);
164 EXPECT_EQ((*shortestPath)[0], lanelets.at(2001));
165 EXPECT_EQ((*shortestPath)[1], lanelets.at(2003));
166 EXPECT_EQ((*shortestPath)[2], lanelets.at(2001));
167 EXPECT_EQ((*shortestPath)[3], lanelets.at(2002));
169 shortestPath = graph->shortestPathVia(lanelets.at(2004), interm, lanelets.at(2002), 0);
170 ASSERT_FALSE(!!shortestPath);
172 shortestPath = graph->shortestPathVia(lanelets.at(2002), interm, lanelets.at(2004), 0);
173 ASSERT_FALSE(!!shortestPath);
179 interm.push_back(
static_cast<ConstLanelet>(lanelets.at(2003)));
180 interm.push_back(
static_cast<ConstLanelet>(lanelets.at(2007)));
181 auto shortestPath = graph->shortestPathVia(lanelets.at(2001), interm, lanelets.at(2013), 0);
182 ASSERT_TRUE(!!shortestPath);
183 EXPECT_EQ(shortestPath->size(), 8ul);
184 auto pathIt = shortestPath->begin();
185 EXPECT_EQ(*pathIt, lanelets.at(2001));
186 EXPECT_EQ(*++pathIt, lanelets.at(2003));
187 EXPECT_EQ(*++pathIt, lanelets.at(2004));
188 EXPECT_EQ(*++pathIt, lanelets.at(2005));
189 EXPECT_EQ(*++pathIt, lanelets.at(2007));
190 EXPECT_EQ(*++pathIt, lanelets.at(2008));
191 EXPECT_EQ(*++pathIt, lanelets.at(2010));
192 EXPECT_EQ(*++pathIt, lanelets.at(2013));
197 interm.push_back(
static_cast<ConstLanelet>(lanelets.at(2003)));
198 interm.push_back(
static_cast<ConstLanelet>(lanelets.at(2007)));
200 EXPECT_THROW(graph->shortestPathVia(lanelets.at(2001), interm, lanelets.at(2002), numCostModules),
InvalidInputError);
203 template <
typename LaneletsT>
205 return !!
utils::findIf(reachableSet, [lltId](
auto& llt) {
return llt.id() == lltId; });
209 auto reachable = graph->reachableSet(lanelets.at(2001), 0., 0);
210 EXPECT_EQ(reachable.size(), 1ul);
213 reachable = graph->reachableSet(lanelets.at(2001), 2.1, 0);
214 EXPECT_EQ(reachable.size(), 3ul);
218 reachable = graph->reachableSet(lanelets.at(2001), 100, 0);
219 EXPECT_EQ(reachable.size(), 15ul);
221 reachable = graph->reachableSet(lanelets.at(2002), 100, 0);
222 EXPECT_EQ(reachable.size(), 11ul);
226 auto reachable = graph->reachableSet(lanelets.at(2017), 100, 0);
227 EXPECT_EQ(reachable.size(), 22ul);
229 reachable = graph->reachableSet(lanelets.at(2021), 100, 0);
230 EXPECT_EQ(reachable.size(), 4ul);
234 EXPECT_THROW(graph->reachableSet(lanelets.at(2021), 0.0, numCostModules),
InvalidInputError);
236 auto reachable = graph->reachableSet(invalid, 0, 0);
237 EXPECT_TRUE(reachable.empty());
241 auto reachable = graph->reachableSetIncludingAreas(lanelets.at(2050), 100);
242 EXPECT_EQ(reachable.size(), 6ul);
251 auto reachable = graph->reachableSetIncludingAreas(areas.at(3000), 100);
252 EXPECT_EQ(reachable.size(), 5ul);
255 auto reachable = graph->reachableSetIncludingAreas(lanelets.at(2053).invert(), 100);
257 EXPECT_EQ(reachable.size(), 6ul);
260 auto reachable = graph->reachableSetIncludingAreas(lanelets.at(2051), 100);
261 EXPECT_EQ(reachable.size(), 1ul);
265 auto reachable = graph->possiblePathsIncludingAreas(lanelets.at(2050), 10, 0,
false);
266 ASSERT_EQ(reachable.size(), 3ul);
267 EXPECT_EQ(reachable[0].size(), 3ul);
268 EXPECT_EQ(reachable[1].size(), 3ul);
269 EXPECT_EQ(reachable[2].size(), 3ul);
273 auto reachable = graph->possiblePathsIncludingAreas(lanelets.at(2050), 3,
false);
274 ASSERT_EQ(reachable.size(), 3ul);
275 EXPECT_EQ(reachable[0].size(), 3ul);
276 EXPECT_EQ(reachable[1].size(), 3ul);
277 EXPECT_EQ(reachable[2].size(), 3ul);
283 auto routes = graph->possiblePaths(lanelets.at(2001), 2.2, 0,
true);
284 EXPECT_EQ(routes.size(), 2ul);
286 routes = graph->possiblePaths(lanelets.at(2002), 4.0, 0,
true);
287 ASSERT_EQ(routes.size(), 1ul);
288 auto& firstRoute = *routes.begin();
289 EXPECT_EQ(firstRoute.size(), 3ul);
294 auto routes = graph->possiblePaths(lanelets.at(2041),
PossiblePathsParams{1000, {}, 0,
true,
true});
295 EXPECT_EQ(routes.size(), 3);
296 auto lastLLts =
utils::transform(routes, [](
auto& route) {
return route.back(); });
297 EXPECT_TRUE(
has(lastLLts, lanelets.at(2062)));
298 EXPECT_TRUE(
has(lastLLts, lanelets.at(2049)));
299 EXPECT_TRUE(
has(lastLLts, lanelets.at(2048)));
303 auto routes = graph->possiblePaths(lanelets.at(2041),
PossiblePathsParams{1000, 100, 0, true, true});
304 EXPECT_EQ(routes.size(), 3);
305 auto lastLLts =
utils::transform(routes, [](
auto& route) {
return route.back(); });
306 EXPECT_TRUE(
has(lastLLts, lanelets.at(2062)));
307 EXPECT_TRUE(
has(lastLLts, lanelets.at(2049)));
308 EXPECT_TRUE(
has(lastLLts, lanelets.at(2048)));
312 auto routes = graph->possiblePaths(lanelets.at(2041),
PossiblePathsParams{1000, {}, 0,
false,
true});
313 EXPECT_EQ(routes.size(), 3);
314 auto lastLLts =
utils::transform(routes, [](
auto& route) {
return route.back(); });
315 EXPECT_TRUE(
has(lastLLts, lanelets.at(2063)));
316 EXPECT_TRUE(
has(lastLLts, lanelets.at(2049)));
317 EXPECT_TRUE(
has(lastLLts, lanelets.at(2047)));
321 auto routes = graph->possiblePaths(lanelets.at(2041),
PossiblePathsParams{1000, 100, 0, false, true});
322 EXPECT_EQ(routes.size(), 3);
323 auto lastLLts =
utils::transform(routes, [](
auto& route) {
return route.back(); });
324 EXPECT_TRUE(
has(lastLLts, lanelets.at(2063)));
325 EXPECT_TRUE(
has(lastLLts, lanelets.at(2049)));
326 EXPECT_TRUE(
has(lastLLts, lanelets.at(2047)));
330 auto routes = graph->possiblePaths(lanelets.at(2041),
PossiblePathsParams{2.5, 3, 0, false, false});
331 EXPECT_TRUE(std::all_of(routes.begin(), routes.end(), [](
auto& r) { return r.size() <= 3; }));
332 EXPECT_EQ(routes.size(), 3);
333 auto lastLLts =
utils::transform(routes, [](
auto& route) {
return route.back(); });
334 EXPECT_TRUE(
has(lastLLts, lanelets.at(2042)));
339 auto routes = graph->possiblePaths(lanelets.at(2017), 10.0, 0,
true);
340 ASSERT_EQ(routes.size(), 1ul);
341 auto& firstRoute = *routes.begin();
342 EXPECT_EQ(firstRoute.size(), 5ul);
348 auto routes = graph->possiblePaths(lanelets.at(2001), 2,
false);
349 EXPECT_EQ(routes.size(), 1ul);
350 auto& firstRoute = *routes.begin();
351 ASSERT_EQ(firstRoute.size(), 2ul);
353 EXPECT_EQ(firstRoute.getRemainingLane(firstRoute.begin()).size(), firstRoute.size());
355 routes = graph->possiblePaths(lanelets.at(2001), 30,
false);
356 EXPECT_EQ(routes.size(), 0ul);
358 routes = graph->possiblePaths(lanelets.at(2001), 10,
true);
359 EXPECT_EQ(routes.size(), 0ul);
361 routes = graph->possiblePaths(lanelets.at(2001), 7,
true);
362 EXPECT_EQ(routes.size(), 3ul);
367 EXPECT_THROW(graph->possiblePaths(lanelets.at(2002), 0., numCostModules,
true),
InvalidInputError);
368 auto routes = graph->possiblePaths(lanelets.at(2002), 0.);
369 ASSERT_EQ(routes.size(), 1ul);
370 EXPECT_EQ(routes[0].size(), 1ul);
372 routes = graph->possiblePaths(invalid, 10.0, 0,
true);
373 EXPECT_EQ(routes.size(), 0ul);
376 EXPECT_THROW(graph->possiblePaths(lanelets.at(2002), 1, numCostModules,
true),
InvalidInputError);
377 routes = graph->possiblePaths(invalid, 10, 0,
true);
378 EXPECT_EQ(routes.size(), 0ul);
382 auto routes = graph->possiblePathsTowards(lanelets.at(2024), 9, 0,
false);
383 ASSERT_EQ(routes.size(), 1UL);
384 EXPECT_EQ(routes[0].front().
id(), 2017);
385 EXPECT_EQ(routes[0].back().
id(), 2024);
389 auto routes = graph->possiblePathsTowards(lanelets.at(2015), 7, 0,
true);
390 ASSERT_EQ(routes.size(), 2UL);
396 auto routes = graph->possiblePathsTowards(lanelets.at(2015), 5,
true);
397 ASSERT_EQ(routes.size(), 2UL);
404 bool lanelet2010Seen =
false;
405 bool lanelet2013Seen =
false;
408 EXPECT_EQ(i.lanelet.id(), 2007) <<
"First lanelet must be 2007";
410 EXPECT_LE(lastVal, i.
cost);
412 lanelet2010Seen |= i.
lanelet.
id() == 2010;
413 lanelet2013Seen |= i.
lanelet.
id() == 2013;
416 EXPECT_TRUE(lanelet2010Seen);
417 EXPECT_FALSE(lanelet2013Seen);
421 class TargetFound {};
423 if (i.laneletOrArea.id() == 2053) {
428 EXPECT_THROW(graph->forEachSuccessorIncludingAreas(lanelets.at(2050), throwIfTarget), TargetFound);
432 class TargetFound {};
434 if (i.laneletOrArea.id() == 2050) {
439 EXPECT_THROW(graph->forEachPredecessorIncludingAreas(lanelets.at(2053), throwIfTarget), TargetFound);
443 class TargetFound {};
445 if (i.laneletOrArea.id() == 2004) {
450 EXPECT_THROW(graph->forEachPredecessorIncludingAreas(lanelets.at(2007), throwIfTarget), TargetFound);
454 class TargetFound {};
456 if (i.lanelet.id() == 2004) {
461 EXPECT_THROW(graph->forEachPredecessor(lanelets.at(2007), throwIfTarget), TargetFound);
468 EXPECT_EQ(path->size(), 2ul);
475 EXPECT_EQ(path->size(), 4ul);
480 graph->shortestPathIncludingAreasVia(
ConstLaneletOrArea(lanelets.at(2050)), {ConstLaneletOrArea(areas.at(3002))},
483 EXPECT_EQ(path->size(), 6ul);
486 TEST(RoutingCostInitialization, NegativeLaneChangeCost) {
506 EXPECT_NO_THROW(RoutingGraph::build(*emptyMap, *trafficRules, costPtrs, routingGraphConf));
510 routingGraphConf.emplace(std::make_pair(RoutingGraph::ParticipantHeight,
Attribute(
"2.")));
511 EXPECT_NO_THROW(RoutingGraph::build(*emptyMap, *trafficRules, costPtrs, routingGraphConf));
515 EXPECT_NO_THROW(RoutingGraph::build(*emptyMap, *trafficRules, costPtrs));