2016-02-15 21:20:22 -05:00
|
|
|
#ifndef ENGINE_API_TABLE_HPP
|
|
|
|
#define ENGINE_API_TABLE_HPP
|
|
|
|
|
|
|
|
#include "engine/api/base_api.hpp"
|
2019-09-16 07:32:53 -04:00
|
|
|
#include "engine/api/base_result.hpp"
|
2016-02-15 21:20:22 -05:00
|
|
|
#include "engine/api/json_factory.hpp"
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "engine/api/table_parameters.hpp"
|
2016-02-15 21:20:22 -05:00
|
|
|
|
|
|
|
#include "engine/datafacade/datafacade_base.hpp"
|
|
|
|
|
|
|
|
#include "engine/guidance/assemble_geometry.hpp"
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "engine/guidance/assemble_leg.hpp"
|
2016-02-15 21:20:22 -05:00
|
|
|
#include "engine/guidance/assemble_overview.hpp"
|
2016-05-27 15:05:04 -04:00
|
|
|
#include "engine/guidance/assemble_route.hpp"
|
2016-02-15 21:20:22 -05:00
|
|
|
#include "engine/guidance/assemble_steps.hpp"
|
|
|
|
|
|
|
|
#include "engine/internal_route_result.hpp"
|
|
|
|
|
|
|
|
#include "util/integer_range.hpp"
|
|
|
|
|
2016-03-08 10:46:01 -05:00
|
|
|
#include <boost/range/algorithm/transform.hpp>
|
|
|
|
|
2016-04-12 09:00:08 -04:00
|
|
|
#include <iterator>
|
|
|
|
|
2022-12-11 04:10:26 -05:00
|
|
|
namespace osrm::engine::api
|
2016-02-15 21:20:22 -05:00
|
|
|
{
|
|
|
|
|
2016-02-17 19:41:50 -05:00
|
|
|
class TableAPI final : public BaseAPI
|
2016-02-15 21:20:22 -05:00
|
|
|
{
|
|
|
|
public:
|
2022-08-31 17:39:47 -04:00
|
|
|
virtual ~TableAPI() = default;
|
|
|
|
|
2018-12-11 12:21:57 -05:00
|
|
|
struct TableCellRef
|
|
|
|
{
|
|
|
|
TableCellRef(const std::size_t &row, const std::size_t &column) : row{row}, column{column}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
std::size_t row;
|
|
|
|
std::size_t column;
|
|
|
|
};
|
|
|
|
|
2016-02-17 19:41:50 -05:00
|
|
|
TableAPI(const datafacade::BaseDataFacade &facade_, const TableParameters ¶meters_)
|
|
|
|
: BaseAPI(facade_, parameters_), parameters(parameters_)
|
2016-02-15 21:20:22 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-05 10:40:26 -04:00
|
|
|
virtual void
|
|
|
|
MakeResponse(const std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>> &tables,
|
2022-08-27 06:36:20 -04:00
|
|
|
const std::vector<PhantomNodeCandidates> &candidates,
|
2019-08-05 10:40:26 -04:00
|
|
|
const std::vector<TableCellRef> &fallback_speed_cells,
|
|
|
|
osrm::engine::api::ResultT &response) const
|
|
|
|
{
|
2019-08-15 04:40:23 -04:00
|
|
|
if (response.is<flatbuffers::FlatBufferBuilder>())
|
|
|
|
{
|
|
|
|
auto &fb_result = response.get<flatbuffers::FlatBufferBuilder>();
|
2022-08-27 06:36:20 -04:00
|
|
|
MakeResponse(tables, candidates, fallback_speed_cells, fb_result);
|
2019-08-06 08:31:39 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-15 04:40:23 -04:00
|
|
|
auto &json_result = response.get<util::json::Object>();
|
2022-08-27 06:36:20 -04:00
|
|
|
MakeResponse(tables, candidates, fallback_speed_cells, json_result);
|
2019-08-05 10:40:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
MakeResponse(const std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>> &tables,
|
2022-08-27 06:36:20 -04:00
|
|
|
const std::vector<PhantomNodeCandidates> &candidates,
|
2019-08-05 10:40:26 -04:00
|
|
|
const std::vector<TableCellRef> &fallback_speed_cells,
|
2019-08-15 04:40:23 -04:00
|
|
|
flatbuffers::FlatBufferBuilder &fb_result) const
|
|
|
|
{
|
2019-08-05 10:40:26 -04:00
|
|
|
auto number_of_sources = parameters.sources.size();
|
|
|
|
auto number_of_destinations = parameters.destinations.size();
|
|
|
|
|
2019-08-23 05:20:56 -04:00
|
|
|
auto data_timestamp = facade.GetTimestamp();
|
2019-09-30 09:33:32 -04:00
|
|
|
flatbuffers::Offset<flatbuffers::String> data_version_string;
|
2019-08-23 05:20:56 -04:00
|
|
|
if (!data_timestamp.empty())
|
|
|
|
{
|
|
|
|
data_version_string = fb_result.CreateString(data_timestamp);
|
|
|
|
}
|
|
|
|
|
2019-08-05 10:40:26 -04:00
|
|
|
// symmetric case
|
2019-08-15 08:39:02 -04:00
|
|
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>> sources;
|
2019-08-05 10:40:26 -04:00
|
|
|
if (parameters.sources.empty())
|
|
|
|
{
|
2019-09-16 10:13:33 -04:00
|
|
|
if (!parameters.skip_waypoints)
|
|
|
|
{
|
2022-08-27 06:36:20 -04:00
|
|
|
sources = MakeWaypoints(fb_result, candidates);
|
2019-09-16 07:32:53 -04:00
|
|
|
}
|
2022-08-27 06:36:20 -04:00
|
|
|
number_of_sources = candidates.size();
|
2019-08-05 10:40:26 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-16 10:13:33 -04:00
|
|
|
if (!parameters.skip_waypoints)
|
|
|
|
{
|
2022-08-27 06:36:20 -04:00
|
|
|
sources = MakeWaypoints(fb_result, candidates, parameters.sources);
|
2019-09-16 07:32:53 -04:00
|
|
|
}
|
2019-08-05 10:40:26 -04:00
|
|
|
}
|
|
|
|
|
2019-08-15 08:39:02 -04:00
|
|
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
|
|
|
|
destinations;
|
2019-08-05 10:40:26 -04:00
|
|
|
if (parameters.destinations.empty())
|
|
|
|
{
|
2019-09-16 10:13:33 -04:00
|
|
|
if (!parameters.skip_waypoints)
|
|
|
|
{
|
2022-08-27 06:36:20 -04:00
|
|
|
destinations = MakeWaypoints(fb_result, candidates);
|
2019-09-16 07:32:53 -04:00
|
|
|
}
|
2022-08-27 06:36:20 -04:00
|
|
|
number_of_destinations = candidates.size();
|
2019-08-05 10:40:26 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-16 10:13:33 -04:00
|
|
|
if (!parameters.skip_waypoints)
|
|
|
|
{
|
2022-08-27 06:36:20 -04:00
|
|
|
destinations = MakeWaypoints(fb_result, candidates, parameters.destinations);
|
2019-09-16 07:32:53 -04:00
|
|
|
}
|
2019-08-05 10:40:26 -04:00
|
|
|
}
|
|
|
|
|
2019-09-30 09:33:32 -04:00
|
|
|
bool use_durations = parameters.annotations & TableParameters::AnnotationsType::Duration;
|
|
|
|
flatbuffers::Offset<flatbuffers::Vector<float>> durations;
|
|
|
|
if (use_durations)
|
2019-08-05 10:40:26 -04:00
|
|
|
{
|
2019-08-15 08:39:02 -04:00
|
|
|
durations = MakeDurationTable(fb_result, tables.first);
|
2019-08-05 10:40:26 -04:00
|
|
|
}
|
|
|
|
|
2019-09-30 09:33:32 -04:00
|
|
|
bool use_distances = parameters.annotations & TableParameters::AnnotationsType::Distance;
|
|
|
|
flatbuffers::Offset<flatbuffers::Vector<float>> distances;
|
|
|
|
if (use_distances)
|
2019-08-05 10:40:26 -04:00
|
|
|
{
|
2019-08-15 08:39:02 -04:00
|
|
|
distances = MakeDistanceTable(fb_result, tables.second);
|
2019-08-05 10:40:26 -04:00
|
|
|
}
|
|
|
|
|
2019-09-30 09:33:32 -04:00
|
|
|
bool have_speed_cells =
|
2022-10-28 10:16:12 -04:00
|
|
|
parameters.fallback_speed != from_alias<double>(INVALID_FALLBACK_SPEED) &&
|
|
|
|
parameters.fallback_speed > 0;
|
2019-09-30 09:33:32 -04:00
|
|
|
flatbuffers::Offset<flatbuffers::Vector<uint32_t>> speed_cells;
|
|
|
|
if (have_speed_cells)
|
2019-08-05 10:40:26 -04:00
|
|
|
{
|
2019-08-15 08:39:02 -04:00
|
|
|
speed_cells = MakeEstimatesTable(fb_result, fallback_speed_cells);
|
2019-08-05 10:40:26 -04:00
|
|
|
}
|
2019-08-12 07:27:28 -04:00
|
|
|
|
2019-08-15 08:39:02 -04:00
|
|
|
fbresult::TableBuilder table(fb_result);
|
|
|
|
table.add_destinations(destinations);
|
2019-08-12 07:27:28 -04:00
|
|
|
table.add_rows(number_of_sources);
|
|
|
|
table.add_cols(number_of_destinations);
|
2019-09-30 09:33:32 -04:00
|
|
|
if (use_durations)
|
2019-08-15 08:39:02 -04:00
|
|
|
{
|
2019-09-30 09:33:32 -04:00
|
|
|
table.add_durations(durations);
|
2019-08-15 08:39:02 -04:00
|
|
|
}
|
2019-09-30 09:33:32 -04:00
|
|
|
if (use_distances)
|
2019-08-15 08:39:02 -04:00
|
|
|
{
|
2019-09-30 09:33:32 -04:00
|
|
|
table.add_distances(distances);
|
2019-08-15 08:39:02 -04:00
|
|
|
}
|
2019-09-30 09:33:32 -04:00
|
|
|
if (have_speed_cells)
|
2019-08-15 08:39:02 -04:00
|
|
|
{
|
2019-09-30 09:33:32 -04:00
|
|
|
table.add_fallback_speed_cells(speed_cells);
|
2019-08-15 08:39:02 -04:00
|
|
|
}
|
|
|
|
auto table_buffer = table.Finish();
|
|
|
|
|
|
|
|
fbresult::FBResultBuilder response(fb_result);
|
2019-09-30 09:33:32 -04:00
|
|
|
if (!data_timestamp.empty())
|
2019-08-23 05:20:56 -04:00
|
|
|
{
|
2019-09-30 09:33:32 -04:00
|
|
|
response.add_data_version(data_version_string);
|
2019-08-23 05:20:56 -04:00
|
|
|
}
|
2019-08-15 08:39:02 -04:00
|
|
|
response.add_table(table_buffer);
|
|
|
|
response.add_waypoints(sources);
|
2019-08-05 10:40:26 -04:00
|
|
|
fb_result.Finish(response.Finish());
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:18:55 -04:00
|
|
|
virtual void
|
|
|
|
MakeResponse(const std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>> &tables,
|
2022-08-27 06:36:20 -04:00
|
|
|
const std::vector<PhantomNodeCandidates> &candidates,
|
2018-12-11 12:21:57 -05:00
|
|
|
const std::vector<TableCellRef> &fallback_speed_cells,
|
2018-04-20 18:18:55 -04:00
|
|
|
util::json::Object &response) const
|
2016-02-15 21:20:22 -05:00
|
|
|
{
|
2016-03-03 18:23:38 -05:00
|
|
|
auto number_of_sources = parameters.sources.size();
|
2016-03-03 08:26:13 -05:00
|
|
|
auto number_of_destinations = parameters.destinations.size();
|
2016-03-03 18:23:38 -05:00
|
|
|
|
2016-02-15 21:20:22 -05:00
|
|
|
// symmetric case
|
|
|
|
if (parameters.sources.empty())
|
|
|
|
{
|
2019-09-16 10:13:33 -04:00
|
|
|
if (!parameters.skip_waypoints)
|
|
|
|
{
|
2022-08-27 06:36:20 -04:00
|
|
|
response.values["sources"] = MakeWaypoints(candidates);
|
2019-09-16 07:32:53 -04:00
|
|
|
}
|
2022-08-27 06:36:20 -04:00
|
|
|
number_of_sources = candidates.size();
|
2016-02-15 21:20:22 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-16 10:13:33 -04:00
|
|
|
if (!parameters.skip_waypoints)
|
|
|
|
{
|
2022-08-27 06:36:20 -04:00
|
|
|
response.values["sources"] = MakeWaypoints(candidates, parameters.sources);
|
2019-09-16 07:32:53 -04:00
|
|
|
}
|
2016-03-03 18:23:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters.destinations.empty())
|
|
|
|
{
|
2019-09-16 10:13:33 -04:00
|
|
|
if (!parameters.skip_waypoints)
|
|
|
|
{
|
2022-08-27 06:36:20 -04:00
|
|
|
response.values["destinations"] = MakeWaypoints(candidates);
|
2019-09-16 07:32:53 -04:00
|
|
|
}
|
2022-08-27 06:36:20 -04:00
|
|
|
number_of_destinations = candidates.size();
|
2016-03-03 18:23:38 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-16 10:13:33 -04:00
|
|
|
if (!parameters.skip_waypoints)
|
|
|
|
{
|
2022-08-27 06:36:20 -04:00
|
|
|
response.values["destinations"] =
|
|
|
|
MakeWaypoints(candidates, parameters.destinations);
|
2019-09-16 07:32:53 -04:00
|
|
|
}
|
2016-02-15 21:20:22 -05:00
|
|
|
}
|
2016-03-03 18:23:38 -05:00
|
|
|
|
2018-04-20 18:18:55 -04:00
|
|
|
if (parameters.annotations & TableParameters::AnnotationsType::Duration)
|
|
|
|
{
|
|
|
|
response.values["durations"] =
|
|
|
|
MakeDurationTable(tables.first, number_of_sources, number_of_destinations);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters.annotations & TableParameters::AnnotationsType::Distance)
|
|
|
|
{
|
|
|
|
response.values["distances"] =
|
|
|
|
MakeDistanceTable(tables.second, number_of_sources, number_of_destinations);
|
|
|
|
}
|
|
|
|
|
2022-10-28 10:16:12 -04:00
|
|
|
if (parameters.fallback_speed != from_alias<double>(INVALID_FALLBACK_SPEED) &&
|
|
|
|
parameters.fallback_speed > 0)
|
2018-12-11 12:21:57 -05:00
|
|
|
{
|
|
|
|
response.values["fallback_speed_cells"] = MakeEstimatesTable(fallback_speed_cells);
|
|
|
|
}
|
|
|
|
|
2016-04-04 08:05:38 -04:00
|
|
|
response.values["code"] = "Ok";
|
2022-08-22 15:07:32 -04:00
|
|
|
auto data_timestamp = facade.GetTimestamp();
|
|
|
|
if (!data_timestamp.empty())
|
|
|
|
{
|
|
|
|
response.values["data_version"] = data_timestamp;
|
|
|
|
}
|
2016-02-15 21:20:22 -05:00
|
|
|
}
|
|
|
|
|
2016-12-15 09:28:54 -05:00
|
|
|
protected:
|
2019-08-05 10:40:26 -04:00
|
|
|
virtual flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
|
2019-08-15 04:40:23 -04:00
|
|
|
MakeWaypoints(flatbuffers::FlatBufferBuilder &builder,
|
2022-08-27 06:36:20 -04:00
|
|
|
const std::vector<PhantomNodeCandidates> &candidates) const
|
2019-08-05 10:40:26 -04:00
|
|
|
{
|
|
|
|
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
|
2022-08-27 06:36:20 -04:00
|
|
|
waypoints.reserve(candidates.size());
|
|
|
|
BOOST_ASSERT(candidates.size() == parameters.coordinates.size());
|
2019-08-05 10:40:26 -04:00
|
|
|
|
2022-08-27 06:36:20 -04:00
|
|
|
boost::range::transform(candidates,
|
|
|
|
std::back_inserter(waypoints),
|
|
|
|
[this, &builder](const PhantomNodeCandidates &candidates) {
|
|
|
|
return BaseAPI::MakeWaypoint(&builder, candidates)->Finish();
|
|
|
|
});
|
2019-08-05 10:40:26 -04:00
|
|
|
return builder.CreateVector(waypoints);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
|
2019-08-15 04:40:23 -04:00
|
|
|
MakeWaypoints(flatbuffers::FlatBufferBuilder &builder,
|
2022-08-27 06:36:20 -04:00
|
|
|
const std::vector<PhantomNodeCandidates> &candidates,
|
2019-08-05 10:40:26 -04:00
|
|
|
const std::vector<std::size_t> &indices) const
|
|
|
|
{
|
|
|
|
std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
|
|
|
|
waypoints.reserve(indices.size());
|
2022-08-27 06:36:20 -04:00
|
|
|
boost::range::transform(
|
|
|
|
indices,
|
|
|
|
std::back_inserter(waypoints),
|
|
|
|
[this, &builder, &candidates](const std::size_t idx) {
|
|
|
|
BOOST_ASSERT(idx < candidates.size());
|
|
|
|
return BaseAPI::MakeWaypoint(&builder, candidates[idx])->Finish();
|
|
|
|
});
|
2019-08-05 10:40:26 -04:00
|
|
|
return builder.CreateVector(waypoints);
|
|
|
|
}
|
|
|
|
|
2019-08-06 05:51:38 -04:00
|
|
|
virtual flatbuffers::Offset<flatbuffers::Vector<float>>
|
2019-08-15 04:40:23 -04:00
|
|
|
MakeDurationTable(flatbuffers::FlatBufferBuilder &builder,
|
2022-10-28 10:16:12 -04:00
|
|
|
const std::vector<EdgeDuration> &values) const
|
2019-08-05 10:40:26 -04:00
|
|
|
{
|
2019-08-06 05:51:38 -04:00
|
|
|
std::vector<float> distance_table;
|
|
|
|
distance_table.resize(values.size());
|
2019-08-15 04:40:23 -04:00
|
|
|
std::transform(
|
2022-10-28 10:16:12 -04:00
|
|
|
values.begin(), values.end(), distance_table.begin(), [](const EdgeDuration duration) {
|
2019-08-15 04:40:23 -04:00
|
|
|
if (duration == MAXIMAL_EDGE_DURATION)
|
|
|
|
{
|
|
|
|
return 0.;
|
|
|
|
}
|
2022-10-28 10:16:12 -04:00
|
|
|
return from_alias<double>(duration) / 10.;
|
2019-08-15 04:40:23 -04:00
|
|
|
});
|
2019-08-06 05:51:38 -04:00
|
|
|
return builder.CreateVector(distance_table);
|
2019-08-05 10:40:26 -04:00
|
|
|
}
|
|
|
|
|
2019-08-06 05:51:38 -04:00
|
|
|
virtual flatbuffers::Offset<flatbuffers::Vector<float>>
|
2019-08-15 04:40:23 -04:00
|
|
|
MakeDistanceTable(flatbuffers::FlatBufferBuilder &builder,
|
2019-08-06 05:51:38 -04:00
|
|
|
const std::vector<EdgeDistance> &values) const
|
2019-08-05 10:40:26 -04:00
|
|
|
{
|
2019-08-06 05:51:38 -04:00
|
|
|
std::vector<float> duration_table;
|
|
|
|
duration_table.resize(values.size());
|
2019-08-15 04:40:23 -04:00
|
|
|
std::transform(
|
|
|
|
values.begin(), values.end(), duration_table.begin(), [](const EdgeDistance distance) {
|
|
|
|
if (distance == INVALID_EDGE_DISTANCE)
|
|
|
|
{
|
|
|
|
return 0.;
|
|
|
|
}
|
2022-10-28 10:16:12 -04:00
|
|
|
return std::round(from_alias<double>(distance) * 10) / 10.;
|
2019-08-15 04:40:23 -04:00
|
|
|
});
|
2019-08-06 05:51:38 -04:00
|
|
|
return builder.CreateVector(duration_table);
|
2019-08-05 10:40:26 -04:00
|
|
|
}
|
|
|
|
|
2019-08-06 05:51:38 -04:00
|
|
|
virtual flatbuffers::Offset<flatbuffers::Vector<uint32_t>>
|
2019-08-15 04:40:23 -04:00
|
|
|
MakeEstimatesTable(flatbuffers::FlatBufferBuilder &builder,
|
|
|
|
const std::vector<TableCellRef> &fallback_speed_cells) const
|
2019-08-05 10:40:26 -04:00
|
|
|
{
|
2019-08-06 05:51:38 -04:00
|
|
|
std::vector<uint32_t> fb_table;
|
2019-08-05 10:40:26 -04:00
|
|
|
fb_table.reserve(fallback_speed_cells.size());
|
|
|
|
std::for_each(
|
2019-08-15 04:40:23 -04:00
|
|
|
fallback_speed_cells.begin(), fallback_speed_cells.end(), [&](const auto &cell) {
|
|
|
|
fb_table.push_back(cell.row);
|
|
|
|
fb_table.push_back(cell.column);
|
|
|
|
});
|
2019-08-05 10:40:26 -04:00
|
|
|
return builder.CreateVector(fb_table);
|
|
|
|
}
|
|
|
|
|
2022-08-27 06:36:20 -04:00
|
|
|
virtual util::json::Array
|
|
|
|
MakeWaypoints(const std::vector<PhantomNodeCandidates> &candidates) const
|
2016-02-15 21:20:22 -05:00
|
|
|
{
|
|
|
|
util::json::Array json_waypoints;
|
2022-08-27 06:36:20 -04:00
|
|
|
json_waypoints.values.reserve(candidates.size());
|
|
|
|
BOOST_ASSERT(candidates.size() == parameters.coordinates.size());
|
2016-03-08 10:46:01 -05:00
|
|
|
|
2022-08-27 06:36:20 -04:00
|
|
|
boost::range::transform(candidates,
|
|
|
|
std::back_inserter(json_waypoints.values),
|
|
|
|
[this](const PhantomNodeCandidates &candidates) {
|
|
|
|
return BaseAPI::MakeWaypoint(candidates);
|
|
|
|
});
|
2016-02-15 21:20:22 -05:00
|
|
|
return json_waypoints;
|
|
|
|
}
|
|
|
|
|
2022-08-27 06:36:20 -04:00
|
|
|
virtual util::json::Array MakeWaypoints(const std::vector<PhantomNodeCandidates> &candidates,
|
2016-02-15 21:20:22 -05:00
|
|
|
const std::vector<std::size_t> &indices) const
|
|
|
|
{
|
|
|
|
util::json::Array json_waypoints;
|
|
|
|
json_waypoints.values.reserve(indices.size());
|
2016-05-27 15:05:04 -04:00
|
|
|
boost::range::transform(indices,
|
|
|
|
std::back_inserter(json_waypoints.values),
|
2022-08-27 06:36:20 -04:00
|
|
|
[this, &candidates](const std::size_t idx) {
|
|
|
|
BOOST_ASSERT(idx < candidates.size());
|
|
|
|
return BaseAPI::MakeWaypoint(candidates[idx]);
|
2016-03-08 10:46:01 -05:00
|
|
|
});
|
2016-02-15 21:20:22 -05:00
|
|
|
return json_waypoints;
|
|
|
|
}
|
|
|
|
|
2022-10-28 10:16:12 -04:00
|
|
|
virtual util::json::Array MakeDurationTable(const std::vector<EdgeDuration> &values,
|
2018-04-20 18:18:55 -04:00
|
|
|
std::size_t number_of_rows,
|
|
|
|
std::size_t number_of_columns) const
|
2016-02-15 21:20:22 -05:00
|
|
|
{
|
|
|
|
util::json::Array json_table;
|
2016-04-12 06:42:16 -04:00
|
|
|
for (const auto row : util::irange<std::size_t>(0UL, number_of_rows))
|
2016-02-15 21:20:22 -05:00
|
|
|
{
|
|
|
|
util::json::Array json_row;
|
|
|
|
auto row_begin_iterator = values.begin() + (row * number_of_columns);
|
|
|
|
auto row_end_iterator = values.begin() + ((row + 1) * number_of_columns);
|
2016-03-03 18:23:38 -05:00
|
|
|
json_row.values.resize(number_of_columns);
|
2016-05-27 15:05:04 -04:00
|
|
|
std::transform(row_begin_iterator,
|
|
|
|
row_end_iterator,
|
|
|
|
json_row.values.begin(),
|
2022-10-28 10:16:12 -04:00
|
|
|
[](const EdgeDuration duration) {
|
2017-01-19 16:52:09 -05:00
|
|
|
if (duration == MAXIMAL_EDGE_DURATION)
|
2016-03-03 08:26:13 -05:00
|
|
|
{
|
|
|
|
return util::json::Value(util::json::Null());
|
|
|
|
}
|
2018-04-20 18:18:55 -04:00
|
|
|
// division by 10 because the duration is in deciseconds (10s)
|
2022-10-28 10:16:12 -04:00
|
|
|
return util::json::Value(
|
|
|
|
util::json::Number(from_alias<double>(duration) / 10.));
|
2016-03-03 08:26:13 -05:00
|
|
|
});
|
2016-02-15 21:20:22 -05:00
|
|
|
json_table.values.push_back(std::move(json_row));
|
|
|
|
}
|
|
|
|
return json_table;
|
|
|
|
}
|
|
|
|
|
2018-04-20 18:18:55 -04:00
|
|
|
virtual util::json::Array MakeDistanceTable(const std::vector<EdgeDistance> &values,
|
|
|
|
std::size_t number_of_rows,
|
|
|
|
std::size_t number_of_columns) const
|
|
|
|
{
|
|
|
|
util::json::Array json_table;
|
|
|
|
for (const auto row : util::irange<std::size_t>(0UL, number_of_rows))
|
|
|
|
{
|
|
|
|
util::json::Array json_row;
|
|
|
|
auto row_begin_iterator = values.begin() + (row * number_of_columns);
|
|
|
|
auto row_end_iterator = values.begin() + ((row + 1) * number_of_columns);
|
|
|
|
json_row.values.resize(number_of_columns);
|
|
|
|
std::transform(row_begin_iterator,
|
|
|
|
row_end_iterator,
|
|
|
|
json_row.values.begin(),
|
|
|
|
[](const EdgeDistance distance) {
|
|
|
|
if (distance == INVALID_EDGE_DISTANCE)
|
|
|
|
{
|
|
|
|
return util::json::Value(util::json::Null());
|
|
|
|
}
|
|
|
|
// round to single decimal place
|
2022-10-28 10:16:12 -04:00
|
|
|
return util::json::Value(util::json::Number(
|
|
|
|
std::round(from_alias<double>(distance) * 10) / 10.));
|
2018-04-20 18:18:55 -04:00
|
|
|
});
|
|
|
|
json_table.values.push_back(std::move(json_row));
|
|
|
|
}
|
|
|
|
return json_table;
|
|
|
|
}
|
|
|
|
|
2018-12-11 12:21:57 -05:00
|
|
|
virtual util::json::Array
|
|
|
|
MakeEstimatesTable(const std::vector<TableCellRef> &fallback_speed_cells) const
|
|
|
|
{
|
|
|
|
util::json::Array json_table;
|
|
|
|
std::for_each(
|
|
|
|
fallback_speed_cells.begin(), fallback_speed_cells.end(), [&](const auto &cell) {
|
|
|
|
util::json::Array row;
|
|
|
|
row.values.push_back(util::json::Number(cell.row));
|
|
|
|
row.values.push_back(util::json::Number(cell.column));
|
|
|
|
json_table.values.push_back(std::move(row));
|
|
|
|
});
|
|
|
|
return json_table;
|
|
|
|
}
|
|
|
|
|
2016-02-15 21:20:22 -05:00
|
|
|
const TableParameters ¶meters;
|
|
|
|
};
|
|
|
|
|
2022-12-20 12:00:11 -05:00
|
|
|
} // namespace osrm::engine::api
|
2016-02-15 21:20:22 -05:00
|
|
|
|
|
|
|
#endif
|