Refactor guidance generation
This commit is contained in:
committed by
Patrick Niklaus
parent
fa4ba42f15
commit
efd33b295a
@@ -4,21 +4,15 @@
|
||||
#include "engine/plugins/plugin_base.hpp"
|
||||
|
||||
#include "engine/object_encoder.hpp"
|
||||
#include "contractor/query_edge.hpp"
|
||||
#include "engine/search_engine.hpp"
|
||||
#include "engine/descriptors/descriptor_base.hpp"
|
||||
#include "util/json_renderer.hpp"
|
||||
#include "util/make_unique.hpp"
|
||||
#include "util/string_util.hpp"
|
||||
#include "util/timing_util.hpp"
|
||||
|
||||
#include "osrm/json_container.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
#include "engine/plugins/plugin_base.hpp"
|
||||
|
||||
#include "util/json_renderer.hpp"
|
||||
|
||||
#include "osrm/json_container.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
#include "engine/map_matching/bayes_classifier.hpp"
|
||||
#include "engine/object_encoder.hpp"
|
||||
#include "engine/search_engine.hpp"
|
||||
#include "engine/descriptors/descriptor_base.hpp"
|
||||
#include "engine/descriptors/json_descriptor.hpp"
|
||||
#include "engine/guidance/textual_route_annotation.hpp"
|
||||
#include "engine/guidance/segment_list.hpp"
|
||||
#include "engine/api_response_generator.hpp"
|
||||
#include "engine/routing_algorithms/map_matching.hpp"
|
||||
#include "util/compute_angle.hpp"
|
||||
#include "util/integer_range.hpp"
|
||||
@@ -185,55 +186,37 @@ template <class DataFacadeT> class MapMatchingPlugin : public BasePlugin
|
||||
subtrace.values["confidence"] = sub.confidence;
|
||||
}
|
||||
|
||||
JSONDescriptor<DataFacadeT> json_descriptor(facade);
|
||||
json_descriptor.SetConfig(route_parameters);
|
||||
auto response_generator = osrm::engine::MakeApiResponseGenerator(facade);
|
||||
|
||||
subtrace.values["hint_data"] = json_descriptor.BuildHintData(raw_route);
|
||||
subtrace.values["hint_data"] = response_generator.BuildHintData(raw_route);
|
||||
|
||||
if (route_parameters.geometry || route_parameters.print_instructions)
|
||||
{
|
||||
DescriptionFactory factory;
|
||||
FixedPointCoordinate current_coordinate;
|
||||
factory.SetStartSegment(raw_route.segment_end_coordinates.front().source_phantom,
|
||||
raw_route.source_traversed_in_reverse.front());
|
||||
for (const auto i :
|
||||
osrm::irange<std::size_t>(0, raw_route.unpacked_path_segments.size()))
|
||||
{
|
||||
for (const PathData &path_data : raw_route.unpacked_path_segments[i])
|
||||
{
|
||||
current_coordinate = facade->GetCoordinateOfNode(path_data.node);
|
||||
factory.AppendSegment(current_coordinate, path_data);
|
||||
}
|
||||
factory.SetEndSegment(raw_route.segment_end_coordinates[i].target_phantom,
|
||||
raw_route.target_traversed_in_reverse[i],
|
||||
raw_route.is_via_leg(i));
|
||||
}
|
||||
|
||||
factory.Run(route_parameters.zoom_level);
|
||||
|
||||
// we need because we don't run path simplification
|
||||
for (auto &segment : factory.path_description)
|
||||
{
|
||||
segment.necessary = true;
|
||||
}
|
||||
using SegmentList = osrm::engine::guidance::SegmentList<DataFacadeT>;
|
||||
//Passing false to extract_alternative extracts the route.
|
||||
const constexpr bool EXTRACT_ROUTE = false;
|
||||
// by passing false to segment_list, we skip the douglas peucker simplification
|
||||
// and mark all segments as necessary within the generation process
|
||||
const constexpr bool NO_ROUTE_SIMPLIFICATION = false;
|
||||
SegmentList segment_list(raw_route, EXTRACT_ROUTE, route_parameters.zoom_level,
|
||||
NO_ROUTE_SIMPLIFICATION, facade);
|
||||
|
||||
if (route_parameters.geometry)
|
||||
{
|
||||
subtrace.values["geometry"] =
|
||||
factory.AppendGeometryString(route_parameters.compression);
|
||||
response_generator.GetGeometry(route_parameters.compression, segment_list);
|
||||
}
|
||||
|
||||
if (route_parameters.print_instructions)
|
||||
{
|
||||
std::vector<typename JSONDescriptor<DataFacadeT>::Segment> temp_segments;
|
||||
subtrace.values["instructions"] =
|
||||
json_descriptor.BuildTextualDescription(factory, temp_segments);
|
||||
osrm::engine::guidance::AnnotateRoute<DataFacadeT>(
|
||||
segment_list.Get(), facade);
|
||||
}
|
||||
|
||||
factory.BuildRouteSummary(factory.get_entire_length(), raw_route.shortest_path_length);
|
||||
osrm::json::Object json_route_summary;
|
||||
json_route_summary.values["total_distance"] = factory.summary.distance;
|
||||
json_route_summary.values["total_time"] = factory.summary.duration;
|
||||
json_route_summary.values["total_distance"] = segment_list.GetDistance();
|
||||
json_route_summary.values["total_time"] = segment_list.GetDuration();
|
||||
subtrace.values["route_summary"] = json_route_summary;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
#define NEAREST_HPP
|
||||
|
||||
#include "engine/plugins/plugin_base.hpp"
|
||||
|
||||
#include "engine/phantom_node.hpp"
|
||||
#include "util/integer_range.hpp"
|
||||
#include "util/json_renderer.hpp"
|
||||
|
||||
#include "osrm/json_container.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
#include "engine/plugins/plugin_base.hpp"
|
||||
|
||||
#include "util/json_renderer.hpp"
|
||||
|
||||
#include "osrm/json_container.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -9,17 +9,12 @@
|
||||
#include "engine/trip/trip_farthest_insertion.hpp"
|
||||
#include "engine/trip/trip_brute_force.hpp"
|
||||
#include "engine/search_engine.hpp"
|
||||
#include "util/matrix_graph_wrapper.hpp" // wrapper to use tarjan
|
||||
// scc on dist table
|
||||
#include "engine/descriptors/descriptor_base.hpp" // to make json output
|
||||
#include "engine/descriptors/json_descriptor.hpp" // to make json output
|
||||
#include "util/matrix_graph_wrapper.hpp" // wrapper to use tarjan scc on dist table
|
||||
#include "engine/api_response_generator.hpp"
|
||||
#include "util/make_unique.hpp"
|
||||
#include "util/timing_util.hpp" // to time runtime
|
||||
//#include "util/simple_logger.hpp" // for logging output
|
||||
#include "util/dist_table_wrapper.hpp" // to access the dist
|
||||
// table more easily
|
||||
|
||||
#include "util/dist_table_wrapper.hpp" // to access the dist table more easily
|
||||
#include "osrm/json_container.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
@@ -284,7 +279,6 @@ template <class DataFacadeT> class RoundTripPlugin final : public BasePlugin
|
||||
|
||||
std::vector<std::vector<NodeID>> route_result;
|
||||
route_result.reserve(scc.GetNumberOfComponents());
|
||||
TIMER_START(TRIP_TIMER);
|
||||
// run Trip computation for every SCC
|
||||
for (std::size_t k = 0; k < scc.GetNumberOfComponents(); ++k)
|
||||
{
|
||||
@@ -337,24 +331,20 @@ template <class DataFacadeT> class RoundTripPlugin final : public BasePlugin
|
||||
comp_route.push_back(ComputeRoute(phantom_node_list, route_parameters, elem));
|
||||
}
|
||||
|
||||
TIMER_STOP(TRIP_TIMER);
|
||||
|
||||
// prepare JSON output
|
||||
// create a json object for every trip
|
||||
osrm::json::Array trip;
|
||||
for (std::size_t i = 0; i < route_result.size(); ++i)
|
||||
{
|
||||
std::unique_ptr<BaseDescriptor<DataFacadeT>> descriptor =
|
||||
osrm::make_unique<JSONDescriptor<DataFacadeT>>(facade);
|
||||
descriptor->SetConfig(route_parameters);
|
||||
|
||||
osrm::json::Object scc_trip;
|
||||
|
||||
// annotate comp_route[i] as a json trip
|
||||
auto generator = osrm::engine::MakeApiResponseGenerator(facade);
|
||||
generator.DescribeRoute(route_parameters, comp_route[i], scc_trip);
|
||||
|
||||
// set permutation output
|
||||
SetLocPermutationOutput(route_result[i], scc_trip);
|
||||
// set viaroute output
|
||||
descriptor->Run(comp_route[i], scc_trip);
|
||||
|
||||
trip.values.push_back(std::move(scc_trip));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,17 +3,14 @@
|
||||
|
||||
#include "engine/plugins/plugin_base.hpp"
|
||||
|
||||
#include "engine/api_response_generator.hpp"
|
||||
#include "engine/object_encoder.hpp"
|
||||
#include "engine/search_engine.hpp"
|
||||
#include "engine/descriptors/descriptor_base.hpp"
|
||||
#include "engine/descriptors/gpx_descriptor.hpp"
|
||||
#include "engine/descriptors/json_descriptor.hpp"
|
||||
#include "util/integer_range.hpp"
|
||||
#include "util/json_renderer.hpp"
|
||||
#include "util/make_unique.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/timing_util.hpp"
|
||||
|
||||
#include "osrm/json_container.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
@@ -26,7 +23,6 @@
|
||||
template <class DataFacadeT> class ViaRoutePlugin final : public BasePlugin
|
||||
{
|
||||
private:
|
||||
DescriptorTable descriptor_table;
|
||||
std::string descriptor_string;
|
||||
std::unique_ptr<SearchEngine<DataFacadeT>> search_engine_ptr;
|
||||
DataFacadeT *facade;
|
||||
@@ -38,10 +34,6 @@ template <class DataFacadeT> class ViaRoutePlugin final : public BasePlugin
|
||||
max_locations_viaroute(max_locations_viaroute)
|
||||
{
|
||||
search_engine_ptr = osrm::make_unique<SearchEngine<DataFacadeT>>(facade);
|
||||
|
||||
descriptor_table.emplace("json", 0);
|
||||
descriptor_table.emplace("gpx", 1);
|
||||
// descriptor_table.emplace("geojson", 2);
|
||||
}
|
||||
|
||||
virtual ~ViaRoutePlugin() {}
|
||||
@@ -139,22 +131,8 @@ template <class DataFacadeT> class ViaRoutePlugin final : public BasePlugin
|
||||
|
||||
bool no_route = INVALID_EDGE_WEIGHT == raw_route.shortest_path_length;
|
||||
|
||||
std::unique_ptr<BaseDescriptor<DataFacadeT>> descriptor;
|
||||
switch (descriptor_table.get_id(route_parameters.output_format))
|
||||
{
|
||||
case 1:
|
||||
descriptor = osrm::make_unique<GPXDescriptor<DataFacadeT>>(facade);
|
||||
break;
|
||||
// case 2:
|
||||
// descriptor = osrm::make_unique<GEOJSONDescriptor<DataFacadeT>>();
|
||||
// break;
|
||||
default:
|
||||
descriptor = osrm::make_unique<JSONDescriptor<DataFacadeT>>(facade);
|
||||
break;
|
||||
}
|
||||
|
||||
descriptor->SetConfig(route_parameters);
|
||||
descriptor->Run(raw_route, json_result);
|
||||
auto generator = osrm::engine::MakeApiResponseGenerator(facade);
|
||||
generator.DescribeRoute(route_parameters, raw_route, json_result);
|
||||
|
||||
// we can only know this after the fact, different SCC ids still
|
||||
// allow for connection in one direction.
|
||||
|
||||
Reference in New Issue
Block a user