Fix routing when start and target are on the same segment

Fixes issue #1864. Given the simple set-up:

a --> b --> c
^-----------|

This would translate into an edge based graph (ab) -> (bc),
(bc) -> (ca), (ca) -> (ab).

Starting at the end of the one-way street (ab) and going to
the beginning, the query has to find a self-loop within the
graph (ab) -> (bc) -> (ca) -> (ab), as both nodes map to the
same segment (ab).
This commit is contained in:
Moritz Kobitzsch
2016-01-07 10:33:47 +01:00
committed by Patrick Niklaus
parent 238e77d959
commit 1c1bfd7541
22 changed files with 744 additions and 287 deletions
@@ -139,14 +139,21 @@ class ManyToManyRouting final
// get target id from bucket entry
const unsigned target_id = current_bucket.target_id;
const int target_distance = current_bucket.distance;
const EdgeWeight current_distance =
(*result_table)[source_id * number_of_targets + target_id];
auto &current_distance = (*result_table)[source_id * number_of_targets + target_id];
// check if new distance is better
const EdgeWeight new_distance = source_distance + target_distance;
if (new_distance >= 0 && new_distance < current_distance)
if (new_distance < 0)
{
(*result_table)[source_id * number_of_targets + target_id] =
(source_distance + target_distance);
const EdgeWeight loop_weight = super::GetLoopWeight(node);
const int new_distance_with_loop = new_distance + loop_weight;
if (loop_weight != INVALID_EDGE_WEIGHT && new_distance_with_loop >= 0)
{
current_distance = std::min(current_distance, new_distance_with_loop);
}
}
else if (new_distance < current_distance)
{
(*result_table)[source_id * number_of_targets + target_id] = new_distance;
}
}
}