Skip to content

Commit

Permalink
Merge pull request Project-OSRM#5908 from systemed/debug_way
Browse files Browse the repository at this point in the history
Profile debug script which fetches a way from OSM
  • Loading branch information
akashihi authored and mjjbell committed Jan 17, 2021
2 parents 5266ac1 + 158d260 commit 0637916
Show file tree
Hide file tree
Showing 46 changed files with 1,716 additions and 1,603 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
- ADDED: Added support for multiple via-way restrictions. [#5907](https://github.com/Project-OSRM/osrm-backend/pull/5907)
- ADDED: Add node bindings support for Node 12, 14, and publish binaries [#5918](https://github.com/Project-OSRM/osrm-backend/pull/5918)
- REMOVED: we no longer publish Node 8 binary modules (they are still buildable from source) [#5918](https://github.com/Project-OSRM/osrm-backend/pull/5918)
- Routing:
- FIXED: Avoid copying ManyToMany table results [#5923](https://github.com/Project-OSRM/osrm-backend/pull/5923)
- Misc:
- CHANGED: Unify `.osrm.turn_penalites_index` dump processing same with `.osrm.turn_weight_penalties` and `.osrm.turn_duration_penalties` [#5868](https://github.com/Project-OSRM/osrm-backend/pull/5868)
- Profile:
- ADDED: Profile debug script which fetches a way from OSM then outputs the result of the profile. [#5908](https://github.com/Project-OSRM/osrm-backend/pull/5908)
- Infrastructure
- CHANGED: Bundled protozero updated to v1.7.0. [#5858](https://github.com/Project-OSRM/osrm-backend/pull/5858)
- Windows:
Expand Down
102 changes: 62 additions & 40 deletions include/engine/api/base_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include "engine/hint.hpp"
#include "util/coordinate_calculation.hpp"

#include <boost/algorithm/string/join.hpp>
#include <boost/assert.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/algorithm/transform.hpp>

#include <memory>
Expand All @@ -22,6 +24,8 @@ namespace engine
namespace api
{

static const constexpr char *INTERSECTION_DELIMITER = " / ";

class BaseAPI
{
public:
Expand All @@ -30,92 +34,110 @@ class BaseAPI
{
}

util::json::Array MakeWaypoints(const std::vector<PhantomNodes> &segment_end_coordinates) const
util::json::Array
MakeWaypoints(const std::vector<PhantomNodeCandidates> &waypoint_candidates) const
{
BOOST_ASSERT(parameters.coordinates.size() > 0);
BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1);
BOOST_ASSERT(parameters.coordinates.size() == waypoint_candidates.size());

util::json::Array waypoints;
waypoints.values.resize(parameters.coordinates.size());
waypoints.values[0] = MakeWaypoint(segment_end_coordinates.front().source_phantom);

auto out_iter = std::next(waypoints.values.begin());
boost::range::transform(
segment_end_coordinates, out_iter, [this](const PhantomNodes &phantom_pair) {
return MakeWaypoint(phantom_pair.target_phantom);
});
waypoint_candidates,
waypoints.values.begin(),
[this](const PhantomNodeCandidates &candidates) { return MakeWaypoint(candidates); });
return waypoints;
}

// FIXME: gcc 4.9 does not like MakeWaypoints to be protected
// protected:
util::json::Object MakeWaypoint(const PhantomNode &phantom) const
util::json::Object MakeWaypoint(const PhantomNodeCandidates &candidates) const
{
// TODO: check forward/reverse
const auto toName = [this](const auto &phantom) {
return facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))
.to_string();
};
std::string waypoint_name = boost::algorithm::join(
candidates | boost::adaptors::transformed(toName), INTERSECTION_DELIMITER);

if (parameters.generate_hints)
{
// TODO: check forward/reverse
return json::makeWaypoint(
phantom.location,
util::coordinate_calculation::fccApproximateDistance(phantom.location,
phantom.input_location),
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string(),
Hint{phantom, facade.GetCheckSum()});
std::vector<Hint> hints(candidates.size());
std::transform(
candidates.begin(), candidates.end(), hints.begin(), [this](const auto &phantom) {
return Hint{phantom, facade.GetCheckSum()};
});
return json::makeWaypoint(SnappedLocation(candidates),
util::coordinate_calculation::fccApproximateDistance(
SnappedLocation(candidates), InputLocation(candidates)),
waypoint_name,
hints);
}
else
{
// TODO: check forward/reverse
return json::makeWaypoint(
phantom.location,
util::coordinate_calculation::fccApproximateDistance(phantom.location,
phantom.input_location),
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))
.to_string());
return json::makeWaypoint(SnappedLocation(candidates),
util::coordinate_calculation::fccApproximateDistance(
SnappedLocation(candidates), InputLocation(candidates)),
waypoint_name);
}
}

flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbresult::Waypoint>>>
MakeWaypoints(flatbuffers::FlatBufferBuilder *builder,
const std::vector<PhantomNodes> &segment_end_coordinates) const
const std::vector<PhantomNodeCandidates> &waypoint_candidates) const
{
BOOST_ASSERT(parameters.coordinates.size() > 0);
BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1);
BOOST_ASSERT(parameters.coordinates.size() == waypoint_candidates.size());

std::vector<flatbuffers::Offset<fbresult::Waypoint>> waypoints;
waypoints.resize(parameters.coordinates.size());
waypoints[0] =
MakeWaypoint(builder, segment_end_coordinates.front().source_phantom)->Finish();

std::transform(segment_end_coordinates.begin(),
segment_end_coordinates.end(),
std::next(waypoints.begin()),
[this, builder](const PhantomNodes &phantom_pair) {
return MakeWaypoint(builder, phantom_pair.target_phantom)->Finish();

std::transform(waypoint_candidates.begin(),
waypoint_candidates.end(),
waypoints.begin(),
[this, builder](const PhantomNodeCandidates &candidates) {
return MakeWaypoint(builder, candidates)->Finish();
});
return builder->CreateVector(waypoints);
}

// FIXME: gcc 4.9 does not like MakeWaypoints to be protected
// protected:
std::unique_ptr<fbresult::WaypointBuilder> MakeWaypoint(flatbuffers::FlatBufferBuilder *builder,
const PhantomNode &phantom) const
std::unique_ptr<fbresult::WaypointBuilder>
MakeWaypoint(flatbuffers::FlatBufferBuilder *builder,
const PhantomNodeCandidates &candidates) const
{

const auto &snapped_location = SnappedLocation(candidates);
auto location =
fbresult::Position(static_cast<double>(util::toFloating(phantom.location.lon)),
static_cast<double>(util::toFloating(phantom.location.lat)));
auto name_string = builder->CreateString(
facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string());
fbresult::Position(static_cast<double>(util::toFloating(snapped_location.lon)),
static_cast<double>(util::toFloating(snapped_location.lat)));

const auto toName = [this](const auto &phantom) {
return facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id))
.to_string();
};
std::string waypoint_name = boost::algorithm::join(
candidates | boost::adaptors::transformed(toName), INTERSECTION_DELIMITER);
auto name_string = builder->CreateString(waypoint_name);

flatbuffers::Offset<flatbuffers::String> hint_string;
if (parameters.generate_hints)
{
hint_string = builder->CreateString(Hint{phantom, facade.GetCheckSum()}.ToBase64());
std::vector<Hint> hints(candidates.size());
std::transform(
candidates.begin(), candidates.end(), hints.begin(), [this](const auto &phantom) {
return Hint{phantom, facade.GetCheckSum()};
});
hint_string = builder->CreateString(ToBase64(hints));
}

auto waypoint = std::make_unique<fbresult::WaypointBuilder>(*builder);
waypoint->add_location(&location);
waypoint->add_distance(util::coordinate_calculation::fccApproximateDistance(
phantom.location, phantom.input_location));
snapped_location, InputLocation(candidates)));
waypoint->add_name(name_string);
if (parameters.generate_hints)
{
Expand Down
4 changes: 2 additions & 2 deletions include/engine/api/base_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct BaseParameters
};

std::vector<util::Coordinate> coordinates;
std::vector<boost::optional<Hint>> hints;
std::vector<std::vector<Hint>> hints;
std::vector<boost::optional<double>> radiuses;
std::vector<boost::optional<Bearing>> bearings;
std::vector<boost::optional<Approach>> approaches;
Expand All @@ -93,7 +93,7 @@ struct BaseParameters
SnappingType snapping = SnappingType::Default;

BaseParameters(const std::vector<util::Coordinate> coordinates_ = {},
const std::vector<boost::optional<Hint>> hints_ = {},
const std::vector<std::vector<Hint>> hints_ = {},
std::vector<boost::optional<double>> radiuses_ = {},
std::vector<boost::optional<Bearing>> bearings_ = {},
std::vector<boost::optional<Approach>> approaches_ = {},
Expand Down
2 changes: 1 addition & 1 deletion include/engine/api/json_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ makeWaypoint(const util::Coordinate &location, const double &distance, std::stri
util::json::Object makeWaypoint(const util::Coordinate &location,
const double &distance,
std::string name,
const Hint &hint);
const std::vector<Hint> &location_hints);

util::json::Object makeRouteLeg(guidance::RouteLeg leg, util::json::Array steps);

Expand Down
6 changes: 3 additions & 3 deletions include/engine/api/match_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class MatchAPI final : public RouteAPI
routes.values.reserve(number_of_routes);
for (auto index : util::irange<std::size_t>(0UL, sub_matchings.size()))
{
auto route = MakeRoute(sub_routes[index].segment_end_coordinates,
auto route = MakeRoute(sub_routes[index].route_endpoints,
sub_routes[index].unpacked_path_segments,
sub_routes[index].source_traversed_in_reverse,
sub_routes[index].target_traversed_in_reverse);
Expand Down Expand Up @@ -141,7 +141,7 @@ class MatchAPI final : public RouteAPI
}
const auto &phantom =
sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index];
auto waypoint = BaseAPI::MakeWaypoint(&fb_result, phantom);
auto waypoint = BaseAPI::MakeWaypoint(&fb_result, {phantom});
waypoint->add_matchings_index(matching_index.sub_matching_index);
waypoint->add_alternatives_count(sub_matchings[matching_index.sub_matching_index]
.alternatives_count[matching_index.point_index]);
Expand Down Expand Up @@ -195,7 +195,7 @@ class MatchAPI final : public RouteAPI
}
const auto &phantom =
sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index];
auto waypoint = BaseAPI::MakeWaypoint(phantom);
auto waypoint = BaseAPI::MakeWaypoint({phantom});
waypoint.values["matchings_index"] = matching_index.sub_matching_index;
waypoint.values["waypoint_index"] = matching_index.point_index;
waypoint.values["alternatives_count"] =
Expand Down
4 changes: 2 additions & 2 deletions include/engine/api/nearest_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class NearestAPI final : public BaseAPI
auto node_values = MakeNodes(phantom_node);
fbresult::Uint64Pair nodes{node_values.first, node_values.second};

auto waypoint = MakeWaypoint(&fb_result, phantom_node);
auto waypoint = MakeWaypoint(&fb_result, {phantom_node});
waypoint->add_nodes(&nodes);
return waypoint->Finish();
});
Expand Down Expand Up @@ -100,7 +100,7 @@ class NearestAPI final : public BaseAPI
waypoints.values.begin(),
[this](const PhantomNodeWithDistance &phantom_with_distance) {
auto &phantom_node = phantom_with_distance.phantom_node;
auto waypoint = MakeWaypoint(phantom_node);
auto waypoint = MakeWaypoint({phantom_node});

util::json::Array nodes;

Expand Down
Loading

0 comments on commit 0637916

Please sign in to comment.