From 80f6d7ae1584ac0155c814d9f7660b7a5587ca7b Mon Sep 17 00:00:00 2001 From: ijleesw Date: Wed, 13 Jan 2021 11:45:16 +0900 Subject: [PATCH] Use weight instead of duration for trip api --- CHANGELOG.md | 1 + include/engine/routing_algorithms.hpp | 24 +++++++------ .../routing_algorithms/many_to_many.hpp | 2 +- src/engine/plugins/table.cpp | 36 ++++++++++--------- src/engine/plugins/trip.cpp | 3 +- .../routing_algorithms/many_to_many_ch.cpp | 5 +-- .../routing_algorithms/many_to_many_mld.cpp | 12 ++++--- 7 files changed, 47 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af99a218c..9f72cbc02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Windows: - FIXED: Fix bit-shift overflow in MLD partition step. [#5878](https://github.com/Project-OSRM/osrm-backend/pull/5878) - FIXED: Fix vector bool permutation in graph contraction step [#5882](https://github.com/Project-OSRM/osrm-backend/pull/5882) + - FIXED: Fix trip api to use weight instead of duration internally [#5930](https://github.com/Project-OSRM/osrm-backend/pull/5930) # 5.23.0 diff --git a/include/engine/routing_algorithms.hpp b/include/engine/routing_algorithms.hpp index 8bedcb8d8..db0fe887f 100644 --- a/include/engine/routing_algorithms.hpp +++ b/include/engine/routing_algorithms.hpp @@ -30,11 +30,12 @@ class RoutingAlgorithmsInterface virtual InternalRouteResult DirectShortestPathSearch(const PhantomNodes &phantom_node_pair) const = 0; - virtual std::pair, std::vector> - ManyToManySearch(const std::vector &phantom_nodes, - const std::vector &source_indices, - const std::vector &target_indices, - const bool calculate_distance) const = 0; + virtual std:: + tuple, std::vector, std::vector> + ManyToManySearch(const std::vector &phantom_nodes, + const std::vector &source_indices, + const std::vector &target_indices, + const bool calculate_distance) const = 0; virtual routing_algorithms::SubMatchingList MapMatching(const routing_algorithms::CandidateLists &candidates_list, @@ -83,11 +84,12 @@ template class RoutingAlgorithms final : public RoutingAlgo InternalRouteResult DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const final override; - virtual std::pair, std::vector> - ManyToManySearch(const std::vector &phantom_nodes, - const std::vector &source_indices, - const std::vector &target_indices, - const bool calculate_distance) const final override; + virtual std:: + tuple, std::vector, std::vector> + ManyToManySearch(const std::vector &phantom_nodes, + const std::vector &source_indices, + const std::vector &target_indices, + const bool calculate_distance) const final override; routing_algorithms::SubMatchingList MapMatching(const routing_algorithms::CandidateLists &candidates_list, @@ -192,7 +194,7 @@ inline routing_algorithms::SubMatchingList RoutingAlgorithms::MapMatc } template -std::pair, std::vector> +std::tuple, std::vector, std::vector> RoutingAlgorithms::ManyToManySearch(const std::vector &phantom_nodes, const std::vector &_source_indices, const std::vector &_target_indices, diff --git a/include/engine/routing_algorithms/many_to_many.hpp b/include/engine/routing_algorithms/many_to_many.hpp index ddd861f06..d2ee7ce61 100644 --- a/include/engine/routing_algorithms/many_to_many.hpp +++ b/include/engine/routing_algorithms/many_to_many.hpp @@ -91,7 +91,7 @@ struct NodeBucket } // namespace template -std::pair, std::vector> +std::tuple, std::vector, std::vector> manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, diff --git a/src/engine/plugins/table.cpp b/src/engine/plugins/table.cpp index 82572f661..5e4eb6d90 100644 --- a/src/engine/plugins/table.cpp +++ b/src/engine/plugins/table.cpp @@ -84,11 +84,13 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, bool request_distance = params.annotations & api::TableParameters::AnnotationsType::Distance; bool request_duration = params.annotations & api::TableParameters::AnnotationsType::Duration; - auto result_tables_pair = algorithms.ManyToManySearch( + auto result_tables_tuple = algorithms.ManyToManySearch( snapped_phantoms, params.sources, params.destinations, request_distance); + auto &durations_table = std::get<1>(result_tables_tuple); + auto &distances_table = std::get<2>(result_tables_tuple); - if ((request_duration && result_tables_pair.first.empty()) || - (request_distance && result_tables_pair.second.empty())) + if ((request_duration && durations_table.empty()) || + (request_distance && distances_table.empty())) { return Error("NoTable", "No table found", result); } @@ -103,9 +105,9 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, for (std::size_t column = 0; column < num_destinations; column++) { const auto &table_index = row * num_destinations + column; - BOOST_ASSERT(table_index < result_tables_pair.first.size()); + BOOST_ASSERT(table_index < durations_table.size()); if (params.fallback_speed != INVALID_FALLBACK_SPEED && params.fallback_speed > 0 && - result_tables_pair.first[table_index] == MAXIMAL_EDGE_DURATION) + durations_table[table_index] == MAXIMAL_EDGE_DURATION) { const auto &source = snapped_phantoms[params.sources.empty() ? row : params.sources[row]]; @@ -121,30 +123,29 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, : util::coordinate_calculation::fccApproximateDistance( source.location, destination.location); - result_tables_pair.first[table_index] = + durations_table[table_index] = distance_estimate / (double)params.fallback_speed; - if (!result_tables_pair.second.empty()) + if (!distances_table.empty()) { - result_tables_pair.second[table_index] = distance_estimate; + distances_table[table_index] = distance_estimate; } estimated_pairs.emplace_back(row, column); } if (params.scale_factor > 0 && params.scale_factor != 1 && - result_tables_pair.first[table_index] != MAXIMAL_EDGE_DURATION && - result_tables_pair.first[table_index] != 0) + durations_table[table_index] != MAXIMAL_EDGE_DURATION && + durations_table[table_index] != 0) { - EdgeDuration diff = - MAXIMAL_EDGE_DURATION / result_tables_pair.first[table_index]; + EdgeDuration diff = MAXIMAL_EDGE_DURATION / durations_table[table_index]; if (params.scale_factor >= diff) { - result_tables_pair.first[table_index] = MAXIMAL_EDGE_DURATION - 1; + durations_table[table_index] = MAXIMAL_EDGE_DURATION - 1; } else { - result_tables_pair.first[table_index] = std::lround( - result_tables_pair.first[table_index] * params.scale_factor); + durations_table[table_index] = + std::lround(durations_table[table_index] * params.scale_factor); } } } @@ -152,7 +153,10 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, } api::TableAPI table_api{facade, params}; - table_api.MakeResponse(result_tables_pair, snapped_phantoms, estimated_pairs, result); + table_api.MakeResponse(std::make_pair(std::move(durations_table), std::move(distances_table)), + snapped_phantoms, + estimated_pairs, + result); return Status::Ok; } diff --git a/src/engine/plugins/trip.cpp b/src/engine/plugins/trip.cpp index d949fcb60..72b543dbe 100644 --- a/src/engine/plugins/trip.cpp +++ b/src/engine/plugins/trip.cpp @@ -217,7 +217,8 @@ Status TripPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, // compute the duration table of all phantom nodes auto result_duration_table = util::DistTableWrapper( - algorithms.ManyToManySearch(snapped_phantoms, {}, {}, /*requestDistance*/ false).first, + std::get<0>( + algorithms.ManyToManySearch(snapped_phantoms, {}, {}, /*requestDistance*/ false)), number_of_locations); if (result_duration_table.size() == 0) diff --git a/src/engine/routing_algorithms/many_to_many_ch.cpp b/src/engine/routing_algorithms/many_to_many_ch.cpp index 2d2108cb2..adb0f000c 100644 --- a/src/engine/routing_algorithms/many_to_many_ch.cpp +++ b/src/engine/routing_algorithms/many_to_many_ch.cpp @@ -178,7 +178,7 @@ void backwardRoutingStep(const DataFacade &facade, } // namespace ch template <> -std::pair, std::vector> +std::tuple, std::vector, std::vector> manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, @@ -248,7 +248,8 @@ manyToManySearch(SearchEngineData &engine_working_data, } } - return std::make_pair(std::move(durations_table), std::move(distances_table)); + return std::make_tuple( + std::move(weights_table), std::move(durations_table), std::move(distances_table)); } } // namespace routing_algorithms diff --git a/src/engine/routing_algorithms/many_to_many_mld.cpp b/src/engine/routing_algorithms/many_to_many_mld.cpp index 9607ccf09..04f70deb3 100644 --- a/src/engine/routing_algorithms/many_to_many_mld.cpp +++ b/src/engine/routing_algorithms/many_to_many_mld.cpp @@ -211,7 +211,7 @@ void relaxOutgoingEdges( // Unidirectional multi-layer Dijkstra search for 1-to-N and N-to-1 matrices // template -std::pair, std::vector> +std::tuple, std::vector, std::vector> oneToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, @@ -392,7 +392,8 @@ oneToManySearch(SearchEngineData &engine_working_data, facade, heapNode, query_heap, phantom_nodes, phantom_index, phantom_indices); } - return std::make_pair(std::move(durations_table), std::move(distances_table)); + return std::make_tuple( + std::move(weights_table), std::move(durations_table), std::move(distances_table)); } // @@ -521,7 +522,7 @@ void retrievePackedPathFromSearchSpace(NodeID middle_node_id, } template -std::pair, std::vector> +std::tuple, std::vector, std::vector> manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes, @@ -601,7 +602,8 @@ manyToManySearch(SearchEngineData &engine_working_data, } } - return std::make_pair(std::move(durations_table), std::move(distances_table)); + return std::make_tuple( + std::move(weights_table), std::move(durations_table), std::move(distances_table)); } } // namespace mld @@ -619,7 +621,7 @@ manyToManySearch(SearchEngineData &engine_working_data, // then search is performed on a reversed graph with phantom nodes with flipped roles and // returning a transposed matrix. template <> -std::pair, std::vector> +std::tuple, std::vector, std::vector> manyToManySearch(SearchEngineData &engine_working_data, const DataFacade &facade, const std::vector &phantom_nodes,