Use weight instead of duration for trip api

This commit is contained in:
ijleesw 2021-01-13 11:45:16 +09:00
parent 58ba3fc84f
commit 80f6d7ae15
7 changed files with 47 additions and 36 deletions

View File

@ -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

View File

@ -30,7 +30,8 @@ class RoutingAlgorithmsInterface
virtual InternalRouteResult
DirectShortestPathSearch(const PhantomNodes &phantom_node_pair) const = 0;
virtual std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
virtual std::
tuple<std::vector<EdgeWeight>, std::vector<EdgeDuration>, std::vector<EdgeDistance>>
ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
const std::vector<std::size_t> &source_indices,
const std::vector<std::size_t> &target_indices,
@ -83,7 +84,8 @@ template <typename Algorithm> class RoutingAlgorithms final : public RoutingAlgo
InternalRouteResult
DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const final override;
virtual std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
virtual std::
tuple<std::vector<EdgeWeight>, std::vector<EdgeDuration>, std::vector<EdgeDistance>>
ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
const std::vector<std::size_t> &source_indices,
const std::vector<std::size_t> &target_indices,
@ -192,7 +194,7 @@ inline routing_algorithms::SubMatchingList RoutingAlgorithms<Algorithm>::MapMatc
}
template <typename Algorithm>
std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
std::tuple<std::vector<EdgeWeight>, std::vector<EdgeDuration>, std::vector<EdgeDistance>>
RoutingAlgorithms<Algorithm>::ManyToManySearch(const std::vector<PhantomNode> &phantom_nodes,
const std::vector<std::size_t> &_source_indices,
const std::vector<std::size_t> &_target_indices,

View File

@ -91,7 +91,7 @@ struct NodeBucket
} // namespace
template <typename Algorithm>
std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
std::tuple<std::vector<EdgeWeight>, std::vector<EdgeDuration>, std::vector<EdgeDistance>>
manyToManySearch(SearchEngineData<Algorithm> &engine_working_data,
const DataFacade<Algorithm> &facade,
const std::vector<PhantomNode> &phantom_nodes,

View File

@ -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;
}

View File

@ -217,7 +217,8 @@ Status TripPlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
// compute the duration table of all phantom nodes
auto result_duration_table = util::DistTableWrapper<EdgeWeight>(
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)

View File

@ -178,7 +178,7 @@ void backwardRoutingStep(const DataFacade<Algorithm> &facade,
} // namespace ch
template <>
std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
std::tuple<std::vector<EdgeWeight>, std::vector<EdgeDuration>, std::vector<EdgeDistance>>
manyToManySearch(SearchEngineData<ch::Algorithm> &engine_working_data,
const DataFacade<ch::Algorithm> &facade,
const std::vector<PhantomNode> &phantom_nodes,
@ -248,7 +248,8 @@ manyToManySearch(SearchEngineData<ch::Algorithm> &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

View File

@ -211,7 +211,7 @@ void relaxOutgoingEdges(
// Unidirectional multi-layer Dijkstra search for 1-to-N and N-to-1 matrices
//
template <bool DIRECTION>
std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
std::tuple<std::vector<EdgeWeight>, std::vector<EdgeDuration>, std::vector<EdgeDistance>>
oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
const DataFacade<Algorithm> &facade,
const std::vector<PhantomNode> &phantom_nodes,
@ -392,7 +392,8 @@ oneToManySearch(SearchEngineData<Algorithm> &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 <bool DIRECTION>
std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>>
std::tuple<std::vector<EdgeWeight>, std::vector<EdgeDuration>, std::vector<EdgeDistance>>
manyToManySearch(SearchEngineData<Algorithm> &engine_working_data,
const DataFacade<Algorithm> &facade,
const std::vector<PhantomNode> &phantom_nodes,
@ -601,7 +602,8 @@ manyToManySearch(SearchEngineData<Algorithm> &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<Algorithm> &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<EdgeDuration>, std::vector<EdgeDistance>>
std::tuple<std::vector<EdgeWeight>, std::vector<EdgeDuration>, std::vector<EdgeDistance>>
manyToManySearch(SearchEngineData<mld::Algorithm> &engine_working_data,
const DataFacade<mld::Algorithm> &facade,
const std::vector<PhantomNode> &phantom_nodes,