Skip to content

Commit

Permalink
Fix phantom nodes selection for N-to-N and 1-to-N searches
Browse files Browse the repository at this point in the history
  • Loading branch information
oxidase committed May 6, 2018
1 parent 3d11a3a commit 40c025c
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 307 deletions.
2 changes: 1 addition & 1 deletion cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module.exports = {
verify: '--strict --tags ~@stress --tags ~@todo --tags ~@mld-only -f progress --require features/support --require features/step_definitions',
todo: '--strict --tags @todo --require features/support --require features/step_definitions',
all: '--strict --require features/support --require features/step_definitions',
mld: '--strict --tags ~@stress --tags ~@todo --tags ~@ch --require features/support --require features/step_definitions'
mld: '--strict --tags ~@stress --tags ~@todo --tags ~@ch --require features/support --require features/step_definitions -f progress'
};
34 changes: 34 additions & 0 deletions features/testbot/multi_level_routing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,40 @@ Feature: Multi level routing
| l | 144.7 | 60 |
| o | 124.7 | 0 |


When I request a travel distance matrix I should get
| | a | f | l | o |
| a | 0 | 2287.2 | 1443.1 | 1243 |
| f | 2284.5+-2 | 0 | 1241.7+-2 | 1441.8+-2 |
| l | 1443.1 | 1244.3 | 0 | 600.4 |
| o | 1243 | 1444.4 | 600.4 | 0 |

When I request a travel distance matrix I should get
| | a | f | l | o |
| a | 0 | 2287.2 | 1443.1 | 1243 |

When I request a travel distance matrix I should get
| | a |
| a | 0 |
| f | 2284.5+-2 |
| l | 1443.1 |
| o | 1243 |

When I request a travel distance matrix I should get
| | a | f | l | o |
| a | 0 | 2287.2 | 1443.1 | 1243 |
| o | 1243 | 1444.4 | 600.4 | 0 |


When I request a travel distance matrix I should get
| | a | o |
| a | 0 | 1243 |
| f | 2284.5+-2 | 1441.8+-2 |
| l | 1443.1 | 600.4 |
| o | 1243 | 0 |



Scenario: Testbot - Multi level routing: horizontal road
Given the node map
"""
Expand Down
97 changes: 76 additions & 21 deletions include/engine/routing_algorithms/routing_base_mld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ inline bool checkParentCellRestriction(CellID, const PhantomNodes &) { return tr

// Restricted search (Args is LevelID, CellID):
// * use the fixed level for queries
// * check if the node cell is the same as the specified parent onr
// * check if the node cell is the same as the specified parent
template <typename MultiLevelPartition>
inline LevelID getNodeQueryLevel(const MultiLevelPartition &, NodeID, LevelID level, CellID)
{
Expand All @@ -65,6 +65,61 @@ inline bool checkParentCellRestriction(CellID cell, LevelID, CellID parent)
{
return cell == parent;
}

// Unrestricted search with a single phantom node (Args is const PhantomNode &):
// * use partition.GetQueryLevel to find the node query level
// * allow to traverse all cells
template <typename MultiLevelPartition>
inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition,
const NodeID node,
const PhantomNode &phantom_node)
{
auto highest_diffrent_level = [&partition, node](const SegmentID &phantom_node) {
if (phantom_node.enabled)
return partition.GetHighestDifferentLevel(phantom_node.id, node);
return INVALID_LEVEL_ID;
};

const auto node_level = std::min(highest_diffrent_level(phantom_node.forward_segment_id),
highest_diffrent_level(phantom_node.reverse_segment_id));

return node_level;
}

// Unrestricted search with a single phantom node and a vector of phantom nodes:
// * use partition.GetQueryLevel to find the node query level
// * allow to traverse all cells
template <typename MultiLevelPartition>
inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition,
NodeID node,
const std::vector<PhantomNode> &phantom_nodes,
const std::size_t phantom_index,
const std::vector<std::size_t> &phantom_indices)
{
auto min_level = [&partition, node](const PhantomNode &phantom_node) {

const auto &forward_segment = phantom_node.forward_segment_id;
const auto forward_level =
forward_segment.enabled ? partition.GetHighestDifferentLevel(node, forward_segment.id)
: INVALID_LEVEL_ID;

const auto &reverse_segment = phantom_node.reverse_segment_id;
const auto reverse_level =
reverse_segment.enabled ? partition.GetHighestDifferentLevel(node, reverse_segment.id)
: INVALID_LEVEL_ID;

return std::min(forward_level, reverse_level);
};

// Get minimum level over all phantoms of the highest different level with respect to node
// This is equivalent to min_{∀ source, target} partition.GetQueryLevel(source, node, target)
auto result = min_level(phantom_nodes[phantom_index]);
for (const auto &index : phantom_indices)
{
result = std::min(result, min_level(phantom_nodes[index]));
}
return result;
}
}

// Heaps only record for each node its predecessor ("parent") on the shortest path.
Expand Down Expand Up @@ -391,20 +446,20 @@ UnpackedPath search(SearchEngineData<Algorithm> &engine_working_data,
// Get packed path as edges {from node ID, to node ID, from_clique_arc}
auto packed_path = retrievePackedPathFromHeap(forward_heap, reverse_heap, middle);

if (!packed_path.empty())
{
std::cout << "packed_path: ";
for (auto edge : packed_path)
{
std::cout << std::get<0>(edge) << ",";
}
std::cout << std::get<1>(packed_path.back());
std::cout << std::endl;
}
else
{
std::cout << "no packed_path!" << std::endl;
}
// if (!packed_path.empty())
// {
// std::cout << "packed_path: ";
// for (auto edge : packed_path)
// {
// std::cout << std::get<0>(edge) << ",";
// }
// std::cout << std::get<1>(packed_path.back());
// std::cout << std::endl;
// }
// else
// {
// std::cout << "no packed_path!" << std::endl;
// }

// Beware the edge case when start, middle, end are all the same.
// In this case we return a single node, no edges. We also don't unpack.
Expand Down Expand Up @@ -465,12 +520,12 @@ UnpackedPath search(SearchEngineData<Algorithm> &engine_working_data,
unpacked_edges.insert(unpacked_edges.end(), subpath_edges.begin(), subpath_edges.end());
}
}
std::cout << "unpacked_nodes: ";
for (auto node : unpacked_nodes)
{
std::cout << node << ", ";
}
std::cout << std::endl;
// std::cout << "unpacked_nodes: ";
// for (auto node : unpacked_nodes)
// {
// std::cout << node << ", ";
// }
// std::cout << std::endl;
return std::make_tuple(weight, std::move(unpacked_nodes), std::move(unpacked_edges));
}

Expand Down
Loading

0 comments on commit 40c025c

Please sign in to comment.