From 2766c24b420aaf129f7eab3b6c1a20e366c71e93 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Tue, 4 Apr 2017 20:41:39 +0200 Subject: [PATCH] prefer smaller legs for equal weights in shortest path plugin --- .../routing_algorithms/shortest_path.cpp | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/engine/routing_algorithms/shortest_path.cpp b/src/engine/routing_algorithms/shortest_path.cpp index 43cba7d44..cbc30c503 100644 --- a/src/engine/routing_algorithms/shortest_path.cpp +++ b/src/engine/routing_algorithms/shortest_path.cpp @@ -456,20 +456,9 @@ shortestPathSearchImpl(SearchEngineData &engine_working_data, total_weight_to_reverse != INVALID_EDGE_WEIGHT); // We make sure the fastest route is always in packed_legs_to_forward - if (total_weight_to_forward > total_weight_to_reverse) - { - // insert sentinel - packed_leg_to_reverse_begin.push_back(total_packed_path_to_reverse.size()); - BOOST_ASSERT(packed_leg_to_reverse_begin.size() == phantom_nodes_vector.size() + 1); - - unpackLegs(facade, - phantom_nodes_vector, - total_packed_path_to_reverse, - packed_leg_to_reverse_begin, - total_weight_to_reverse, - raw_route_data); - } - else + if (total_weight_to_forward < total_weight_to_reverse || + (total_weight_to_forward == total_weight_to_reverse && + total_packed_path_to_forward.size() < total_packed_path_to_reverse.size())) { // insert sentinel packed_leg_to_forward_begin.push_back(total_packed_path_to_forward.size()); @@ -482,6 +471,19 @@ shortestPathSearchImpl(SearchEngineData &engine_working_data, total_weight_to_forward, raw_route_data); } + else + { + // insert sentinel + packed_leg_to_reverse_begin.push_back(total_packed_path_to_reverse.size()); + BOOST_ASSERT(packed_leg_to_reverse_begin.size() == phantom_nodes_vector.size() + 1); + + unpackLegs(facade, + phantom_nodes_vector, + total_packed_path_to_reverse, + packed_leg_to_reverse_begin, + total_weight_to_reverse, + raw_route_data); + } return raw_route_data; }