Skip to content

Commit

Permalink
Allow single edge paths in MLD alternatives, #4691
Browse files Browse the repository at this point in the history
  • Loading branch information
oxidase committed Nov 20, 2017
1 parent a53794f commit 263f643
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
24 changes: 24 additions & 0 deletions features/testbot/alternative_loop.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ Feature: Alternative route
| 5 | 6 | dc,ca,ab,bd,dc,dc | |
| 7 | 8 | ca,ab,bd,dc,ca,ca | |


Scenario: Alternative Loop Paths with an asymmetric circle
Given a grid size of 10 meters
Given the node map
"""
a b c
l d
k e
j f
i h g
"""

And the ways
| nodes | oneway |
| abcdefghijkla | no |

And the query options
| alternatives | true |

When I route I should get
| from | to | route | alternative | weight |
| e | k | abcdefghijkla,abcdefghijkla | abcdefghijkla,abcdefghijkla | 6.8 |


# This test case does not work in a platform independent way
# since it depends on a specific CH structure that is only
# present on linux it seems.
Expand Down
20 changes: 18 additions & 2 deletions src/engine/routing_algorithms/alternative_path_mld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ RandIt filterPackedPathsByCellSharing(RandIt first, RandIt last, const Partition
cells.insert(get_cell(std::get<1>(edge)));

const auto over_sharing_limit = [&](const auto &packed) {

if (packed.path.empty())
{ // don't remove routes with single-node (empty) path
return false;
}

const auto not_seen = [&](const PackedEdge edge) {
const auto source_cell = get_cell(std::get<0>(edge));
const auto target_cell = get_cell(std::get<1>(edge));
Expand Down Expand Up @@ -310,7 +316,7 @@ RandIt filterPackedPathsByLocalOptimality(const WeightedViaNodePackedPath &path,
// Check plateaux edges towards the target. Terminates at the source / target
// at the latest, since parent(target)==target for the reverse heap and
// parent(target) != target in the forward heap (and vice versa).
while (has_plateaux_at_node(node, fst, snd))
while (node != fst.GetData(node).parent && has_plateaux_at_node(node, fst, snd))
node = fst.GetData(node).parent;

return node;
Expand All @@ -320,7 +326,11 @@ RandIt filterPackedPathsByLocalOptimality(const WeightedViaNodePackedPath &path,
BOOST_ASSERT(packed.via.node != path.via.node);
BOOST_ASSERT(packed.via.weight != INVALID_EDGE_WEIGHT);
BOOST_ASSERT(packed.via.node != SPECIAL_NODEID);
BOOST_ASSERT(!packed.path.empty());

if (packed.path.empty())
{ // the edge case when packed.via.node is both source and target node
return false;
}

const NodeID via = packed.via.node;

Expand Down Expand Up @@ -395,6 +405,12 @@ template <typename RandIt> RandIt filterUnpackedPathsBySharing(RandIt first, Ran
edges.insert(begin(shortest_path.edges), begin(shortest_path.edges));

const auto over_sharing_limit = [&](const auto &unpacked) {

if (unpacked.edges.empty())
{ // don't remove routes with single-node (empty) path
return false;
}

const auto not_seen = [&](const EdgeID edge) { return edges.count(edge) < 1; };
const auto different = std::count_if(begin(unpacked.edges), end(unpacked.edges), not_seen);

Expand Down

0 comments on commit 263f643

Please sign in to comment.