Use struct instead of tuple to define UnpackedPath (#6974)

This commit is contained in:
Siarhei Fedartsou 2024-06-29 21:34:43 +02:00 committed by GitHub
parent 93c0e1dab3
commit bdc6ed8a53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 66 additions and 59 deletions

View File

@ -24,6 +24,7 @@
- NodeJS:
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
- Misc:
- CHANGED: Use struct instead of tuple to define UnpackedPath. [#6974](https://github.com/Project-OSRM/osrm-backend/pull/6974)
- CHANGED: Micro performance optimisation in map matching. [#6976](https://github.com/Project-OSRM/osrm-backend/pull/6976)
- CHANGED: Re-use priority queue in StaticRTree. [#6952](https://github.com/Project-OSRM/osrm-backend/pull/6952)
- CHANGED: Optimise encodePolyline function. [#6940](https://github.com/Project-OSRM/osrm-backend/pull/6940)

View File

@ -487,7 +487,13 @@ void routingStep(const DataFacade<Algorithm> &facade,
using UnpackedNodes = std::vector<NodeID>;
using UnpackedEdges = std::vector<EdgeID>;
using UnpackedPath = std::tuple<EdgeWeight, UnpackedNodes, UnpackedEdges>;
struct UnpackedPath
{
EdgeWeight weight;
UnpackedNodes nodes;
UnpackedEdges edges;
};
template <typename Algorithm, typename Heap, typename... Args>
std::optional<std::pair<NodeID, EdgeWeight>> runSearch(const DataFacade<Algorithm> &facade,
@ -551,7 +557,7 @@ UnpackedPath search(SearchEngineData<Algorithm> &engine_working_data,
facade, forward_heap, reverse_heap, force_step_nodes, weight_upper_bound, args...);
if (!searchResult)
{
return std::make_tuple(INVALID_EDGE_WEIGHT, std::vector<NodeID>(), std::vector<EdgeID>());
return {INVALID_EDGE_WEIGHT, std::vector<NodeID>(), std::vector<EdgeID>()};
}
auto [middle, weight] = *searchResult;
@ -595,7 +601,7 @@ UnpackedPath search(SearchEngineData<Algorithm> &engine_working_data,
forward_heap.Insert(source, {0}, {source});
reverse_heap.Insert(target, {0}, {target});
auto [subpath_weight, subpath_nodes, subpath_edges] = search(engine_working_data,
auto unpacked_subpath = search(engine_working_data,
facade,
forward_heap,
reverse_heap,
@ -603,17 +609,19 @@ UnpackedPath search(SearchEngineData<Algorithm> &engine_working_data,
INVALID_EDGE_WEIGHT,
sublevel,
parent_cell_id);
BOOST_ASSERT(!subpath_edges.empty());
BOOST_ASSERT(subpath_nodes.size() > 1);
BOOST_ASSERT(subpath_nodes.front() == source);
BOOST_ASSERT(subpath_nodes.back() == target);
unpacked_nodes.insert(
unpacked_nodes.end(), std::next(subpath_nodes.begin()), subpath_nodes.end());
unpacked_edges.insert(unpacked_edges.end(), subpath_edges.begin(), subpath_edges.end());
BOOST_ASSERT(!unpacked_subpath.edges.empty());
BOOST_ASSERT(unpacked_subpath.nodes.size() > 1);
BOOST_ASSERT(unpacked_subpath.nodes.front() == source);
BOOST_ASSERT(unpacked_subpath.nodes.back() == target);
unpacked_nodes.insert(unpacked_nodes.end(),
std::next(unpacked_subpath.nodes.begin()),
unpacked_subpath.nodes.end());
unpacked_edges.insert(
unpacked_edges.end(), unpacked_subpath.edges.begin(), unpacked_subpath.edges.end());
}
}
return std::make_tuple(weight, std::move(unpacked_nodes), std::move(unpacked_edges));
return {weight, std::move(unpacked_nodes), std::move(unpacked_edges)};
}
template <typename Algorithm, typename... Args>
@ -654,13 +662,15 @@ inline void search(SearchEngineData<Algorithm> &engine_working_data,
const EdgeWeight weight_upper_bound = INVALID_EDGE_WEIGHT)
{
// TODO: change search calling interface to use unpacked_edges result
std::tie(weight, unpacked_nodes, std::ignore) = search(engine_working_data,
auto unpacked_path = search(engine_working_data,
facade,
forward_heap,
reverse_heap,
force_step_nodes,
weight_upper_bound,
endpoints);
weight = unpacked_path.weight;
unpacked_nodes = std::move(unpacked_path.nodes);
}
// TODO: refactor CH-related stub to use unpacked_edges

View File

@ -621,12 +621,7 @@ void unpackPackedPaths(InputIt first,
BOOST_ASSERT(!facade.ExcludeNode(source));
BOOST_ASSERT(!facade.ExcludeNode(target));
// TODO: when structured bindings will be allowed change to
// auto [subpath_weight, subpath_source, subpath_target, subpath] = ...
EdgeWeight subpath_weight;
std::vector<NodeID> subpath_nodes;
std::vector<EdgeID> subpath_edges;
std::tie(subpath_weight, subpath_nodes, subpath_edges) = search(search_engine_data,
auto unpacked_subpath = search(search_engine_data,
facade,
forward_heap,
reverse_heap,
@ -634,14 +629,16 @@ void unpackPackedPaths(InputIt first,
INVALID_EDGE_WEIGHT,
sublevel,
parent_cell_id);
BOOST_ASSERT(!subpath_edges.empty());
BOOST_ASSERT(subpath_nodes.size() > 1);
BOOST_ASSERT(subpath_nodes.front() == source);
BOOST_ASSERT(subpath_nodes.back() == target);
unpacked_nodes.insert(
unpacked_nodes.end(), std::next(subpath_nodes.begin()), subpath_nodes.end());
unpacked_edges.insert(
unpacked_edges.end(), subpath_edges.begin(), subpath_edges.end());
BOOST_ASSERT(!unpacked_subpath.edges.empty());
BOOST_ASSERT(unpacked_subpath.nodes.size() > 1);
BOOST_ASSERT(unpacked_subpath.nodes.front() == source);
BOOST_ASSERT(unpacked_subpath.nodes.back() == target);
unpacked_nodes.insert(unpacked_nodes.end(),
std::next(unpacked_subpath.nodes.begin()),
unpacked_subpath.nodes.end());
unpacked_edges.insert(unpacked_edges.end(),
unpacked_subpath.edges.begin(),
unpacked_subpath.edges.end());
}
}

View File

@ -70,12 +70,7 @@ InternalRouteResult directShortestPathSearch(SearchEngineData<mld::Algorithm> &e
auto &reverse_heap = *engine_working_data.reverse_heap_1;
insertNodesInHeaps(forward_heap, reverse_heap, endpoint_candidates);
// TODO: when structured bindings will be allowed change to
// auto [weight, source_node, target_node, unpacked_edges] = ...
EdgeWeight weight = INVALID_EDGE_WEIGHT;
std::vector<NodeID> unpacked_nodes;
std::vector<EdgeID> unpacked_edges;
std::tie(weight, unpacked_nodes, unpacked_edges) = mld::search(engine_working_data,
auto unpacked_path = mld::search(engine_working_data,
facade,
forward_heap,
reverse_heap,
@ -83,7 +78,11 @@ InternalRouteResult directShortestPathSearch(SearchEngineData<mld::Algorithm> &e
INVALID_EDGE_WEIGHT,
endpoint_candidates);
return extractRoute(facade, weight, endpoint_candidates, unpacked_nodes, unpacked_edges);
return extractRoute(facade,
unpacked_path.weight,
endpoint_candidates,
unpacked_path.nodes,
unpacked_path.edges);
}
} // namespace osrm::engine::routing_algorithms