From 8af54ffe837099a052d085d0f9b0306a1461a570 Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Sat, 22 Jul 2017 12:36:53 +0200 Subject: [PATCH] Handles distinction of no-route vs invalid-route in mld alternatives The viaroute plugin always expects a route to be there potentially with invalid edge weight to represent no-route-found. By switching to the many-route-result for the mld alternatives algorithm we might return an empty many-route-result invalidating the post-condition. --- src/engine/plugins/viaroute.cpp | 5 ++++- src/engine/routing_algorithms/alternative_path_mld.cpp | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/engine/plugins/viaroute.cpp b/src/engine/plugins/viaroute.cpp index c80c0411b..2a11a2e9d 100644 --- a/src/engine/plugins/viaroute.cpp +++ b/src/engine/plugins/viaroute.cpp @@ -121,9 +121,12 @@ ViaRoutePlugin::HandleRequest(const datafacade::ContiguousInternalMemoryDataFaca routes = algorithms.ShortestPathSearch(start_end_nodes, route_parameters.continue_straight); } + // The post condition for all path searches is we have at least one route in our result. + // This route might be invalid by means of INVALID_EDGE_WEIGHT as shortest path weight. + BOOST_ASSERT(!routes.routes.empty()); + // we can only know this after the fact, different SCC ids still // allow for connection in one direction. - BOOST_ASSERT(!routes.routes.empty()); if (routes.routes[0].is_valid()) { diff --git a/src/engine/routing_algorithms/alternative_path_mld.cpp b/src/engine/routing_algorithms/alternative_path_mld.cpp index 83f4a8e9b..0926bc99b 100644 --- a/src/engine/routing_algorithms/alternative_path_mld.cpp +++ b/src/engine/routing_algorithms/alternative_path_mld.cpp @@ -792,8 +792,15 @@ InternalManyRoutesResult alternativePathSearch(SearchEngineData &sear shortest_path_via_it->node != SPECIAL_NODEID && shortest_path_via_it->weight != INVALID_EDGE_WEIGHT; + // Care needs to be taken to meet the call sites post condition. + // We must return at least one route, even if it's an invalid one. if (!has_shortest_path) - return InternalManyRoutesResult{}; + { + InternalRouteResult invalid; + invalid.shortest_path_weight = INVALID_EDGE_WEIGHT; + invalid.segment_end_coordinates = {phantom_node_pair}; + return invalid; + } NodeID shortest_path_via = shortest_path_via_it->node; EdgeWeight shortest_path_weight = shortest_path_via_it->weight;