diff --git a/include/engine/guidance/assemble_steps.hpp b/include/engine/guidance/assemble_steps.hpp index 2bef099ad..0f52995d3 100644 --- a/include/engine/guidance/assemble_steps.hpp +++ b/include/engine/guidance/assemble_steps.hpp @@ -209,13 +209,22 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa else { BOOST_ASSERT(source_node.fwd_segment_position == target_node.fwd_segment_position); - // s t - // u-------------v - // |---| source_duration - // |---------| target_duration + BOOST_ASSERT(source_traversed_in_reverse == target_traversed_in_reverse); - const EdgeWeight duration = target_duration - source_duration; + // The difference (target-source) should handle + // all variants for similar directions u-v and s-t (and opposite) + // s(t) t(s) source_traversed_in_reverse = target_traversed_in_reverse = false + // u-------------v + // |---| source_weight + // |---------| target_weight + + // s(t) t(s) source_traversed_in_reverse = target_traversed_in_reverse = true + // u-------------v + // | |---------| source_weight + // | |---| target_weight const EdgeWeight weight = target_weight - source_weight; + const EdgeWeight duration = target_duration - source_duration; + BOOST_ASSERT(weight >= 0); BOOST_ASSERT(duration >= 0); steps.push_back(RouteStep{source_node.name_id, diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index 47788f5b3..2af6ab747 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -35,12 +35,16 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade target with + // weight(source -> node) = forward_weight, weight(node -> to) = edge_weight and + // weight(to -> target) ≤ reverse_weight is forward_weight + edge_weight + reverse_weight + // More tighter upper bound requires additional condition reverse_heap.WasRemoved(to) + // with weight(to -> target) = reverse_weight and all weights ≥ 0 + if (reverse_heap.WasInserted(to)) { auto reverse_weight = reverse_heap.GetKey(to); auto path_weight = forward_weight + edge_weight + reverse_weight; - BOOST_ASSERT(path_weight >= 0); - if (path_weight < path_upper_bound) + if (path_weight >= 0 && path_weight < path_upper_bound) { middle_node = to; path_upper_bound = path_weight;