From 07278fdce3ceac6a87aa067c772d840329f7d6a5 Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Thu, 9 Mar 2017 11:06:35 +0100 Subject: [PATCH 01/12] The table service now supports queries for both durations and distances. To this end, the concept of "EdgePayloads" was introduced. --- CMakeLists.txt | 12 ++ docs/http.md | 11 +- include/contractor/contractor_graph.hpp | 9 +- include/contractor/graph_contractor.hpp | 10 +- .../contractor/graph_contractor_adaptors.hpp | 4 +- include/contractor/query_edge.hpp | 18 ++- include/engine/api/table_api.hpp | 32 ++-- include/engine/api/table_parameters.hpp | 15 +- include/engine/api/table_payload.hpp | 84 +++++++++++ include/engine/geospatial_query.hpp | 38 ++++- include/engine/hint.hpp | 4 +- include/engine/phantom_node.hpp | 55 ++++--- include/engine/routing_algorithms.hpp | 43 +++++- .../routing_algorithms/many_to_many.hpp | 2 +- .../routing_algorithms/routing_base.hpp | 30 +++- include/engine/search_engine_data.hpp | 5 +- .../extractor/compressed_edge_container.hpp | 9 +- include/extractor/edge_based_edge.hpp | 21 +-- include/extractor/internal_extractor_edge.hpp | 4 +- include/extractor/node_based_edge.hpp | 19 +-- include/partition/edge_based_graph_reader.hpp | 22 +-- .../server/api/table_parameter_grammar.hpp | 10 +- include/server/service/match_service.hpp | 2 +- include/server/service/nearest_service.hpp | 2 +- include/server/service/route_service.hpp | 2 +- include/server/service/table_service.hpp | 2 +- include/server/service/tile_service.hpp | 2 +- include/server/service/trip_service.hpp | 2 +- include/util/node_based_graph.hpp | 12 +- include/util/payload.hpp | 138 ++++++++++++++++++ include/util/typedefs.hpp | 4 +- src/contractor/contractor.cpp | 2 +- src/contractor/graph_contractor.cpp | 18 ++- src/engine/plugins/table.cpp | 2 +- src/engine/plugins/trip.cpp | 4 +- .../routing_algorithms/alternative_path.cpp | 2 +- .../routing_algorithms/many_to_many.cpp | 62 ++++---- src/extractor/compressed_edge_container.cpp | 20 +-- src/extractor/edge_based_graph_factory.cpp | 8 +- src/extractor/extraction_containers.cpp | 9 +- src/extractor/graph_compressor.cpp | 24 +-- unit_tests/server/parameters_parser.cpp | 2 +- 42 files changed, 571 insertions(+), 205 deletions(-) create mode 100644 include/engine/api/table_payload.hpp create mode 100644 include/util/payload.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ea32ec110c7..8081f1899e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -819,3 +819,15 @@ foreach(header ${headers_to_check}) endforeach() add_library(check-headers STATIC EXCLUDE_FROM_ALL ${sources}) set_target_properties(check-headers PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${check_headers_dir}) + +if(PAYLOAD_TYPE MATCHES DurationsAndDistances) + message(STATUS "Configuring OSRM to support duration+distance payload") + add_definitions("-DPAYLOAD_TYPE_DURATIONS_AND_DISTANCES") +elseif(PAYLOAD_TYPE MATCHES Durations) + message(STATUS "Configuring OSRM to support duration payload") + add_definitions("-DPAYLOAD_TYPE_DURATIONS") +else() + message(STATUS "Unrecognized or missing payload type - will default to duration payload") + add_definitions("-DPAYLOAD_TYPE_DURATIONS") +endif() + diff --git a/docs/http.md b/docs/http.md index 674514e4802..b94492725c1 100644 --- a/docs/http.md +++ b/docs/http.md @@ -212,10 +212,11 @@ GET /table/v1/{profile}/{coordinates}?{sources}=[{elem}...];&destinations=[{elem In addition to the [general options](#general-options) the following options are supported for this service: -|Option |Values |Description | -|------------|--------------------------------------------------|---------------------------------------------| -|sources |`{index};{index}[;{index} ...]` or `all` (default)|Use location with given index as source. | -|destinations|`{index};{index}[;{index} ...]` or `all` (default)|Use location with given index as destination.| +|Option |Values |Description | +|-------------|---------------------------------------------------|---------------------------------------------| +|sources |`{index};{index}[;{index} ...]` or `all` (default) |Use location with given index as source. | +|destinations |`{index};{index}[;{index} ...]` or `all` (default) |Use location with given index as destination.| +|output_fields|`{durations|distances}[;{durations|distances} ...]`|Matrix fields to output in the reponse. Defaults to `durations` is missing. | Unlike other array encoded options, the length of `sources` and `destinations` can be **smaller or equal** to number of input locations; @@ -248,6 +249,8 @@ curl 'http://router.project-osrm.org/table/v1/driving/polyline(egs_Iq_aqAppHzbHu - `code` if the request was successful `Ok` otherwise see the service dependent and general status codes. - `durations` array of arrays that stores the matrix in row-major order. `durations[i][j]` gives the travel time from the i-th waypoint to the j-th waypoint. Values are given in seconds. +- `distances` array of arrays that stores the matrix in row-major order. `distances[i][j]` gives the distance from + the i-th waypoint to the j-th waypoint. Values are given in meters. - `sources` array of `Waypoint` objects describing all sources in order - `destinations` array of `Waypoint` objects describing all destinations in order diff --git a/include/contractor/contractor_graph.hpp b/include/contractor/contractor_graph.hpp index e50f29f970d..e5ca06a98ba 100644 --- a/include/contractor/contractor_graph.hpp +++ b/include/contractor/contractor_graph.hpp @@ -2,6 +2,7 @@ #define OSRM_CONTRACTOR_CONTRACTOR_GRAPH_HPP_ #include "util/dynamic_graph.hpp" +#include "util/payload.hpp" #include namespace osrm @@ -12,24 +13,24 @@ namespace contractor struct ContractorEdgeData { ContractorEdgeData() - : weight(0), duration(0), id(0), originalEdges(0), shortcut(0), forward(0), backward(0), + : weight(0), payload(), id(0), originalEdges(0), shortcut(0), forward(0), backward(0), is_original_via_node_ID(false) { } ContractorEdgeData(EdgeWeight weight, - EdgeWeight duration, + EdgePayload payload, unsigned original_edges, unsigned id, bool shortcut, bool forward, bool backward) - : weight(weight), duration(duration), id(id), + : weight(weight), payload(payload), id(id), originalEdges(std::min((1u << 28) - 1u, original_edges)), shortcut(shortcut), forward(forward), backward(backward), is_original_via_node_ID(false) { } EdgeWeight weight; - EdgeWeight duration; + EdgePayload payload; unsigned id; unsigned originalEdges : 28; bool shortcut : 1; diff --git a/include/contractor/graph_contractor.hpp b/include/contractor/graph_contractor.hpp index f2a2b12e0cf..457ca551384 100644 --- a/include/contractor/graph_contractor.hpp +++ b/include/contractor/graph_contractor.hpp @@ -134,7 +134,7 @@ class GraphContractor BOOST_ASSERT_MSG(SPECIAL_NODEID != new_edge.source, "Source id invalid"); BOOST_ASSERT_MSG(SPECIAL_NODEID != new_edge.target, "Target id invalid"); new_edge.data.weight = data.weight; - new_edge.data.duration = data.duration; + new_edge.data.payload = data.payload; new_edge.data.shortcut = data.shortcut; if (!data.is_original_via_node_ID && !orig_node_id_from_new_node_id_map.empty()) { @@ -244,7 +244,7 @@ class GraphContractor inserted_edges.emplace_back(source, target, path_weight, - in_data.duration + out_data.duration, + in_data.payload + out_data.payload, out_data.originalEdges + in_data.originalEdges, node, @@ -255,7 +255,7 @@ class GraphContractor inserted_edges.emplace_back(target, source, path_weight, - in_data.duration + out_data.duration, + in_data.payload + out_data.payload, out_data.originalEdges + in_data.originalEdges, node, @@ -316,7 +316,7 @@ class GraphContractor inserted_edges.emplace_back(source, target, path_weight, - in_data.duration + out_data.duration, + in_data.payload + out_data.payload, out_data.originalEdges + in_data.originalEdges, node, SHORTCUT_ARC, @@ -326,7 +326,7 @@ class GraphContractor inserted_edges.emplace_back(target, source, path_weight, - in_data.duration + out_data.duration, + in_data.payload + out_data.payload, out_data.originalEdges + in_data.originalEdges, node, SHORTCUT_ARC, diff --git a/include/contractor/graph_contractor_adaptors.hpp b/include/contractor/graph_contractor_adaptors.hpp index 969e78c85ca..87d221fb2ca 100644 --- a/include/contractor/graph_contractor_adaptors.hpp +++ b/include/contractor/graph_contractor_adaptors.hpp @@ -33,7 +33,7 @@ std::vector adaptToContractorInput(InputEdgeContainer input_edge edges.emplace_back(input_edge.source, input_edge.target, std::max(input_edge.data.weight, 1), - input_edge.data.duration, + input_edge.data.payload, 1, input_edge.data.edge_id, false, @@ -43,7 +43,7 @@ std::vector adaptToContractorInput(InputEdgeContainer input_edge edges.emplace_back(input_edge.target, input_edge.source, std::max(input_edge.data.weight, 1), - input_edge.data.duration, + input_edge.data.payload, 1, input_edge.data.edge_id, false, diff --git a/include/contractor/query_edge.hpp b/include/contractor/query_edge.hpp index f34d0575cbd..cfb495fe794 100644 --- a/include/contractor/query_edge.hpp +++ b/include/contractor/query_edge.hpp @@ -2,6 +2,7 @@ #define QUERYEDGE_HPP #include "util/typedefs.hpp" +#include "util/payload.hpp" #include @@ -17,28 +18,28 @@ struct QueryEdge struct EdgeData { explicit EdgeData() - : id(0), shortcut(false), weight(0), duration(0), forward(false), backward(false) + : id(0), shortcut(false), weight(0), forward(false), backward(false), payload() { } template EdgeData(const OtherT &other) { - weight = other.weight; - duration = other.duration; + weight = other.weight; shortcut = other.shortcut; id = other.id; forward = other.forward; backward = other.backward; + payload = other.payload; } // this ID is either the middle node of the shortcut, or the ID of the edge based node (node // based edge) storing the appropriate data. If `shortcut` is set to true, we get the middle // node. Otherwise we see the edge based node to access node data. NodeID id : 31; bool shortcut : 1; - EdgeWeight weight; - EdgeWeight duration : 30; + EdgeWeight weight : 30; std::uint32_t forward : 1; std::uint32_t backward : 1; + EdgePayload payload; } data; QueryEdge() : source(SPECIAL_NODEID), target(SPECIAL_NODEID) {} @@ -56,9 +57,10 @@ struct QueryEdge bool operator==(const QueryEdge &right) const { return (source == right.source && target == right.target && - data.weight == right.data.weight && data.duration == right.data.duration && - data.shortcut == right.data.shortcut && data.forward == right.data.forward && - data.backward == right.data.backward && data.id == right.data.id); + data.weight == right.data.weight && data.shortcut == right.data.shortcut && + data.forward == right.data.forward && data.backward == right.data.backward && + data.payload == right.data.payload && + data.id == right.data.id); } }; } diff --git a/include/engine/api/table_api.hpp b/include/engine/api/table_api.hpp index e4932feea58..10670a3dc48 100644 --- a/include/engine/api/table_api.hpp +++ b/include/engine/api/table_api.hpp @@ -4,6 +4,7 @@ #include "engine/api/base_api.hpp" #include "engine/api/json_factory.hpp" #include "engine/api/table_parameters.hpp" +#include "engine/api/table_payload.hpp" #include "engine/datafacade/datafacade_base.hpp" @@ -36,9 +37,11 @@ class TableAPI final : public BaseAPI { } - virtual void MakeResponse(const std::vector &durations, + virtual void MakeResponse(const std::vector &entries, const std::vector &phantoms, - util::json::Object &response) const + util::json::Object &response, + const std::vector & output_fields + ) const { auto number_of_sources = parameters.sources.size(); auto number_of_destinations = parameters.destinations.size(); @@ -64,9 +67,13 @@ class TableAPI final : public BaseAPI { response.values["destinations"] = MakeWaypoints(phantoms, parameters.destinations); } + + for (auto &component : output_fields.size() == 0 ? DEFAULT_FIELDS : output_fields) + { + response.values[TableOutputFieldName[component]] = + MakeTable(entries, number_of_sources, number_of_destinations, get_encoder(component)); + } - response.values["durations"] = - MakeTable(durations, number_of_sources, number_of_destinations); response.values["code"] = "Ok"; } @@ -98,9 +105,10 @@ class TableAPI final : public BaseAPI return json_waypoints; } - virtual util::json::Array MakeTable(const std::vector &values, + virtual util::json::Array MakeTable(const std::vector &values, std::size_t number_of_rows, - std::size_t number_of_columns) const + std::size_t number_of_columns, + PAYLOAD_ENCODER encoder) const { util::json::Array json_table; for (const auto row : util::irange(0UL, number_of_rows)) @@ -112,21 +120,19 @@ class TableAPI final : public BaseAPI std::transform(row_begin_iterator, row_end_iterator, json_row.values.begin(), - [](const EdgeWeight duration) { - if (duration == MAXIMAL_EDGE_DURATION) - { - return util::json::Value(util::json::Null()); - } - return util::json::Value(util::json::Number(duration / 10.)); - }); + encoder); json_table.values.push_back(std::move(json_row)); } return json_table; } const TableParameters ¶meters; + + static const std::vector DEFAULT_FIELDS; }; +const std::vector TableAPI::DEFAULT_FIELDS = std::vector(1, DURATION); + } // ns api } // ns engine } // ns osrm diff --git a/include/engine/api/table_parameters.hpp b/include/engine/api/table_parameters.hpp index 78f17b1e168..b0b6022563f 100644 --- a/include/engine/api/table_parameters.hpp +++ b/include/engine/api/table_parameters.hpp @@ -42,6 +42,16 @@ namespace engine { namespace api { + +enum TableOutputField { + DURATION, + DISTANCE +}; + +const std::string TableOutputFieldName[] = { + "durations", + "distances" +}; /** * Parameters specific to the OSRM Table service. @@ -51,6 +61,7 @@ namespace api * use all coordinates as sources * - destinations: indices into coordinates indicating destinations for the Table service, no * destinations means use all coordinates as destinations + * - output_fields: fields that should get returned (durations, distances) * * \see OSRM, Coordinate, Hint, Bearing, RouteParame, RouteParameters, TableParameters, * NearestParameters, TripParameters, MatchParameters and TileParameters @@ -59,14 +70,16 @@ struct TableParameters : public BaseParameters { std::vector sources; std::vector destinations; + std::vector output_fields; TableParameters() = default; template TableParameters(std::vector sources_, std::vector destinations_, + std::vector output_fields, Args... args_) : BaseParameters{std::forward(args_)...}, sources{std::move(sources_)}, - destinations{std::move(destinations_)} + destinations{std::move(destinations_)}, output_fields(output_fields) { } diff --git a/include/engine/api/table_payload.hpp b/include/engine/api/table_payload.hpp new file mode 100644 index 00000000000..afc727ff5d7 --- /dev/null +++ b/include/engine/api/table_payload.hpp @@ -0,0 +1,84 @@ +#ifndef ENGINE_TABLE_PAYLOAD_HPP +#define ENGINE_TABLE_PAYLOAD_HPP + +#include "engine/api/base_api.hpp" +#include "engine/api/json_factory.hpp" +#include "engine/api/table_parameters.hpp" + +#include "engine/datafacade/datafacade_base.hpp" + +#include "engine/internal_route_result.hpp" + +#include "util/integer_range.hpp" + +#include + +namespace osrm +{ +namespace engine +{ +namespace api +{ + +template +using PAYLOAD_ENCODER = util::json::Value (*)(const PayloadType & entry); + +template +inline util::json::Value default_duration_encoder(const PayloadType & entry) +{ + if (entry.duration == MAXIMAL_EDGE_DURATION) return util::json::Value(util::json::Null()); + return util::json::Value(util::json::Number(entry.duration / 10.)); +} + +template +inline util::json::Value default_distance_encoder(const PayloadType & entry) +{ + if (entry.distance == MAXIMAL_EDGE_DISTANCE) return util::json::Value(util::json::Null()); + return util::json::Value(util::json::Number(entry.distance)); +} + +template +inline util::json::Value empty_encoder(const PayloadType & entry) +{ + return util::json::Value(util::json::Null()); +} + +template +inline PAYLOAD_ENCODER get_encoder(TableOutputField component) +{ + throw util::exception("Internal Error: Encoders missing for used payload type."); +} + +template<> +inline PAYLOAD_ENCODER get_encoder(TableOutputField component) +{ + switch(component) + { + case DURATION: + return default_duration_encoder; + case DISTANCE: + return default_distance_encoder; + default: + throw util::exception("Internal Error: Encountered unknown output component type: " + component); + } +} + +template<> +inline PAYLOAD_ENCODER get_encoder(TableOutputField component) +{ + switch(component) + { + case DURATION: + return default_duration_encoder; + case DISTANCE: + throw util::exception("Internal Error: Requested distance, but osrm is not configured to provide distances.");//TODO: Graceful error handling + default: + throw util::exception("Internal Error: Encountered unknown output component type: " + component); + } +} + +} // ns api +} // ns engine +} // ns osrm + +#endif diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index 5bcb334735a..62d11178b25 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -373,6 +373,10 @@ template class GeospatialQuery EdgeWeight reverse_weight_offset = 0, reverse_weight = 0; EdgeWeight forward_duration_offset = 0, forward_duration = 0; EdgeWeight reverse_duration_offset = 0, reverse_duration = 0; + EdgeDistance forward_distance = EdgeDistance(); + EdgeDistance reverse_distance = EdgeDistance(); + EdgeDistance forward_distance_offset = EdgeDistance(); + EdgeDistance reverse_distance_offset = EdgeDistance(); const std::vector forward_weight_vector = datafacade.GetUncompressedForwardWeights(data.packed_geometry_id); @@ -382,38 +386,54 @@ template class GeospatialQuery datafacade.GetUncompressedForwardDurations(data.packed_geometry_id); const std::vector reverse_duration_vector = datafacade.GetUncompressedReverseDurations(data.packed_geometry_id); + const std::vector forward_node_vector = + datafacade.GetUncompressedForwardGeometry(data.packed_geometry_id); + const std::vector reverse_node_vector = + datafacade.GetUncompressedReverseGeometry(data.packed_geometry_id); for (std::size_t i = 0; i < data.fwd_segment_position; i++) { forward_weight_offset += forward_weight_vector[i]; forward_duration_offset += forward_duration_vector[i]; + + auto c1 = coordinates[forward_node_vector[i]]; + auto c2 = coordinates[forward_node_vector[i+1]]; + forward_distance_offset += util::coordinate_calculation::greatCircleDistance(c1, c2); } forward_weight = forward_weight_vector[data.fwd_segment_position]; forward_duration = forward_duration_vector[data.fwd_segment_position]; + forward_distance = util::coordinate_calculation::greatCircleDistance(coordinates[forward_node_vector[data.fwd_segment_position]], + coordinates[forward_node_vector[data.fwd_segment_position + 1]]); BOOST_ASSERT(data.fwd_segment_position < reverse_weight_vector.size()); - for (std::size_t i = 0; i < reverse_weight_vector.size() - data.fwd_segment_position - 1; - i++) + const std::size_t reverse_segment_position = reverse_weight_vector.size() - data.fwd_segment_position - 1; + for (std::size_t i = 0; i < reverse_segment_position; i++) { reverse_weight_offset += reverse_weight_vector[i]; reverse_duration_offset += reverse_duration_vector[i]; + + auto c1 = coordinates[reverse_node_vector[i]]; + auto c2 = coordinates[reverse_node_vector[i+1]]; + reverse_distance_offset += util::coordinate_calculation::greatCircleDistance(c1, c2); } - reverse_weight = - reverse_weight_vector[reverse_weight_vector.size() - data.fwd_segment_position - 1]; - reverse_duration = - reverse_duration_vector[reverse_duration_vector.size() - data.fwd_segment_position - 1]; + reverse_weight = reverse_weight_vector[reverse_segment_position]; + reverse_duration = reverse_duration_vector[reverse_segment_position]; + reverse_distance = util::coordinate_calculation::greatCircleDistance(coordinates[reverse_node_vector[reverse_segment_position]], + coordinates[reverse_node_vector[reverse_segment_position + 1]]); ratio = std::min(1.0, std::max(0.0, ratio)); if (data.forward_segment_id.id != SPECIAL_SEGMENTID) { forward_weight = static_cast(forward_weight * ratio); forward_duration = static_cast(forward_duration * ratio); + forward_distance = static_cast(forward_distance * ratio); } if (data.reverse_segment_id.id != SPECIAL_SEGMENTID) { reverse_weight -= static_cast(reverse_weight * ratio); reverse_duration -= static_cast(reverse_duration * ratio); + reverse_distance -= static_cast(reverse_distance * ratio); } auto transformed = PhantomNodeWithDistance{PhantomNode{data, @@ -423,8 +443,10 @@ template class GeospatialQuery reverse_weight_offset, forward_duration, reverse_duration, - forward_duration_offset, - reverse_duration_offset, + MAKE_PAYLOAD(forward_duration_offset + forward_duration, + forward_distance_offset + forward_distance), + MAKE_PAYLOAD(reverse_duration_offset + reverse_duration, + reverse_distance_offset + reverse_distance), point_on_segment, input_coordinate}, current_perpendicular_distance}; diff --git a/include/engine/hint.hpp b/include/engine/hint.hpp index 12757e5f991..a65cb6496a0 100644 --- a/include/engine/hint.hpp +++ b/include/engine/hint.hpp @@ -63,8 +63,8 @@ struct Hint friend std::ostream &operator<<(std::ostream &, const Hint &); }; -static_assert(sizeof(Hint) == 72 + 4, "Hint is bigger than expected"); -constexpr std::size_t ENCODED_HINT_SIZE = 104; +static_assert(sizeof(Hint) == sizeof(PhantomNode) + 4, "Hint is bigger than expected"); +constexpr std::size_t ENCODED_HINT_SIZE = (std::size_t) std::ceil(sizeof(Hint) / 3.) * 4; static_assert(ENCODED_HINT_SIZE / 4 * 3 >= sizeof(Hint), "ENCODED_HINT_SIZE does not match size of Hint"); } diff --git a/include/engine/phantom_node.hpp b/include/engine/phantom_node.hpp index fa32cfa49d0..cedaaea0b03 100644 --- a/include/engine/phantom_node.hpp +++ b/include/engine/phantom_node.hpp @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "extractor/travel_mode.hpp" #include "util/typedefs.hpp" +#include "util/payload.hpp" #include "util/coordinate.hpp" @@ -55,8 +56,8 @@ struct PhantomNode EdgeWeight reverse_weight_offset, EdgeWeight forward_duration, EdgeWeight reverse_duration, - EdgeWeight forward_duration_offset, - EdgeWeight reverse_duration_offset, + EdgePayload forward_payload, + EdgePayload reverse_payload, unsigned packed_geometry_id_, bool is_tiny_component, unsigned component_id, @@ -69,8 +70,8 @@ struct PhantomNode name_id(name_id), forward_weight(forward_weight), reverse_weight(reverse_weight), forward_weight_offset(forward_weight_offset), reverse_weight_offset(reverse_weight_offset), forward_duration(forward_duration), - reverse_duration(reverse_duration), forward_duration_offset(forward_duration_offset), - reverse_duration_offset(reverse_duration_offset), packed_geometry_id(packed_geometry_id_), + reverse_duration(reverse_duration), forward_payload(forward_payload), + reverse_payload(reverse_payload), packed_geometry_id(packed_geometry_id_), component{component_id, is_tiny_component}, location(std::move(location)), input_location(std::move(input_location)), fwd_segment_position(fwd_segment_position), forward_travel_mode(forward_travel_mode), backward_travel_mode(backward_travel_mode) @@ -82,8 +83,8 @@ struct PhantomNode reverse_segment_id{SPECIAL_SEGMENTID, false}, name_id(std::numeric_limits::max()), forward_weight(INVALID_EDGE_WEIGHT), reverse_weight(INVALID_EDGE_WEIGHT), forward_weight_offset(0), reverse_weight_offset(0), - forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION), - forward_duration_offset(0), reverse_duration_offset(0), + forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION), + forward_payload(INVALID_PAYLOAD), reverse_payload(INVALID_PAYLOAD), packed_geometry_id(SPECIAL_GEOMETRYID), component{INVALID_COMPONENTID, false}, fwd_segment_position(0), forward_travel_mode(TRAVEL_MODE_INACCESSIBLE), backward_travel_mode(TRAVEL_MODE_INACCESSIBLE) @@ -101,17 +102,15 @@ struct PhantomNode BOOST_ASSERT(reverse_segment_id.enabled); return reverse_weight_offset + reverse_weight; } - - EdgeWeight GetForwardDuration() const + + EdgePayload GetForwardPayload() const { - BOOST_ASSERT(forward_segment_id.enabled); - return forward_duration + forward_duration_offset; + return forward_payload; } - - EdgeWeight GetReverseDuration() const + + EdgePayload GetReversePayload() const { - BOOST_ASSERT(reverse_segment_id.enabled); - return reverse_duration + reverse_duration_offset; + return reverse_payload; } bool IsBidirected() const { return forward_segment_id.enabled && reverse_segment_id.enabled; } @@ -144,17 +143,17 @@ struct PhantomNode EdgeWeight reverse_weight_offset, EdgeWeight forward_duration, EdgeWeight reverse_duration, - EdgeWeight forward_duration_offset, - EdgeWeight reverse_duration_offset, + EdgePayload forward_payload, + EdgePayload reverse_payload, const util::Coordinate location, const util::Coordinate input_location) : forward_segment_id{other.forward_segment_id}, reverse_segment_id{other.reverse_segment_id}, name_id{other.name_id}, forward_weight{forward_weight}, reverse_weight{reverse_weight}, - forward_weight_offset{forward_weight_offset}, - reverse_weight_offset{reverse_weight_offset}, forward_duration{forward_duration}, - reverse_duration{reverse_duration}, forward_duration_offset{forward_duration_offset}, - reverse_duration_offset{reverse_duration_offset}, + forward_weight_offset{forward_weight_offset}, reverse_weight_offset{reverse_weight_offset}, + forward_duration{forward_duration}, + reverse_duration{reverse_duration}, + forward_payload{forward_payload}, reverse_payload{reverse_payload}, packed_geometry_id{other.packed_geometry_id}, component{other.component.id, other.component.is_tiny}, location{location}, input_location{input_location}, fwd_segment_position{other.fwd_segment_position}, @@ -169,11 +168,11 @@ struct PhantomNode EdgeWeight forward_weight; EdgeWeight reverse_weight; EdgeWeight forward_weight_offset; // TODO: try to remove -> requires path unpacking changes - EdgeWeight reverse_weight_offset; // TODO: try to remove -> requires path unpacking changes - EdgeWeight forward_duration; - EdgeWeight reverse_duration; - EdgeWeight forward_duration_offset; // TODO: try to remove -> requires path unpacking changes - EdgeWeight reverse_duration_offset; // TODO: try to remove -> requires path unpacking changes + EdgeWeight reverse_weight_offset; // TODO: try to remove -> requires path unpacking changes + EdgeWeight forward_duration; // TODO: try to remove -> requires path unpacking changes + EdgeWeight reverse_duration; // TODO: try to remove -> requires path unpacking changes + EdgePayload forward_payload; + EdgePayload reverse_payload; unsigned packed_geometry_id; struct ComponentType { @@ -191,7 +190,7 @@ struct PhantomNode extractor::TravelMode backward_travel_mode; }; -static_assert(sizeof(PhantomNode) == 72, "PhantomNode has more padding then expected"); +static_assert(sizeof(PhantomNode) == 64 + 2 * sizeof(EdgePayload), "PhantomNode has more padding then expected"); using PhantomNodePair = std::pair; @@ -225,8 +224,8 @@ inline std::ostream &operator<<(std::ostream &out, const PhantomNode &pn) << "rev-o: " << pn.reverse_weight_offset << ", " << "fwd-d: " << pn.forward_duration << ", " << "rev-d: " << pn.reverse_duration << ", " - << "fwd-do: " << pn.forward_duration_offset << ", " - << "rev-do: " << pn.reverse_duration_offset << ", " + << "fwd-do: " << pn.forward_payload.duration - pn.forward_duration << ", " + << "rev-do: " << pn.reverse_payload.duration - pn.forward_duration << ", " << "geom: " << pn.packed_geometry_id << ", " << "comp: " << pn.component.is_tiny << " / " << pn.component.id << ", " << "pos: " << pn.fwd_segment_position << ", " diff --git a/include/engine/routing_algorithms.hpp b/include/engine/routing_algorithms.hpp index 5b9fd553ed4..02d3e235041 100644 --- a/include/engine/routing_algorithms.hpp +++ b/include/engine/routing_algorithms.hpp @@ -29,10 +29,15 @@ class RoutingAlgorithmsInterface virtual InternalRouteResult DirectShortestPathSearch(const PhantomNodes &phantom_node_pair) const = 0; - virtual std::vector + virtual std::vector ManyToManySearch(const std::vector &phantom_nodes, const std::vector &source_indices, const std::vector &target_indices) const = 0; + + virtual std::vector + ManyToManyDurations(const std::vector &phantom_nodes, + const std::vector &source_indices, + const std::vector &target_indices) const = 0; virtual routing_algorithms::SubMatchingList MapMatching(const routing_algorithms::CandidateLists &candidates_list, @@ -74,10 +79,15 @@ template class RoutingAlgorithms final : public RoutingAlg InternalRouteResult DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const final override; - std::vector + std::vector ManyToManySearch(const std::vector &phantom_nodes, const std::vector &source_indices, const std::vector &target_indices) const final override; + + std::vector + ManyToManyDurations(const std::vector &phantom_nodes, + const std::vector &source_indices, + const std::vector &target_indices) const final override; routing_algorithms::SubMatchingList MapMatching( const routing_algorithms::CandidateLists &candidates_list, @@ -149,7 +159,7 @@ RoutingAlgorithms::DirectShortestPathSearch(const PhantomNodes &phan } template -std::vector RoutingAlgorithms::ManyToManySearch( +std::vector RoutingAlgorithms::ManyToManySearch( const std::vector &phantom_nodes, const std::vector &source_indices, const std::vector &target_indices) const @@ -158,6 +168,22 @@ std::vector RoutingAlgorithms::ManyToManySearch( heaps, facade, phantom_nodes, source_indices, target_indices); } +template +std::vector RoutingAlgorithms::ManyToManyDurations( + const std::vector &phantom_nodes, + const std::vector &source_indices, + const std::vector &target_indices) const +{ + std::vector table = routing_algorithms::manyToManySearch( + heaps, facade, phantom_nodes, source_indices, target_indices); + std::vector durations; + std::transform(table.begin(), + table.end(), + std::back_inserter(durations), + [](const RoutingPayload& e) { return e.duration; }); + return durations; +} + template inline routing_algorithms::SubMatchingList RoutingAlgorithms::MapMatching( const routing_algorithms::CandidateLists &candidates_list, @@ -201,7 +227,7 @@ InternalRouteResult inline RoutingAlgorithms::DirectShortestPath } template <> -inline std::vector +inline std::vector RoutingAlgorithms::ManyToManySearch(const std::vector &, const std::vector &, const std::vector &) const @@ -209,6 +235,15 @@ RoutingAlgorithms::ManyToManySearch(const std::vector +inline std::vector +RoutingAlgorithms::ManyToManyDurations(const std::vector &, + const std::vector &, + const std::vector &) const +{ + throw util::exception("ManyToManySearch is not implemented"); +} + template <> inline routing_algorithms::SubMatchingList RoutingAlgorithms::MapMatching(const routing_algorithms::CandidateLists &, diff --git a/include/engine/routing_algorithms/many_to_many.hpp b/include/engine/routing_algorithms/many_to_many.hpp index c6c1dbcedf4..d4b0617ff77 100644 --- a/include/engine/routing_algorithms/many_to_many.hpp +++ b/include/engine/routing_algorithms/many_to_many.hpp @@ -17,7 +17,7 @@ namespace engine namespace routing_algorithms { -std::vector +std::vector manyToManySearch(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes, diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index e1b0a630e09..2ab9c0dbad1 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -11,6 +11,7 @@ #include "util/coordinate_calculation.hpp" #include "util/guidance/turn_bearing.hpp" #include "util/typedefs.hpp" +#include "util/payload.hpp" #include @@ -201,12 +202,12 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade(facade, node, weight, forward_heap); } -template +inline EdgeWeight getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade &facade, NodeID node) { - EdgeWeight loop_weight = UseDuration ? MAXIMAL_EDGE_DURATION : INVALID_EDGE_WEIGHT; + EdgeWeight loop_weight = INVALID_EDGE_WEIGHT; for (auto edge : facade.GetAdjacentEdgeRange(node)) { const auto &data = facade.GetEdgeData(edge); @@ -215,7 +216,7 @@ getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade &facade, + NodeID node) +{ + EdgeWeight loop_weight = INVALID_EDGE_WEIGHT; + EdgePayload result = INVALID_PAYLOAD; + for (auto edge : facade.GetAdjacentEdgeRange(node)) + { + const auto &data = facade.GetEdgeData(edge); + if (data.forward) + { + const NodeID to = facade.GetTarget(edge); + if (to == node && data.weight < loop_weight) + { + loop_weight = data.weight; + result = data.payload; + } + } + } + return result; +} + /** * Given a sequence of connected `NodeID`s in the CH graph, performs a depth-first unpacking of * the shortcut diff --git a/include/engine/search_engine_data.hpp b/include/engine/search_engine_data.hpp index ba57487b3cc..1a557888187 100644 --- a/include/engine/search_engine_data.hpp +++ b/include/engine/search_engine_data.hpp @@ -5,6 +5,7 @@ #include "util/binary_heap.hpp" #include "util/typedefs.hpp" +#include "util/payload.hpp" namespace osrm { @@ -19,8 +20,8 @@ struct HeapData struct ManyToManyHeapData : HeapData { - EdgeWeight duration; - ManyToManyHeapData(NodeID p, EdgeWeight duration) : HeapData(p), duration(duration) {} + RoutingPayload payload; + ManyToManyHeapData(NodeID p, RoutingPayload payload) : HeapData(p), payload(payload) {} }; struct SearchEngineData diff --git a/include/extractor/compressed_edge_container.hpp b/include/extractor/compressed_edge_container.hpp index 72c93f9dcd8..3effc726981 100644 --- a/include/extractor/compressed_edge_container.hpp +++ b/include/extractor/compressed_edge_container.hpp @@ -2,6 +2,7 @@ #define GEOMETRY_COMPRESSOR_HPP_ #include "util/typedefs.hpp" +#include "util/payload.hpp" #include @@ -21,7 +22,7 @@ class CompressedEdgeContainer public: NodeID node_id; // refers to an internal node-based-node EdgeWeight weight; // the weight of the edge leading to this node - EdgeWeight duration; // the duration of the edge leading to this node + UncompressedEdgePayload payload; // the payload of the edge leading to this node }; using OnewayEdgeBucket = std::vector; @@ -33,13 +34,13 @@ class CompressedEdgeContainer const NodeID target_node, const EdgeWeight weight1, const EdgeWeight weight2, - const EdgeWeight duration1, - const EdgeWeight duration2); + const UncompressedEdgePayload & payload1, + const UncompressedEdgePayload & payload2); void AddUncompressedEdge(const EdgeID edge_id, const NodeID target_node, const EdgeWeight weight, - const EdgeWeight duration); + const UncompressedEdgePayload & payload); void InitializeBothwayVector(); unsigned ZipEdges(const unsigned f_edge_pos, const unsigned r_edge_pos); diff --git a/include/extractor/edge_based_edge.hpp b/include/extractor/edge_based_edge.hpp index cbc10308d3b..14ea5728be3 100644 --- a/include/extractor/edge_based_edge.hpp +++ b/include/extractor/edge_based_edge.hpp @@ -3,6 +3,7 @@ #include "extractor/travel_mode.hpp" #include "util/typedefs.hpp" +#include "util/payload.hpp" #include namespace osrm @@ -21,7 +22,7 @@ struct EdgeBasedEdge const NodeID target, const NodeID edge_id, const EdgeWeight weight, - const EdgeWeight duration, + const EdgePayload & payload, const bool forward, const bool backward); @@ -32,28 +33,28 @@ struct EdgeBasedEdge struct EdgeData { - EdgeData() : edge_id(0), weight(0), duration(0), forward(false), backward(false) {} + EdgeData() : edge_id(0), weight(0), forward(false), backward(false), payload() {} EdgeData(const NodeID edge_id, const EdgeWeight weight, - const EdgeWeight duration, + const EdgePayload & payload, const bool forward, const bool backward) - : edge_id(edge_id), weight(weight), duration(duration), forward(forward), - backward(backward) + : edge_id(edge_id), weight(weight), forward(forward), + backward(backward), payload(payload) { } NodeID edge_id; - EdgeWeight weight; - EdgeWeight duration : 30; + EdgeWeight weight : 30; std::uint32_t forward : 1; std::uint32_t backward : 1; + EdgePayload payload; auto is_unidirectional() const { return !forward || !backward; } } data; }; -static_assert(sizeof(extractor::EdgeBasedEdge) == 20, +static_assert(sizeof(extractor::EdgeBasedEdge) == 16 + sizeof(EdgePayload), "Size of extractor::EdgeBasedEdge type is " "bigger than expected. This will influence " "memory consumption."); @@ -66,10 +67,10 @@ inline EdgeBasedEdge::EdgeBasedEdge(const NodeID source, const NodeID target, const NodeID edge_id, const EdgeWeight weight, - const EdgeWeight duration, + const EdgePayload & payload, const bool forward, const bool backward) - : source(source), target(target), data{edge_id, weight, duration, forward, backward} + : source(source), target(target), data{edge_id, weight, payload, forward, backward} { } diff --git a/include/extractor/internal_extractor_edge.hpp b/include/extractor/internal_extractor_edge.hpp index ab267e70ef7..c5095e0af49 100644 --- a/include/extractor/internal_extractor_edge.hpp +++ b/include/extractor/internal_extractor_edge.hpp @@ -64,7 +64,7 @@ struct InternalExtractorEdge MIN_OSM_NODEID, SPECIAL_NODEID, 0, - 0, + EdgePayload(), false, // forward false, // backward false, // roundabout @@ -99,7 +99,7 @@ struct InternalExtractorEdge target, name_id, 0, - 0, + EdgePayload(), forward, backward, roundabout, diff --git a/include/extractor/node_based_edge.hpp b/include/extractor/node_based_edge.hpp index 2715993a72e..1e0ff4b9ffe 100644 --- a/include/extractor/node_based_edge.hpp +++ b/include/extractor/node_based_edge.hpp @@ -3,6 +3,7 @@ #include "extractor/travel_mode.hpp" #include "util/typedefs.hpp" +#include "util/payload.hpp" #include "extractor/guidance/road_classification.hpp" @@ -19,7 +20,7 @@ struct NodeBasedEdge NodeID target, NodeID name_id, EdgeWeight weight, - EdgeWeight duration, + const EdgePayload & payload, bool forward, bool backward, bool roundabout, @@ -37,7 +38,7 @@ struct NodeBasedEdge NodeID target; // 32 4 NodeID name_id; // 32 4 EdgeWeight weight; // 32 4 - EdgeWeight duration; // 32 4 + EdgePayload payload; // std::uint8_t forward : 1; // 1 std::uint8_t backward : 1; // 1 std::uint8_t roundabout : 1; // 1 @@ -56,7 +57,7 @@ struct NodeBasedEdgeWithOSM : NodeBasedEdge OSMNodeID target, NodeID name_id, EdgeWeight weight, - EdgeWeight duration, + const EdgePayload & payload, bool forward, bool backward, bool roundabout, @@ -75,7 +76,7 @@ struct NodeBasedEdgeWithOSM : NodeBasedEdge // Impl. inline NodeBasedEdge::NodeBasedEdge() - : source(SPECIAL_NODEID), target(SPECIAL_NODEID), name_id(0), weight(0), duration(0), + : source(SPECIAL_NODEID), target(SPECIAL_NODEID), name_id(0), weight(0), payload(), forward(false), backward(false), roundabout(false), circular(false), startpoint(true), restricted(false), is_split(false), travel_mode(TRAVEL_MODE_INACCESSIBLE), lane_description_id(INVALID_LANE_DESCRIPTIONID) @@ -86,7 +87,7 @@ inline NodeBasedEdge::NodeBasedEdge(NodeID source, NodeID target, NodeID name_id, EdgeWeight weight, - EdgeWeight duration, + const EdgePayload & payload, bool forward, bool backward, bool roundabout, @@ -97,7 +98,7 @@ inline NodeBasedEdge::NodeBasedEdge(NodeID source, TravelMode travel_mode, const LaneDescriptionID lane_description_id, guidance::RoadClassification road_classification) - : source(source), target(target), name_id(name_id), weight(weight), duration(duration), + : source(source), target(target), name_id(name_id), weight(weight), payload(payload), forward(forward), backward(backward), roundabout(roundabout), circular(circular), startpoint(startpoint), restricted(restricted), is_split(is_split), travel_mode(travel_mode), lane_description_id(lane_description_id), road_classification(std::move(road_classification)) @@ -125,7 +126,7 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM(OSMNodeID source, OSMNodeID target, NodeID name_id, EdgeWeight weight, - EdgeWeight duration, + const EdgePayload & payload, bool forward, bool backward, bool roundabout, @@ -140,7 +141,7 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM(OSMNodeID source, SPECIAL_NODEID, name_id, weight, - duration, + payload, forward, backward, roundabout, @@ -155,7 +156,7 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM(OSMNodeID source, { } -static_assert(sizeof(extractor::NodeBasedEdge) == 28, +static_assert(sizeof(extractor::NodeBasedEdge) == 24 + sizeof(EdgePayload), "Size of extractor::NodeBasedEdge type is " "bigger than expected. This will influence " "memory consumption."); diff --git a/include/partition/edge_based_graph_reader.hpp b/include/partition/edge_based_graph_reader.hpp index 39f0afe73a5..dbee51e2f7a 100644 --- a/include/partition/edge_based_graph_reader.hpp +++ b/include/partition/edge_based_graph_reader.hpp @@ -51,7 +51,7 @@ splitBidirectionalEdges(const std::vector &edges) edge.target, edge.data.edge_id, std::max(edge.data.weight, 1), - edge.data.duration, + edge.data.payload, edge.data.forward, edge.data.backward); @@ -59,7 +59,7 @@ splitBidirectionalEdges(const std::vector &edges) edge.source, edge.data.edge_id, std::max(edge.data.weight, 1), - edge.data.duration, + edge.data.payload, edge.data.backward, edge.data.forward); } @@ -93,7 +93,7 @@ prepareEdgesForUsageInGraph(std::vector edges) forward_edge.target = reverse_edge.target = target; forward_edge.data.edge_id = reverse_edge.data.edge_id = edges[i].data.edge_id; forward_edge.data.weight = reverse_edge.data.weight = INVALID_EDGE_WEIGHT; - forward_edge.data.duration = reverse_edge.data.duration = MAXIMAL_EDGE_DURATION_INT_30; + forward_edge.data.payload = reverse_edge.data.payload = INVALID_PAYLOAD; forward_edge.data.forward = reverse_edge.data.backward = true; forward_edge.data.backward = reverse_edge.data.forward = false; @@ -102,15 +102,19 @@ prepareEdgesForUsageInGraph(std::vector edges) { if (edges[i].data.forward) { - forward_edge.data.weight = std::min(edges[i].data.weight, forward_edge.data.weight); - forward_edge.data.duration = - std::min(edges[i].data.duration, forward_edge.data.duration); + if (edges[i].data.weight < forward_edge.data.weight) + { + forward_edge.data.weight = edges[i].data.weight; + forward_edge.data.payload = edges[i].data.payload; + } } if (edges[i].data.backward) { - reverse_edge.data.weight = std::min(edges[i].data.weight, reverse_edge.data.weight); - reverse_edge.data.duration = - std::min(edges[i].data.duration, reverse_edge.data.duration); + if (edges[i].data.weight < reverse_edge.data.weight) + { + reverse_edge.data.weight = edges[i].data.weight; + reverse_edge.data.payload = edges[i].data.payload; + } } ++i; } diff --git a/include/server/api/table_parameter_grammar.hpp b/include/server/api/table_parameter_grammar.hpp index 5a97c8e3d40..068112566a1 100644 --- a/include/server/api/table_parameter_grammar.hpp +++ b/include/server/api/table_parameter_grammar.hpp @@ -48,7 +48,13 @@ struct TableParametersGrammar final : public BaseParametersGrammar -('?' > (table_rule(qi::_r1) | BaseGrammar::base_rule(qi::_r1)) % '&'); @@ -59,7 +65,9 @@ struct TableParametersGrammar final : public BaseParametersGrammar table_rule; qi::rule sources_rule; qi::rule destinations_rule; + qi::rule output_fields_rule; qi::rule size_t_; + qi::rule output_component; }; } } diff --git a/include/server/service/match_service.hpp b/include/server/service/match_service.hpp index 07a95e20f1a..617c96116bd 100644 --- a/include/server/service/match_service.hpp +++ b/include/server/service/match_service.hpp @@ -25,7 +25,7 @@ class MatchService final : public BaseService engine::Status RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; - unsigned GetVersion() final override { return 1; } + unsigned GetVersion() final override { return 2; } }; } } diff --git a/include/server/service/nearest_service.hpp b/include/server/service/nearest_service.hpp index ffbbaf84b56..c87fc7e4cca 100644 --- a/include/server/service/nearest_service.hpp +++ b/include/server/service/nearest_service.hpp @@ -25,7 +25,7 @@ class NearestService final : public BaseService engine::Status RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; - unsigned GetVersion() final override { return 1; } + unsigned GetVersion() final override { return 2; } }; } } diff --git a/include/server/service/route_service.hpp b/include/server/service/route_service.hpp index 3e9be1bf8ab..8b2c022e136 100644 --- a/include/server/service/route_service.hpp +++ b/include/server/service/route_service.hpp @@ -25,7 +25,7 @@ class RouteService final : public BaseService engine::Status RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; - unsigned GetVersion() final override { return 1; } + unsigned GetVersion() final override { return 2; } }; } } diff --git a/include/server/service/table_service.hpp b/include/server/service/table_service.hpp index ca32f4d8351..b8d2e3754d2 100644 --- a/include/server/service/table_service.hpp +++ b/include/server/service/table_service.hpp @@ -25,7 +25,7 @@ class TableService final : public BaseService engine::Status RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; - unsigned GetVersion() final override { return 1; } + unsigned GetVersion() final override { return 2; } }; } } diff --git a/include/server/service/tile_service.hpp b/include/server/service/tile_service.hpp index afa9a442c2a..1f765690a47 100644 --- a/include/server/service/tile_service.hpp +++ b/include/server/service/tile_service.hpp @@ -25,7 +25,7 @@ class TileService final : public BaseService engine::Status RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; - unsigned GetVersion() final override { return 1; } + unsigned GetVersion() final override { return 2; } }; } } diff --git a/include/server/service/trip_service.hpp b/include/server/service/trip_service.hpp index 7dd6fbfcb46..9f7ca18652c 100644 --- a/include/server/service/trip_service.hpp +++ b/include/server/service/trip_service.hpp @@ -25,7 +25,7 @@ class TripService final : public BaseService engine::Status RunQuery(std::size_t prefix_length, std::string &query, ResultT &result) final override; - unsigned GetVersion() final override { return 1; } + unsigned GetVersion() final override { return 2; } }; } } diff --git a/include/util/node_based_graph.hpp b/include/util/node_based_graph.hpp index 9a53df148da..65dfa061adb 100644 --- a/include/util/node_based_graph.hpp +++ b/include/util/node_based_graph.hpp @@ -18,7 +18,7 @@ namespace util struct NodeBasedEdgeData { NodeBasedEdgeData() - : weight(INVALID_EDGE_WEIGHT), duration(INVALID_EDGE_WEIGHT), edge_id(SPECIAL_NODEID), + : weight(INVALID_EDGE_WEIGHT), payload(INVALID_PAYLOAD), edge_id(SPECIAL_NODEID), name_id(std::numeric_limits::max()), reversed(false), roundabout(false), circular(false), travel_mode(TRAVEL_MODE_INACCESSIBLE), lane_description_id(INVALID_LANE_DESCRIPTIONID) @@ -26,7 +26,7 @@ struct NodeBasedEdgeData } NodeBasedEdgeData(EdgeWeight weight, - EdgeWeight duration, + const EdgePayload & payload, unsigned edge_id, unsigned name_id, bool reversed, @@ -36,14 +36,14 @@ struct NodeBasedEdgeData bool restricted, extractor::TravelMode travel_mode, const LaneDescriptionID lane_description_id) - : weight(weight), duration(duration), edge_id(edge_id), name_id(name_id), + : weight(weight), payload(payload), edge_id(edge_id), name_id(name_id), reversed(reversed), roundabout(roundabout), circular(circular), startpoint(startpoint), restricted(restricted), travel_mode(travel_mode), lane_description_id(lane_description_id) { } EdgeWeight weight; - EdgeWeight duration; + EdgePayload payload; unsigned edge_id; unsigned name_id; bool reversed : 1; @@ -84,7 +84,7 @@ NodeBasedDynamicGraphFromEdges(NodeID number_of_nodes, [](NodeBasedDynamicGraph::InputEdge &output_edge, const extractor::NodeBasedEdge &input_edge) { output_edge.data.weight = input_edge.weight; - output_edge.data.duration = input_edge.duration; + output_edge.data.payload = input_edge.payload; output_edge.data.roundabout = input_edge.roundabout; output_edge.data.circular = input_edge.circular; output_edge.data.name_id = input_edge.name_id; @@ -95,7 +95,7 @@ NodeBasedDynamicGraphFromEdges(NodeID number_of_nodes, output_edge.data.lane_description_id = input_edge.lane_description_id; BOOST_ASSERT(output_edge.data.weight > 0); - BOOST_ASSERT(output_edge.data.duration > 0); + BOOST_ASSERT(output_edge.data.payload.duration > 0); }); tbb::parallel_sort(edges_list.begin(), edges_list.end()); diff --git a/include/util/payload.hpp b/include/util/payload.hpp new file mode 100644 index 00000000000..797689c637f --- /dev/null +++ b/include/util/payload.hpp @@ -0,0 +1,138 @@ +/* + +Copyright (c) 2016, Project OSRM contributors +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef PAYLOAD_H +#define PAYLOAD_H + +#include "util/typedefs.hpp" + +struct DurationDistancePayload +{ + EdgeWeight duration; + EdgeDistance distance; + + DurationDistancePayload(const EdgeWeight & duration, const EdgeDistance & distance) : duration(duration), distance(distance) {} + DurationDistancePayload() : duration(0), distance(0) {} + + bool operator==(const DurationDistancePayload &right) const + { + return duration == right.duration && distance == right.distance; + } + + bool operator<(const DurationDistancePayload &right) const + { + return duration < right.duration || (duration == right.duration && distance < right.distance); + } + + DurationDistancePayload & operator+=(const DurationDistancePayload &right) + { + duration += right.duration; + distance += right.distance; + return *this; + } + + DurationDistancePayload operator-() const + { + return DurationDistancePayload(-duration, -distance); + } +}; + +inline DurationDistancePayload operator+(const DurationDistancePayload& lhs, const DurationDistancePayload& rhs) +{ + return DurationDistancePayload(lhs.duration + rhs.duration, lhs.distance + rhs.distance); +} + +static_assert(sizeof(DurationDistancePayload) == 8, "DurationDistancePayload is larger than expected"); + +struct DurationPayload +{ + EdgeWeight duration; + + DurationPayload(const DurationDistancePayload & other) : DurationPayload(other.duration) {} + DurationPayload(const EdgeWeight & duration, const EdgeDistance & distance) : DurationPayload(duration) { (void)distance; } + DurationPayload(const EdgeWeight & duration) : duration(duration) {} + DurationPayload() : duration(0) {} + + bool operator==(const DurationPayload &right) const + { + return duration == right.duration; + } + + bool operator<(const DurationPayload &right) const + { + return duration < right.duration; + } + + DurationPayload & operator+=(const DurationPayload &right) + { + duration += right.duration; + return *this; + } + + DurationPayload operator-() const + { + return DurationPayload(-duration); + } +}; + +inline DurationPayload operator+(const DurationPayload& lhs, const DurationPayload& rhs) +{ + return DurationPayload(lhs.duration + rhs.duration); +} + +static_assert(sizeof(DurationPayload) == 4, "DurationPayload is larger than expected"); + + +////////////////////////////////////////////////////// + +#ifdef PAYLOAD_TYPE_DURATIONS_AND_DISTANCES +using EdgePayload = DurationDistancePayload; +using UncompressedEdgePayload = DurationPayload; +using RoutingPayload = DurationDistancePayload; +#elif PAYLOAD_TYPE_DURATIONS +using EdgePayload = DurationPayload; +using UncompressedEdgePayload = DurationPayload; +using RoutingPayload = DurationPayload; +#else +#error "Please specify desired payload type in Makefile." +#endif + +static inline EdgePayload MAKE_PAYLOAD(EdgeWeight duration, EdgeDistance distance) +{ + return DurationDistancePayload(duration, distance); +} + +static inline RoutingPayload MAKE_ROUTING_PAYLOAD(EdgeWeight duration, EdgeDistance distance) +{ + return RoutingPayload(duration, distance); +} + + +static const EdgePayload INVALID_PAYLOAD = MAKE_PAYLOAD(MAXIMAL_EDGE_DURATION, MAXIMAL_EDGE_DISTANCE); +static const RoutingPayload INVALID_RPAYLOAD = MAKE_ROUTING_PAYLOAD(MAXIMAL_EDGE_DURATION, MAXIMAL_EDGE_DISTANCE); + +#endif /* PAYLOAD_H */ \ No newline at end of file diff --git a/include/util/typedefs.hpp b/include/util/typedefs.hpp index 815ca170dbb..5fa0baaa60e 100644 --- a/include/util/typedefs.hpp +++ b/include/util/typedefs.hpp @@ -58,6 +58,7 @@ using NodeID = std::uint32_t; using EdgeID = std::uint32_t; using NameID = std::uint32_t; using EdgeWeight = std::int32_t; +using EdgeDistance = float; using TurnPenalty = std::int16_t; // turn penalty in 100ms units static const std::size_t INVALID_INDEX = std::numeric_limits::max(); @@ -85,8 +86,9 @@ static const EdgeID SPECIAL_EDGEID = std::numeric_limits::max(); static const NameID INVALID_NAMEID = std::numeric_limits::max(); static const NameID EMPTY_NAMEID = 0; static const unsigned INVALID_COMPONENTID = 0; -static const EdgeWeight INVALID_EDGE_WEIGHT = std::numeric_limits::max(); +static const EdgeWeight INVALID_EDGE_WEIGHT = (1 << 29) - 1;//TODO: Discuss! static const EdgeWeight MAXIMAL_EDGE_DURATION = std::numeric_limits::max(); +static const EdgeDistance MAXIMAL_EDGE_DISTANCE = std::numeric_limits::infinity(); static const TurnPenalty INVALID_TURN_PENALTY = std::numeric_limits::max(); // FIXME the bitfields we use require a reduced maximal duration, this should be kept consistent diff --git a/src/contractor/contractor.cpp b/src/contractor/contractor.cpp index b0f0e0988a1..9137d55b2e9 100644 --- a/src/contractor/contractor.cpp +++ b/src/contractor/contractor.cpp @@ -909,7 +909,7 @@ Contractor::LoadEdgeExpandedGraph(const ContractorConfig &config, // Update edge weight inbuffer.data.weight = new_weight + turn_weight_penalty; - inbuffer.data.duration = new_duration + turn_duration_penalty; + inbuffer.data.payload.duration = new_duration + turn_duration_penalty; } edge_based_edge_list.emplace_back(std::move(inbuffer)); diff --git a/src/contractor/graph_contractor.cpp b/src/contractor/graph_contractor.cpp index 0a3833ccf73..25756c7f3bc 100644 --- a/src/contractor/graph_contractor.cpp +++ b/src/contractor/graph_contractor.cpp @@ -39,21 +39,25 @@ GraphContractor::GraphContractor(int nodes, forward_edge.data.id = reverse_edge.data.id = id; forward_edge.data.originalEdges = reverse_edge.data.originalEdges = 1; forward_edge.data.weight = reverse_edge.data.weight = INVALID_EDGE_WEIGHT; - forward_edge.data.duration = reverse_edge.data.duration = MAXIMAL_EDGE_DURATION; + forward_edge.data.payload = reverse_edge.data.payload = INVALID_PAYLOAD; // remove parallel edges while (i < edges.size() && edges[i].source == source && edges[i].target == target) { if (edges[i].data.forward) { - forward_edge.data.weight = std::min(edges[i].data.weight, forward_edge.data.weight); - forward_edge.data.duration = - std::min(edges[i].data.duration, forward_edge.data.duration); + if (edges[i].data.weight < forward_edge.data.weight) + { + forward_edge.data.weight = edges[i].data.weight; + forward_edge.data.payload = edges[i].data.payload; + } } if (edges[i].data.backward) { - reverse_edge.data.weight = std::min(edges[i].data.weight, reverse_edge.data.weight); - reverse_edge.data.duration = - std::min(edges[i].data.duration, reverse_edge.data.duration); + if (edges[i].data.weight < reverse_edge.data.weight) + { + reverse_edge.data.weight = edges[i].data.weight; + reverse_edge.data.payload = edges[i].data.payload; + } } ++i; } diff --git a/src/engine/plugins/table.cpp b/src/engine/plugins/table.cpp index b5d391276b6..3941bce047b 100644 --- a/src/engine/plugins/table.cpp +++ b/src/engine/plugins/table.cpp @@ -77,7 +77,7 @@ Status TablePlugin::HandleRequest(const datafacade::ContiguousInternalMemoryData } api::TableAPI table_api{facade, params}; - table_api.MakeResponse(result_table, snapped_phantoms, result); + table_api.MakeResponse(result_table, snapped_phantoms, result, params.output_fields); return Status::Ok; } diff --git a/src/engine/plugins/trip.cpp b/src/engine/plugins/trip.cpp index ce85c70ea45..f6374102ee8 100644 --- a/src/engine/plugins/trip.cpp +++ b/src/engine/plugins/trip.cpp @@ -214,7 +214,7 @@ Status TripPlugin::HandleRequest(const datafacade::ContiguousInternalMemoryDataF // compute the duration table of all phantom nodes auto result_table = util::DistTableWrapper( - algorithms.ManyToManySearch(snapped_phantoms, {}, {}), number_of_locations); + algorithms.ManyToManyDurations(snapped_phantoms, {}, {}), number_of_locations); if (result_table.size() == 0) { @@ -276,4 +276,4 @@ Status TripPlugin::HandleRequest(const datafacade::ContiguousInternalMemoryDataF } } } -} +} \ No newline at end of file diff --git a/src/engine/routing_algorithms/alternative_path.cpp b/src/engine/routing_algorithms/alternative_path.cpp index ad998fe4ea7..9e097b34d7a 100644 --- a/src/engine/routing_algorithms/alternative_path.cpp +++ b/src/engine/routing_algorithms/alternative_path.cpp @@ -89,7 +89,7 @@ void alternativeRoutingStep( else { // check whether there is a loop present at the node - const auto loop_weight = getLoopWeight(facade, node); + const auto loop_weight = getLoopWeight(facade, node); const EdgeWeight new_weight_with_loop = new_weight + loop_weight; if (loop_weight != INVALID_EDGE_WEIGHT && new_weight_with_loop <= *upper_bound_to_shortest_path_weight) diff --git a/src/engine/routing_algorithms/many_to_many.cpp b/src/engine/routing_algorithms/many_to_many.cpp index 6eef3b0d1db..8b6be5dca54 100644 --- a/src/engine/routing_algorithms/many_to_many.cpp +++ b/src/engine/routing_algorithms/many_to_many.cpp @@ -23,9 +23,9 @@ struct NodeBucket { unsigned target_id; // essentially a row in the weight matrix EdgeWeight weight; - EdgeWeight duration; - NodeBucket(const unsigned target_id, const EdgeWeight weight, const EdgeWeight duration) - : target_id(target_id), weight(weight), duration(duration) + RoutingPayload payload; + NodeBucket(const unsigned target_id, const EdgeWeight weight, const RoutingPayload & payload) + : target_id(target_id), weight(weight), payload(payload) { } }; @@ -37,7 +37,7 @@ template void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade &facade, const NodeID node, const EdgeWeight weight, - const EdgeWeight duration, + const RoutingPayload & payload, ManyToManyQueryHeap &query_heap) { for (auto edge : facade.GetAdjacentEdgeRange(node)) @@ -47,22 +47,22 @@ void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade 0, "edge_weight invalid"); const EdgeWeight to_weight = weight + edge_weight; - const EdgeWeight to_duration = duration + edge_duration; + const RoutingPayload to_payload = payload + edge_payload; // New Node discovered -> Add to Heap + Node Info Storage if (!query_heap.WasInserted(to)) { - query_heap.Insert(to, to_weight, {node, to_duration}); + query_heap.Insert(to, to_weight, {node, to_payload}); } // Found a shorter Path -> Update weight else if (to_weight < query_heap.GetKey(to)) { // new parent - query_heap.GetData(to) = {node, to_duration}; + query_heap.GetData(to) = {node, to_payload}; query_heap.DecreaseKey(to, to_weight); } } @@ -75,11 +75,11 @@ void forwardRoutingStep(const datafacade::ContiguousInternalMemoryDataFacade &weights_table, - std::vector &durations_table) + std::vector &payload_table) { const NodeID node = query_heap.DeleteMin(); const EdgeWeight source_weight = query_heap.GetKey(node); - const EdgeWeight source_duration = query_heap.GetData(node).duration; + const RoutingPayload & source_payload = query_heap.GetData(node).payload; // check if each encountered node has an entry const auto bucket_iterator = search_space_with_buckets.find(node); @@ -92,29 +92,31 @@ void forwardRoutingStep(const datafacade::ContiguousInternalMemoryDataFacade(facade, node); + const EdgeWeight loop_weight = getLoopWeight(facade, node); const EdgeWeight new_weight_with_loop = new_weight + loop_weight; if (loop_weight != INVALID_EDGE_WEIGHT && new_weight_with_loop >= 0) { - current_weight = std::min(current_weight, new_weight_with_loop); - current_duration = std::min(current_duration, - source_duration + target_duration + - getLoopWeight(facade, node)); + if (new_weight_with_loop < current_weight) + { + current_weight = new_weight_with_loop; + RoutingPayload payload = RoutingPayload(GetLoopPayload(facade, node)); + current_payload = source_payload + target_payload + payload; + } } } else if (new_weight < current_weight) { current_weight = new_weight; - current_duration = source_duration + target_duration; + current_payload = source_payload + target_payload; } } } @@ -123,7 +125,7 @@ void forwardRoutingStep(const datafacade::ContiguousInternalMemoryDataFacade(facade, node, source_weight, source_duration, query_heap); + relaxOutgoingEdges(facade, node, source_weight, source_payload, query_heap); } void backwardRoutingStep( @@ -134,21 +136,21 @@ void backwardRoutingStep( { const NodeID node = query_heap.DeleteMin(); const EdgeWeight target_weight = query_heap.GetKey(node); - const EdgeWeight target_duration = query_heap.GetData(node).duration; + const RoutingPayload target_payload = query_heap.GetData(node).payload; // store settled nodes in search space bucket - search_space_with_buckets[node].emplace_back(column_idx, target_weight, target_duration); + search_space_with_buckets[node].emplace_back(column_idx, target_weight, target_payload); if (stallAtNode(facade, node, target_weight, query_heap)) { return; } - relaxOutgoingEdges(facade, node, target_weight, target_duration, query_heap); + relaxOutgoingEdges(facade, node, target_weight, target_payload, query_heap); } } -std::vector +std::vector manyToManySearch(SearchEngineData &engine_working_data, const datafacade::ContiguousInternalMemoryDataFacade &facade, const std::vector &phantom_nodes, @@ -162,7 +164,7 @@ manyToManySearch(SearchEngineData &engine_working_data, const auto number_of_entries = number_of_sources * number_of_targets; std::vector weights_table(number_of_entries, INVALID_EDGE_WEIGHT); - std::vector durations_table(number_of_entries, MAXIMAL_EDGE_DURATION); + std::vector payload_table(number_of_entries, INVALID_RPAYLOAD); engine_working_data.InitializeOrClearManyToManyThreadLocalStorage(facade.GetNumberOfNodes()); @@ -179,13 +181,13 @@ manyToManySearch(SearchEngineData &engine_working_data, { query_heap.Insert(phantom.forward_segment_id.id, phantom.GetForwardWeightPlusOffset(), - {phantom.forward_segment_id.id, phantom.GetForwardDuration()}); + {phantom.forward_segment_id.id, RoutingPayload(phantom.GetForwardPayload())}); } if (phantom.reverse_segment_id.enabled) { query_heap.Insert(phantom.reverse_segment_id.id, phantom.GetReverseWeightPlusOffset(), - {phantom.reverse_segment_id.id, phantom.GetReverseDuration()}); + {phantom.reverse_segment_id.id, RoutingPayload(phantom.GetReversePayload())}); } // explore search space @@ -206,13 +208,13 @@ manyToManySearch(SearchEngineData &engine_working_data, { query_heap.Insert(phantom.forward_segment_id.id, -phantom.GetForwardWeightPlusOffset(), - {phantom.forward_segment_id.id, -phantom.GetForwardDuration()}); + {phantom.forward_segment_id.id, -RoutingPayload(phantom.GetForwardPayload())}); } if (phantom.reverse_segment_id.enabled) { query_heap.Insert(phantom.reverse_segment_id.id, -phantom.GetReverseWeightPlusOffset(), - {phantom.reverse_segment_id.id, -phantom.GetReverseDuration()}); + {phantom.reverse_segment_id.id, -RoutingPayload(phantom.GetReversePayload())}); } // explore search space @@ -224,7 +226,7 @@ manyToManySearch(SearchEngineData &engine_working_data, query_heap, search_space_with_buckets, weights_table, - durations_table); + payload_table); } ++row_idx; }; @@ -261,7 +263,7 @@ manyToManySearch(SearchEngineData &engine_working_data, } } - return durations_table; + return payload_table; } } // namespace routing_algorithms diff --git a/src/extractor/compressed_edge_container.cpp b/src/extractor/compressed_edge_container.cpp index b34ab90e782..b323f8cd17c 100644 --- a/src/extractor/compressed_edge_container.cpp +++ b/src/extractor/compressed_edge_container.cpp @@ -126,8 +126,8 @@ void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1, const NodeID target_node_id, const EdgeWeight weight1, const EdgeWeight weight2, - const EdgeWeight duration1, - const EdgeWeight duration2) + const UncompressedEdgePayload & payload1, + const UncompressedEdgePayload & payload2) { // remove super-trivial geometries BOOST_ASSERT(SPECIAL_EDGEID != edge_id_1); @@ -172,7 +172,7 @@ void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1, // weight1 is the distance to the (currently) last coordinate in the bucket if (edge_bucket_list1.empty()) { - edge_bucket_list1.emplace_back(OnewayCompressedEdge{via_node_id, weight1, duration1}); + edge_bucket_list1.emplace_back(OnewayCompressedEdge{via_node_id, weight1, payload1}); } BOOST_ASSERT(0 < edge_bucket_list1.size()); @@ -203,14 +203,14 @@ void CompressedEdgeContainer::CompressEdge(const EdgeID edge_id_1, else { // we are certain that the second edge is atomic. - edge_bucket_list1.emplace_back(OnewayCompressedEdge{target_node_id, weight2, duration2}); + edge_bucket_list1.emplace_back(OnewayCompressedEdge{target_node_id, weight2, payload2}); } } void CompressedEdgeContainer::AddUncompressedEdge(const EdgeID edge_id, const NodeID target_node_id, const EdgeWeight weight, - const EdgeWeight duration) + const UncompressedEdgePayload & payload) { // remove super-trivial geometries BOOST_ASSERT(SPECIAL_EDGEID != edge_id); @@ -246,7 +246,7 @@ void CompressedEdgeContainer::AddUncompressedEdge(const EdgeID edge_id, // Don't re-add this if it's already in there. if (edge_bucket_list.empty()) { - edge_bucket_list.emplace_back(OnewayCompressedEdge{target_node_id, weight, duration}); + edge_bucket_list.emplace_back(OnewayCompressedEdge{target_node_id, weight, payload}); } } @@ -279,7 +279,7 @@ unsigned CompressedEdgeContainer::ZipEdges(const EdgeID f_edge_id, const EdgeID m_compressed_geometry_fwd_weights.emplace_back(INVALID_EDGE_WEIGHT); m_compressed_geometry_rev_weights.emplace_back(first_node.weight); m_compressed_geometry_fwd_durations.emplace_back(INVALID_EDGE_WEIGHT); - m_compressed_geometry_rev_durations.emplace_back(first_node.duration); + m_compressed_geometry_rev_durations.emplace_back(first_node.payload.duration); for (std::size_t i = 0; i < forward_bucket.size() - 1; ++i) { @@ -291,8 +291,8 @@ unsigned CompressedEdgeContainer::ZipEdges(const EdgeID f_edge_id, const EdgeID m_compressed_geometry_nodes.emplace_back(fwd_node.node_id); m_compressed_geometry_fwd_weights.emplace_back(fwd_node.weight); m_compressed_geometry_rev_weights.emplace_back(rev_node.weight); - m_compressed_geometry_fwd_durations.emplace_back(fwd_node.duration); - m_compressed_geometry_rev_durations.emplace_back(rev_node.duration); + m_compressed_geometry_fwd_durations.emplace_back(fwd_node.payload.duration); + m_compressed_geometry_rev_durations.emplace_back(rev_node.payload.duration); } const auto &last_node = forward_bucket.back(); @@ -300,7 +300,7 @@ unsigned CompressedEdgeContainer::ZipEdges(const EdgeID f_edge_id, const EdgeID m_compressed_geometry_nodes.emplace_back(last_node.node_id); m_compressed_geometry_fwd_weights.emplace_back(last_node.weight); m_compressed_geometry_rev_weights.emplace_back(INVALID_EDGE_WEIGHT); - m_compressed_geometry_fwd_durations.emplace_back(last_node.duration); + m_compressed_geometry_fwd_durations.emplace_back(last_node.payload.duration); m_compressed_geometry_rev_durations.emplace_back(INVALID_EDGE_WEIGHT); return zipped_geometry_id; diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index 5b660c16ad9..534573f6b8a 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -563,12 +563,14 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( auto weight = boost::numeric_cast(edge_data1.weight + weight_penalty); auto duration = - boost::numeric_cast(edge_data1.duration + duration_penalty); + boost::numeric_cast(edge_data1.payload.duration + duration_penalty); + EdgePayload payload = edge_data1.payload; + payload.duration = duration; m_edge_based_edge_list.emplace_back(edge_data1.edge_id, edge_data2.edge_id, turn_id, weight, - duration, + payload, true, false); BOOST_ASSERT(original_edges_counter == m_edge_based_edge_list.size()); @@ -620,7 +622,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( lookup::SegmentBlock nodeblock{to.node_id, segment_length, target_node.weight, - target_node.duration}; + target_node.payload.duration}; edge_segment_file.write(reinterpret_cast(&nodeblock), sizeof(nodeblock)); diff --git a/src/extractor/extraction_containers.cpp b/src/extractor/extraction_containers.cpp index b878c3b0525..f57709293fc 100644 --- a/src/extractor/extraction_containers.cpp +++ b/src/extractor/extraction_containers.cpp @@ -402,7 +402,8 @@ void ExtractionContainers::PrepareEdges(ScriptingEnvironment &scripting_environm auto &edge = edge_iterator->result; edge.weight = std::max(1, std::round(extracted_segment.weight * weight_multiplier)); - edge.duration = std::max(1, std::round(extracted_segment.duration * 10.)); + edge.payload = MAKE_PAYLOAD(std::max(1, + std::round(extracted_segment.duration * 10.)), distance); // assign new node id auto id_iter = external_to_internal_node_id_map.find(node_iterator->node_id); @@ -469,9 +470,9 @@ void ExtractionContainers::PrepareEdges(ScriptingEnvironment &scripting_environm NodeID target = all_edges_list[i].result.target; auto min_forward = std::make_pair(std::numeric_limits::max(), - std::numeric_limits::max()); + INVALID_PAYLOAD); auto min_backward = std::make_pair(std::numeric_limits::max(), - std::numeric_limits::max()); + INVALID_PAYLOAD); std::size_t min_forward_idx = std::numeric_limits::max(); std::size_t min_backward_idx = std::numeric_limits::max(); @@ -480,7 +481,7 @@ void ExtractionContainers::PrepareEdges(ScriptingEnvironment &scripting_environm all_edges_list[i].result.target == target) { const auto &result = all_edges_list[i].result; - const auto value = std::make_pair(result.weight, result.duration); + const auto value = std::make_pair(result.weight, result.payload); if (result.forward && value < min_forward) { min_forward_idx = i; diff --git a/src/extractor/graph_compressor.cpp b/src/extractor/graph_compressor.cpp index 12a07d319d1..e7bf69c2992 100644 --- a/src/extractor/graph_compressor.cpp +++ b/src/extractor/graph_compressor.cpp @@ -122,16 +122,16 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, // Get weights before graph is modified const EdgeWeight forward_weight1 = fwd_edge_data1.weight; const EdgeWeight forward_weight2 = fwd_edge_data2.weight; - const EdgeWeight forward_duration1 = fwd_edge_data1.duration; - const EdgeWeight forward_duration2 = fwd_edge_data2.duration; + const EdgePayload & forward_payload1 = fwd_edge_data1.payload; + const EdgePayload & forward_payload2 = fwd_edge_data2.payload; BOOST_ASSERT(0 != forward_weight1); BOOST_ASSERT(0 != forward_weight2); const EdgeWeight reverse_weight1 = rev_edge_data1.weight; const EdgeWeight reverse_weight2 = rev_edge_data2.weight; - const EdgeWeight reverse_duration1 = rev_edge_data1.duration; - const EdgeWeight reverse_duration2 = rev_edge_data2.duration; + const EdgePayload & reverse_payload1 = rev_edge_data1.payload; + const EdgePayload & reverse_payload2 = rev_edge_data2.payload; BOOST_ASSERT(0 != reverse_weight1); BOOST_ASSERT(0 != reverse_weight2); @@ -140,9 +140,9 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, graph.GetEdgeData(forward_e1).weight += forward_weight2; graph.GetEdgeData(reverse_e1).weight += reverse_weight2; - // add duration of e2's to e1 - graph.GetEdgeData(forward_e1).duration += forward_duration2; - graph.GetEdgeData(reverse_e1).duration += reverse_duration2; + // add payload of e2's to e1 + graph.GetEdgeData(forward_e1).payload += forward_payload2; + graph.GetEdgeData(reverse_e1).payload += reverse_payload2; // extend e1's to targets of e2's graph.SetTarget(forward_e1, node_w); @@ -210,16 +210,16 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, node_w, forward_weight1, forward_weight2, - forward_duration1, - forward_duration2); + UncompressedEdgePayload(forward_payload1), + UncompressedEdgePayload(forward_payload2)); geometry_compressor.CompressEdge(reverse_e1, reverse_e2, node_v, node_u, reverse_weight1, reverse_weight2, - reverse_duration1, - reverse_duration2); + UncompressedEdgePayload(reverse_payload1), + UncompressedEdgePayload(reverse_payload2)); } } } @@ -235,7 +235,7 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, { const EdgeData &data = graph.GetEdgeData(edge_id); const NodeID target = graph.GetTarget(edge_id); - geometry_compressor.AddUncompressedEdge(edge_id, target, data.weight, data.duration); + geometry_compressor.AddUncompressedEdge(edge_id, target, data.weight, UncompressedEdgePayload(data.payload)); } } } diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index abfe1c68ce1..421c068b0f6 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -413,7 +413,7 @@ BOOST_AUTO_TEST_CASE(valid_table_urls) std::vector sources_2 = {1, 2, 3}; std::vector destinations_2 = {4, 5}; - TableParameters reference_2{sources_2, destinations_2}; + TableParameters reference_2{sources_2, destinations_2, std::vector()}; reference_2.coordinates = coords_1; auto result_2 = parseParameters("1,2;3,4?sources=1;2;3&destinations=4;5"); BOOST_CHECK(result_2); From 244dd8d85f6a6726c1591aec773b2f88534f31e8 Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Thu, 9 Mar 2017 11:31:41 +0100 Subject: [PATCH 02/12] Defaulting to "Durations" payload if no Payload has been selected in the environment. Build server not using cmake? --- include/util/payload.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/util/payload.hpp b/include/util/payload.hpp index 797689c637f..2b09a0fb99b 100644 --- a/include/util/payload.hpp +++ b/include/util/payload.hpp @@ -113,12 +113,10 @@ static_assert(sizeof(DurationPayload) == 4, "DurationPayload is larger than expe using EdgePayload = DurationDistancePayload; using UncompressedEdgePayload = DurationPayload; using RoutingPayload = DurationDistancePayload; -#elif PAYLOAD_TYPE_DURATIONS +#else //PAYLOAD_TYPE_DURATIONS using EdgePayload = DurationPayload; using UncompressedEdgePayload = DurationPayload; using RoutingPayload = DurationPayload; -#else -#error "Please specify desired payload type in Makefile." #endif static inline EdgePayload MAKE_PAYLOAD(EdgeWeight duration, EdgeDistance distance) From 0e118b6e4056a26fa2c923630d7ce627c9f8467d Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Thu, 9 Mar 2017 12:50:58 +0100 Subject: [PATCH 03/12] Trying to fix build issues on build servers (works on my test systems...). --- include/engine/hint.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/engine/hint.hpp b/include/engine/hint.hpp index a65cb6496a0..b1094fae7d6 100644 --- a/include/engine/hint.hpp +++ b/include/engine/hint.hpp @@ -64,7 +64,7 @@ struct Hint }; static_assert(sizeof(Hint) == sizeof(PhantomNode) + 4, "Hint is bigger than expected"); -constexpr std::size_t ENCODED_HINT_SIZE = (std::size_t) std::ceil(sizeof(Hint) / 3.) * 4; +constexpr std::size_t ENCODED_HINT_SIZE = sizeof(EdgePayload) == 4 ? 104 : (sizeof(EdgePayload) == 8 ? 112 : 0); // (std::size_t) std::ceil(sizeof(Hint) / 3.) * 4; static_assert(ENCODED_HINT_SIZE / 4 * 3 >= sizeof(Hint), "ENCODED_HINT_SIZE does not match size of Hint"); } From 6e372c35e6214dd74193a6ca80838fe5f6a97e75 Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Thu, 9 Mar 2017 13:26:03 +0100 Subject: [PATCH 04/12] Fixed another merge issue. --- src/engine/routing_algorithms/tile_turns.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/routing_algorithms/tile_turns.cpp b/src/engine/routing_algorithms/tile_turns.cpp index 1dbbf5c72b7..3c95729d033 100644 --- a/src/engine/routing_algorithms/tile_turns.cpp +++ b/src/engine/routing_algorithms/tile_turns.cpp @@ -193,7 +193,7 @@ getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade // penalties, but at this stage, we can't divide those out, so we just // treat the whole lot as the "turn cost" that we'll stick on the map. const auto turn_weight = data.weight - sum_node_weight; - const auto turn_duration = data.duration - sum_node_duration; + const auto turn_duration = data.payload.duration - sum_node_duration; // Find the three nodes that make up the turn movement) const auto node_from = startnode; From 2a7ecfc00b798078c8dd822f199b376a1ce126a1 Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Thu, 9 Mar 2017 13:48:08 +0100 Subject: [PATCH 05/12] Added payload.hpp header reference to buildscript. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8081f1899e7..eb43f882489 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -701,7 +701,7 @@ file(GLOB VariantGlob third_party/variant/include/mapbox/*.hpp) file(GLOB LibraryGlob include/osrm/*.hpp) file(GLOB ParametersGlob include/engine/api/*_parameters.hpp) set(EngineHeader include/engine/status.hpp include/engine/engine_config.hpp include/engine/hint.hpp include/engine/bearing.hpp include/engine/phantom_node.hpp) -set(UtilHeader include/util/coordinate.hpp include/util/json_container.hpp include/util/typedefs.hpp include/util/strong_typedef.hpp include/util/exception.hpp) +set(UtilHeader include/util/coordinate.hpp include/util/json_container.hpp include/util/typedefs.hpp include/util/strong_typedef.hpp include/util/exception.hpp include/util/payload.hpp) set(ExtractorHeader include/extractor/extractor.hpp include/extractor/extractor_config.hpp include/extractor/travel_mode.hpp) set(PartitionerHeader include/partition/partitioner.hpp include/partition/partition_config.hpp) set(ContractorHeader include/contractor/contractor.hpp include/contractor/contractor_config.hpp) From 368617aa7196b3dd315785fdaaeac3c6433f7803 Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Thu, 9 Mar 2017 14:14:32 +0100 Subject: [PATCH 06/12] Whitespace change only: Clang format. --- include/contractor/query_edge.hpp | 7 +- include/engine/api/table_api.hpp | 20 ++--- include/engine/api/table_parameters.hpp | 14 ++- include/engine/api/table_payload.hpp | 71 ++++++++------- include/engine/geospatial_query.hpp | 54 ++++++------ include/engine/hint.hpp | 5 +- include/engine/phantom_node.hpp | 36 ++++---- include/engine/routing_algorithms.hpp | 26 +++--- include/engine/search_engine_data.hpp | 2 +- .../extractor/compressed_edge_container.hpp | 12 +-- include/extractor/edge_based_edge.hpp | 12 +-- include/extractor/node_based_edge.hpp | 12 +-- .../server/api/table_parameter_grammar.hpp | 9 +- include/util/node_based_graph.hpp | 6 +- include/util/payload.hpp | 87 ++++++++++--------- include/util/typedefs.hpp | 2 +- .../routing_algorithms/many_to_many.cpp | 40 +++++---- src/extractor/compressed_edge_container.cpp | 6 +- src/extractor/edge_based_graph_factory.cpp | 4 +- src/extractor/extraction_containers.cpp | 10 +-- src/extractor/graph_compressor.cpp | 13 +-- 21 files changed, 229 insertions(+), 219 deletions(-) diff --git a/include/contractor/query_edge.hpp b/include/contractor/query_edge.hpp index cfb495fe794..905985c4fec 100644 --- a/include/contractor/query_edge.hpp +++ b/include/contractor/query_edge.hpp @@ -1,8 +1,8 @@ #ifndef QUERYEDGE_HPP #define QUERYEDGE_HPP -#include "util/typedefs.hpp" #include "util/payload.hpp" +#include "util/typedefs.hpp" #include @@ -24,7 +24,7 @@ struct QueryEdge template EdgeData(const OtherT &other) { - weight = other.weight; + weight = other.weight; shortcut = other.shortcut; id = other.id; forward = other.forward; @@ -59,8 +59,7 @@ struct QueryEdge return (source == right.source && target == right.target && data.weight == right.data.weight && data.shortcut == right.data.shortcut && data.forward == right.data.forward && data.backward == right.data.backward && - data.payload == right.data.payload && - data.id == right.data.id); + data.payload == right.data.payload && data.id == right.data.id); } }; } diff --git a/include/engine/api/table_api.hpp b/include/engine/api/table_api.hpp index 10670a3dc48..8387271efdd 100644 --- a/include/engine/api/table_api.hpp +++ b/include/engine/api/table_api.hpp @@ -40,8 +40,7 @@ class TableAPI final : public BaseAPI virtual void MakeResponse(const std::vector &entries, const std::vector &phantoms, util::json::Object &response, - const std::vector & output_fields - ) const + const std::vector &output_fields) const { auto number_of_sources = parameters.sources.size(); auto number_of_destinations = parameters.destinations.size(); @@ -67,11 +66,14 @@ class TableAPI final : public BaseAPI { response.values["destinations"] = MakeWaypoints(phantoms, parameters.destinations); } - + for (auto &component : output_fields.size() == 0 ? DEFAULT_FIELDS : output_fields) { response.values[TableOutputFieldName[component]] = - MakeTable(entries, number_of_sources, number_of_destinations, get_encoder(component)); + MakeTable(entries, + number_of_sources, + number_of_destinations, + get_encoder(component)); } response.values["code"] = "Ok"; @@ -117,21 +119,19 @@ class TableAPI final : public BaseAPI 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(), - encoder); + std::transform(row_begin_iterator, row_end_iterator, json_row.values.begin(), encoder); json_table.values.push_back(std::move(json_row)); } return json_table; } const TableParameters ¶meters; - + static const std::vector DEFAULT_FIELDS; }; -const std::vector TableAPI::DEFAULT_FIELDS = std::vector(1, DURATION); +const std::vector TableAPI::DEFAULT_FIELDS = + std::vector(1, DURATION); } // ns api } // ns engine diff --git a/include/engine/api/table_parameters.hpp b/include/engine/api/table_parameters.hpp index b0b6022563f..20fb59e3023 100644 --- a/include/engine/api/table_parameters.hpp +++ b/include/engine/api/table_parameters.hpp @@ -42,17 +42,15 @@ namespace engine { namespace api { - -enum TableOutputField { - DURATION, - DISTANCE -}; -const std::string TableOutputFieldName[] = { - "durations", - "distances" +enum TableOutputField +{ + DURATION, + DISTANCE }; +const std::string TableOutputFieldName[] = {"durations", "distances"}; + /** * Parameters specific to the OSRM Table service. * diff --git a/include/engine/api/table_payload.hpp b/include/engine/api/table_payload.hpp index afc727ff5d7..e8dab9a030f 100644 --- a/include/engine/api/table_payload.hpp +++ b/include/engine/api/table_payload.hpp @@ -20,62 +20,67 @@ namespace engine namespace api { -template -using PAYLOAD_ENCODER = util::json::Value (*)(const PayloadType & entry); +template +using PAYLOAD_ENCODER = util::json::Value (*)(const PayloadType &entry); -template -inline util::json::Value default_duration_encoder(const PayloadType & entry) +template +inline util::json::Value default_duration_encoder(const PayloadType &entry) { - if (entry.duration == MAXIMAL_EDGE_DURATION) return util::json::Value(util::json::Null()); + if (entry.duration == MAXIMAL_EDGE_DURATION) + return util::json::Value(util::json::Null()); return util::json::Value(util::json::Number(entry.duration / 10.)); } -template -inline util::json::Value default_distance_encoder(const PayloadType & entry) +template +inline util::json::Value default_distance_encoder(const PayloadType &entry) { - if (entry.distance == MAXIMAL_EDGE_DISTANCE) return util::json::Value(util::json::Null()); + if (entry.distance == MAXIMAL_EDGE_DISTANCE) + return util::json::Value(util::json::Null()); return util::json::Value(util::json::Number(entry.distance)); } -template -inline util::json::Value empty_encoder(const PayloadType & entry) +template inline util::json::Value empty_encoder(const PayloadType &entry) { return util::json::Value(util::json::Null()); } -template -inline PAYLOAD_ENCODER get_encoder(TableOutputField component) +template +inline PAYLOAD_ENCODER get_encoder(TableOutputField component) { throw util::exception("Internal Error: Encoders missing for used payload type."); -} +} -template<> -inline PAYLOAD_ENCODER get_encoder(TableOutputField component) +template <> +inline PAYLOAD_ENCODER +get_encoder(TableOutputField component) { - switch(component) + switch (component) { - case DURATION: - return default_duration_encoder; - case DISTANCE: - return default_distance_encoder; - default: - throw util::exception("Internal Error: Encountered unknown output component type: " + component); + case DURATION: + return default_duration_encoder; + case DISTANCE: + return default_distance_encoder; + default: + throw util::exception("Internal Error: Encountered unknown output component type: " + + component); } -} +} -template<> -inline PAYLOAD_ENCODER get_encoder(TableOutputField component) +template <> +inline PAYLOAD_ENCODER get_encoder(TableOutputField component) { - switch(component) + switch (component) { - case DURATION: - return default_duration_encoder; - case DISTANCE: - throw util::exception("Internal Error: Requested distance, but osrm is not configured to provide distances.");//TODO: Graceful error handling - default: - throw util::exception("Internal Error: Encountered unknown output component type: " + component); + case DURATION: + return default_duration_encoder; + case DISTANCE: + throw util::exception("Internal Error: Requested distance, but osrm is not configured to " + "provide distances."); // TODO: Graceful error handling + default: + throw util::exception("Internal Error: Encountered unknown output component type: " + + component); } -} +} } // ns api } // ns engine diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index 62d11178b25..36ea7626da3 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -386,41 +386,44 @@ template class GeospatialQuery datafacade.GetUncompressedForwardDurations(data.packed_geometry_id); const std::vector reverse_duration_vector = datafacade.GetUncompressedReverseDurations(data.packed_geometry_id); - const std::vector forward_node_vector = + const std::vector forward_node_vector = datafacade.GetUncompressedForwardGeometry(data.packed_geometry_id); - const std::vector reverse_node_vector = + const std::vector reverse_node_vector = datafacade.GetUncompressedReverseGeometry(data.packed_geometry_id); for (std::size_t i = 0; i < data.fwd_segment_position; i++) { forward_weight_offset += forward_weight_vector[i]; forward_duration_offset += forward_duration_vector[i]; - + auto c1 = coordinates[forward_node_vector[i]]; - auto c2 = coordinates[forward_node_vector[i+1]]; + auto c2 = coordinates[forward_node_vector[i + 1]]; forward_distance_offset += util::coordinate_calculation::greatCircleDistance(c1, c2); } forward_weight = forward_weight_vector[data.fwd_segment_position]; forward_duration = forward_duration_vector[data.fwd_segment_position]; - forward_distance = util::coordinate_calculation::greatCircleDistance(coordinates[forward_node_vector[data.fwd_segment_position]], - coordinates[forward_node_vector[data.fwd_segment_position + 1]]); + forward_distance = util::coordinate_calculation::greatCircleDistance( + coordinates[forward_node_vector[data.fwd_segment_position]], + coordinates[forward_node_vector[data.fwd_segment_position + 1]]); BOOST_ASSERT(data.fwd_segment_position < reverse_weight_vector.size()); - const std::size_t reverse_segment_position = reverse_weight_vector.size() - data.fwd_segment_position - 1; + const std::size_t reverse_segment_position = + reverse_weight_vector.size() - data.fwd_segment_position - 1; for (std::size_t i = 0; i < reverse_segment_position; i++) { reverse_weight_offset += reverse_weight_vector[i]; reverse_duration_offset += reverse_duration_vector[i]; - + auto c1 = coordinates[reverse_node_vector[i]]; - auto c2 = coordinates[reverse_node_vector[i+1]]; + auto c2 = coordinates[reverse_node_vector[i + 1]]; reverse_distance_offset += util::coordinate_calculation::greatCircleDistance(c1, c2); } reverse_weight = reverse_weight_vector[reverse_segment_position]; reverse_duration = reverse_duration_vector[reverse_segment_position]; - reverse_distance = util::coordinate_calculation::greatCircleDistance(coordinates[reverse_node_vector[reverse_segment_position]], - coordinates[reverse_node_vector[reverse_segment_position + 1]]); + reverse_distance = util::coordinate_calculation::greatCircleDistance( + coordinates[reverse_node_vector[reverse_segment_position]], + coordinates[reverse_node_vector[reverse_segment_position + 1]]); ratio = std::min(1.0, std::max(0.0, ratio)); if (data.forward_segment_id.id != SPECIAL_SEGMENTID) @@ -436,20 +439,21 @@ template class GeospatialQuery reverse_distance -= static_cast(reverse_distance * ratio); } - auto transformed = PhantomNodeWithDistance{PhantomNode{data, - forward_weight, - reverse_weight, - forward_weight_offset, - reverse_weight_offset, - forward_duration, - reverse_duration, - MAKE_PAYLOAD(forward_duration_offset + forward_duration, - forward_distance_offset + forward_distance), - MAKE_PAYLOAD(reverse_duration_offset + reverse_duration, - reverse_distance_offset + reverse_distance), - point_on_segment, - input_coordinate}, - current_perpendicular_distance}; + auto transformed = PhantomNodeWithDistance{ + PhantomNode{data, + forward_weight, + reverse_weight, + forward_weight_offset, + reverse_weight_offset, + forward_duration, + reverse_duration, + MAKE_PAYLOAD(forward_duration_offset + forward_duration, + forward_distance_offset + forward_distance), + MAKE_PAYLOAD(reverse_duration_offset + reverse_duration, + reverse_distance_offset + reverse_distance), + point_on_segment, + input_coordinate}, + current_perpendicular_distance}; return transformed; } diff --git a/include/engine/hint.hpp b/include/engine/hint.hpp index b1094fae7d6..abe4e4cceab 100644 --- a/include/engine/hint.hpp +++ b/include/engine/hint.hpp @@ -64,7 +64,10 @@ struct Hint }; static_assert(sizeof(Hint) == sizeof(PhantomNode) + 4, "Hint is bigger than expected"); -constexpr std::size_t ENCODED_HINT_SIZE = sizeof(EdgePayload) == 4 ? 104 : (sizeof(EdgePayload) == 8 ? 112 : 0); // (std::size_t) std::ceil(sizeof(Hint) / 3.) * 4; +constexpr std::size_t ENCODED_HINT_SIZE = + sizeof(EdgePayload) == 4 + ? 104 + : (sizeof(EdgePayload) == 8 ? 112 : 0); // (std::size_t) std::ceil(sizeof(Hint) / 3.) * 4; static_assert(ENCODED_HINT_SIZE / 4 * 3 >= sizeof(Hint), "ENCODED_HINT_SIZE does not match size of Hint"); } diff --git a/include/engine/phantom_node.hpp b/include/engine/phantom_node.hpp index cedaaea0b03..5e637e54929 100644 --- a/include/engine/phantom_node.hpp +++ b/include/engine/phantom_node.hpp @@ -29,8 +29,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define PHANTOM_NODES_H #include "extractor/travel_mode.hpp" -#include "util/typedefs.hpp" #include "util/payload.hpp" +#include "util/typedefs.hpp" #include "util/coordinate.hpp" @@ -83,7 +83,7 @@ struct PhantomNode reverse_segment_id{SPECIAL_SEGMENTID, false}, name_id(std::numeric_limits::max()), forward_weight(INVALID_EDGE_WEIGHT), reverse_weight(INVALID_EDGE_WEIGHT), forward_weight_offset(0), reverse_weight_offset(0), - forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION), + forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION), forward_payload(INVALID_PAYLOAD), reverse_payload(INVALID_PAYLOAD), packed_geometry_id(SPECIAL_GEOMETRYID), component{INVALID_COMPONENTID, false}, fwd_segment_position(0), forward_travel_mode(TRAVEL_MODE_INACCESSIBLE), @@ -102,16 +102,10 @@ struct PhantomNode BOOST_ASSERT(reverse_segment_id.enabled); return reverse_weight_offset + reverse_weight; } - - EdgePayload GetForwardPayload() const - { - return forward_payload; - } - - EdgePayload GetReversePayload() const - { - return reverse_payload; - } + + EdgePayload GetForwardPayload() const { return forward_payload; } + + EdgePayload GetReversePayload() const { return reverse_payload; } bool IsBidirected() const { return forward_segment_id.enabled && reverse_segment_id.enabled; } @@ -150,11 +144,10 @@ struct PhantomNode : forward_segment_id{other.forward_segment_id}, reverse_segment_id{other.reverse_segment_id}, name_id{other.name_id}, forward_weight{forward_weight}, reverse_weight{reverse_weight}, - forward_weight_offset{forward_weight_offset}, reverse_weight_offset{reverse_weight_offset}, - forward_duration{forward_duration}, - reverse_duration{reverse_duration}, - forward_payload{forward_payload}, reverse_payload{reverse_payload}, - packed_geometry_id{other.packed_geometry_id}, + forward_weight_offset{forward_weight_offset}, + reverse_weight_offset{reverse_weight_offset}, forward_duration{forward_duration}, + reverse_duration{reverse_duration}, forward_payload{forward_payload}, + reverse_payload{reverse_payload}, packed_geometry_id{other.packed_geometry_id}, component{other.component.id, other.component.is_tiny}, location{location}, input_location{input_location}, fwd_segment_position{other.fwd_segment_position}, forward_travel_mode{other.forward_travel_mode}, @@ -168,9 +161,9 @@ struct PhantomNode EdgeWeight forward_weight; EdgeWeight reverse_weight; EdgeWeight forward_weight_offset; // TODO: try to remove -> requires path unpacking changes - EdgeWeight reverse_weight_offset; // TODO: try to remove -> requires path unpacking changes - EdgeWeight forward_duration; // TODO: try to remove -> requires path unpacking changes - EdgeWeight reverse_duration; // TODO: try to remove -> requires path unpacking changes + EdgeWeight reverse_weight_offset; // TODO: try to remove -> requires path unpacking changes + EdgeWeight forward_duration; // TODO: try to remove -> requires path unpacking changes + EdgeWeight reverse_duration; // TODO: try to remove -> requires path unpacking changes EdgePayload forward_payload; EdgePayload reverse_payload; unsigned packed_geometry_id; @@ -190,7 +183,8 @@ struct PhantomNode extractor::TravelMode backward_travel_mode; }; -static_assert(sizeof(PhantomNode) == 64 + 2 * sizeof(EdgePayload), "PhantomNode has more padding then expected"); +static_assert(sizeof(PhantomNode) == 64 + 2 * sizeof(EdgePayload), + "PhantomNode has more padding then expected"); using PhantomNodePair = std::pair; diff --git a/include/engine/routing_algorithms.hpp b/include/engine/routing_algorithms.hpp index 02d3e235041..d2730ad108c 100644 --- a/include/engine/routing_algorithms.hpp +++ b/include/engine/routing_algorithms.hpp @@ -33,11 +33,11 @@ class RoutingAlgorithmsInterface ManyToManySearch(const std::vector &phantom_nodes, const std::vector &source_indices, const std::vector &target_indices) const = 0; - + virtual std::vector ManyToManyDurations(const std::vector &phantom_nodes, - const std::vector &source_indices, - const std::vector &target_indices) const = 0; + const std::vector &source_indices, + const std::vector &target_indices) const = 0; virtual routing_algorithms::SubMatchingList MapMatching(const routing_algorithms::CandidateLists &candidates_list, @@ -83,11 +83,11 @@ template class RoutingAlgorithms final : public RoutingAlg ManyToManySearch(const std::vector &phantom_nodes, const std::vector &source_indices, const std::vector &target_indices) const final override; - + std::vector ManyToManyDurations(const std::vector &phantom_nodes, - const std::vector &source_indices, - const std::vector &target_indices) const final override; + const std::vector &source_indices, + const std::vector &target_indices) const final override; routing_algorithms::SubMatchingList MapMatching( const routing_algorithms::CandidateLists &candidates_list, @@ -177,11 +177,11 @@ std::vector RoutingAlgorithms::ManyToManyDurations( std::vector table = routing_algorithms::manyToManySearch( heaps, facade, phantom_nodes, source_indices, target_indices); std::vector durations; - std::transform(table.begin(), - table.end(), - std::back_inserter(durations), - [](const RoutingPayload& e) { return e.duration; }); - return durations; + std::transform(table.begin(), + table.end(), + std::back_inserter(durations), + [](const RoutingPayload &e) { return e.duration; }); + return durations; } template @@ -238,8 +238,8 @@ RoutingAlgorithms::ManyToManySearch(const std::vector inline std::vector RoutingAlgorithms::ManyToManyDurations(const std::vector &, - const std::vector &, - const std::vector &) const + const std::vector &, + const std::vector &) const { throw util::exception("ManyToManySearch is not implemented"); } diff --git a/include/engine/search_engine_data.hpp b/include/engine/search_engine_data.hpp index 1a557888187..ca48a1ba7f3 100644 --- a/include/engine/search_engine_data.hpp +++ b/include/engine/search_engine_data.hpp @@ -4,8 +4,8 @@ #include #include "util/binary_heap.hpp" -#include "util/typedefs.hpp" #include "util/payload.hpp" +#include "util/typedefs.hpp" namespace osrm { diff --git a/include/extractor/compressed_edge_container.hpp b/include/extractor/compressed_edge_container.hpp index 3effc726981..5e190a32c70 100644 --- a/include/extractor/compressed_edge_container.hpp +++ b/include/extractor/compressed_edge_container.hpp @@ -1,8 +1,8 @@ #ifndef GEOMETRY_COMPRESSOR_HPP_ #define GEOMETRY_COMPRESSOR_HPP_ -#include "util/typedefs.hpp" #include "util/payload.hpp" +#include "util/typedefs.hpp" #include @@ -20,8 +20,8 @@ class CompressedEdgeContainer struct OnewayCompressedEdge { public: - NodeID node_id; // refers to an internal node-based-node - EdgeWeight weight; // the weight of the edge leading to this node + NodeID node_id; // refers to an internal node-based-node + EdgeWeight weight; // the weight of the edge leading to this node UncompressedEdgePayload payload; // the payload of the edge leading to this node }; @@ -34,13 +34,13 @@ class CompressedEdgeContainer const NodeID target_node, const EdgeWeight weight1, const EdgeWeight weight2, - const UncompressedEdgePayload & payload1, - const UncompressedEdgePayload & payload2); + const UncompressedEdgePayload &payload1, + const UncompressedEdgePayload &payload2); void AddUncompressedEdge(const EdgeID edge_id, const NodeID target_node, const EdgeWeight weight, - const UncompressedEdgePayload & payload); + const UncompressedEdgePayload &payload); void InitializeBothwayVector(); unsigned ZipEdges(const unsigned f_edge_pos, const unsigned r_edge_pos); diff --git a/include/extractor/edge_based_edge.hpp b/include/extractor/edge_based_edge.hpp index 14ea5728be3..abfa327198c 100644 --- a/include/extractor/edge_based_edge.hpp +++ b/include/extractor/edge_based_edge.hpp @@ -2,8 +2,8 @@ #define EDGE_BASED_EDGE_HPP #include "extractor/travel_mode.hpp" -#include "util/typedefs.hpp" #include "util/payload.hpp" +#include "util/typedefs.hpp" #include namespace osrm @@ -22,7 +22,7 @@ struct EdgeBasedEdge const NodeID target, const NodeID edge_id, const EdgeWeight weight, - const EdgePayload & payload, + const EdgePayload &payload, const bool forward, const bool backward); @@ -37,11 +37,11 @@ struct EdgeBasedEdge EdgeData(const NodeID edge_id, const EdgeWeight weight, - const EdgePayload & payload, + const EdgePayload &payload, const bool forward, const bool backward) - : edge_id(edge_id), weight(weight), forward(forward), - backward(backward), payload(payload) + : edge_id(edge_id), weight(weight), forward(forward), backward(backward), + payload(payload) { } @@ -67,7 +67,7 @@ inline EdgeBasedEdge::EdgeBasedEdge(const NodeID source, const NodeID target, const NodeID edge_id, const EdgeWeight weight, - const EdgePayload & payload, + const EdgePayload &payload, const bool forward, const bool backward) : source(source), target(target), data{edge_id, weight, payload, forward, backward} diff --git a/include/extractor/node_based_edge.hpp b/include/extractor/node_based_edge.hpp index 1e0ff4b9ffe..78bac99da2b 100644 --- a/include/extractor/node_based_edge.hpp +++ b/include/extractor/node_based_edge.hpp @@ -2,8 +2,8 @@ #define NODE_BASED_EDGE_HPP #include "extractor/travel_mode.hpp" -#include "util/typedefs.hpp" #include "util/payload.hpp" +#include "util/typedefs.hpp" #include "extractor/guidance/road_classification.hpp" @@ -20,7 +20,7 @@ struct NodeBasedEdge NodeID target, NodeID name_id, EdgeWeight weight, - const EdgePayload & payload, + const EdgePayload &payload, bool forward, bool backward, bool roundabout, @@ -38,7 +38,7 @@ struct NodeBasedEdge NodeID target; // 32 4 NodeID name_id; // 32 4 EdgeWeight weight; // 32 4 - EdgePayload payload; // + EdgePayload payload; // std::uint8_t forward : 1; // 1 std::uint8_t backward : 1; // 1 std::uint8_t roundabout : 1; // 1 @@ -57,7 +57,7 @@ struct NodeBasedEdgeWithOSM : NodeBasedEdge OSMNodeID target, NodeID name_id, EdgeWeight weight, - const EdgePayload & payload, + const EdgePayload &payload, bool forward, bool backward, bool roundabout, @@ -87,7 +87,7 @@ inline NodeBasedEdge::NodeBasedEdge(NodeID source, NodeID target, NodeID name_id, EdgeWeight weight, - const EdgePayload & payload, + const EdgePayload &payload, bool forward, bool backward, bool roundabout, @@ -126,7 +126,7 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM(OSMNodeID source, OSMNodeID target, NodeID name_id, EdgeWeight weight, - const EdgePayload & payload, + const EdgePayload &payload, bool forward, bool backward, bool roundabout, diff --git a/include/server/api/table_parameter_grammar.hpp b/include/server/api/table_parameter_grammar.hpp index 068112566a1..c28feaf883f 100644 --- a/include/server/api/table_parameter_grammar.hpp +++ b/include/server/api/table_parameter_grammar.hpp @@ -48,13 +48,16 @@ struct TableParametersGrammar final : public BaseParametersGrammar - (output_component % ';')[ph::bind(&engine::api::TableParameters::output_fields, qi::_r1) = qi::_1]; + (output_component % + ';')[ph::bind(&engine::api::TableParameters::output_fields, qi::_r1) = qi::_1]; - table_rule = destinations_rule(qi::_r1) | sources_rule(qi::_r1) | output_fields_rule(qi::_r1); + table_rule = + destinations_rule(qi::_r1) | sources_rule(qi::_r1) | output_fields_rule(qi::_r1); root_rule = BaseGrammar::query_rule(qi::_r1) > -qi::lit(".json") > -('?' > (table_rule(qi::_r1) | BaseGrammar::base_rule(qi::_r1)) % '&'); diff --git a/include/util/node_based_graph.hpp b/include/util/node_based_graph.hpp index 65dfa061adb..07fa2afd99e 100644 --- a/include/util/node_based_graph.hpp +++ b/include/util/node_based_graph.hpp @@ -26,7 +26,7 @@ struct NodeBasedEdgeData } NodeBasedEdgeData(EdgeWeight weight, - const EdgePayload & payload, + const EdgePayload &payload, unsigned edge_id, unsigned name_id, bool reversed, @@ -36,8 +36,8 @@ struct NodeBasedEdgeData bool restricted, extractor::TravelMode travel_mode, const LaneDescriptionID lane_description_id) - : weight(weight), payload(payload), edge_id(edge_id), name_id(name_id), - reversed(reversed), roundabout(roundabout), circular(circular), startpoint(startpoint), + : weight(weight), payload(payload), edge_id(edge_id), name_id(name_id), reversed(reversed), + roundabout(roundabout), circular(circular), startpoint(startpoint), restricted(restricted), travel_mode(travel_mode), lane_description_id(lane_description_id) { } diff --git a/include/util/payload.hpp b/include/util/payload.hpp index 2b09a0fb99b..c8d77e5a45d 100644 --- a/include/util/payload.hpp +++ b/include/util/payload.hpp @@ -30,90 +30,90 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "util/typedefs.hpp" -struct DurationDistancePayload +struct DurationDistancePayload { EdgeWeight duration; EdgeDistance distance; - - DurationDistancePayload(const EdgeWeight & duration, const EdgeDistance & distance) : duration(duration), distance(distance) {} + + DurationDistancePayload(const EdgeWeight &duration, const EdgeDistance &distance) + : duration(duration), distance(distance) + { + } DurationDistancePayload() : duration(0), distance(0) {} - + bool operator==(const DurationDistancePayload &right) const { return duration == right.duration && distance == right.distance; } - + bool operator<(const DurationDistancePayload &right) const { - return duration < right.duration || (duration == right.duration && distance < right.distance); + return duration < right.duration || + (duration == right.duration && distance < right.distance); } - - DurationDistancePayload & operator+=(const DurationDistancePayload &right) + + DurationDistancePayload &operator+=(const DurationDistancePayload &right) { duration += right.duration; distance += right.distance; return *this; } - - DurationDistancePayload operator-() const - { + + DurationDistancePayload operator-() const + { return DurationDistancePayload(-duration, -distance); - } + } }; -inline DurationDistancePayload operator+(const DurationDistancePayload& lhs, const DurationDistancePayload& rhs) +inline DurationDistancePayload operator+(const DurationDistancePayload &lhs, + const DurationDistancePayload &rhs) { - return DurationDistancePayload(lhs.duration + rhs.duration, lhs.distance + rhs.distance); + return DurationDistancePayload(lhs.duration + rhs.duration, lhs.distance + rhs.distance); } -static_assert(sizeof(DurationDistancePayload) == 8, "DurationDistancePayload is larger than expected"); +static_assert(sizeof(DurationDistancePayload) == 8, + "DurationDistancePayload is larger than expected"); -struct DurationPayload +struct DurationPayload { EdgeWeight duration; - - DurationPayload(const DurationDistancePayload & other) : DurationPayload(other.duration) {} - DurationPayload(const EdgeWeight & duration, const EdgeDistance & distance) : DurationPayload(duration) { (void)distance; } - DurationPayload(const EdgeWeight & duration) : duration(duration) {} - DurationPayload() : duration(0) {} - - bool operator==(const DurationPayload &right) const - { - return duration == right.duration; - } - - bool operator<(const DurationPayload &right) const + + DurationPayload(const DurationDistancePayload &other) : DurationPayload(other.duration) {} + DurationPayload(const EdgeWeight &duration, const EdgeDistance &distance) + : DurationPayload(duration) { - return duration < right.duration; + (void)distance; } - - DurationPayload & operator+=(const DurationPayload &right) + DurationPayload(const EdgeWeight &duration) : duration(duration) {} + DurationPayload() : duration(0) {} + + bool operator==(const DurationPayload &right) const { return duration == right.duration; } + + bool operator<(const DurationPayload &right) const { return duration < right.duration; } + + DurationPayload &operator+=(const DurationPayload &right) { duration += right.duration; return *this; } - - DurationPayload operator-() const - { - return DurationPayload(-duration); - } + + DurationPayload operator-() const { return DurationPayload(-duration); } }; -inline DurationPayload operator+(const DurationPayload& lhs, const DurationPayload& rhs) +inline DurationPayload operator+(const DurationPayload &lhs, const DurationPayload &rhs) { - return DurationPayload(lhs.duration + rhs.duration); + return DurationPayload(lhs.duration + rhs.duration); } static_assert(sizeof(DurationPayload) == 4, "DurationPayload is larger than expected"); - ////////////////////////////////////////////////////// #ifdef PAYLOAD_TYPE_DURATIONS_AND_DISTANCES using EdgePayload = DurationDistancePayload; using UncompressedEdgePayload = DurationPayload; using RoutingPayload = DurationDistancePayload; -#else //PAYLOAD_TYPE_DURATIONS +#else // PAYLOAD_TYPE_DURATIONS using EdgePayload = DurationPayload; using UncompressedEdgePayload = DurationPayload; using RoutingPayload = DurationPayload; @@ -129,8 +129,9 @@ static inline RoutingPayload MAKE_ROUTING_PAYLOAD(EdgeWeight duration, EdgeDista return RoutingPayload(duration, distance); } - -static const EdgePayload INVALID_PAYLOAD = MAKE_PAYLOAD(MAXIMAL_EDGE_DURATION, MAXIMAL_EDGE_DISTANCE); -static const RoutingPayload INVALID_RPAYLOAD = MAKE_ROUTING_PAYLOAD(MAXIMAL_EDGE_DURATION, MAXIMAL_EDGE_DISTANCE); +static const EdgePayload INVALID_PAYLOAD = + MAKE_PAYLOAD(MAXIMAL_EDGE_DURATION, MAXIMAL_EDGE_DISTANCE); +static const RoutingPayload INVALID_RPAYLOAD = + MAKE_ROUTING_PAYLOAD(MAXIMAL_EDGE_DURATION, MAXIMAL_EDGE_DISTANCE); #endif /* PAYLOAD_H */ \ No newline at end of file diff --git a/include/util/typedefs.hpp b/include/util/typedefs.hpp index 5fa0baaa60e..480a9ed2ae4 100644 --- a/include/util/typedefs.hpp +++ b/include/util/typedefs.hpp @@ -86,7 +86,7 @@ static const EdgeID SPECIAL_EDGEID = std::numeric_limits::max(); static const NameID INVALID_NAMEID = std::numeric_limits::max(); static const NameID EMPTY_NAMEID = 0; static const unsigned INVALID_COMPONENTID = 0; -static const EdgeWeight INVALID_EDGE_WEIGHT = (1 << 29) - 1;//TODO: Discuss! +static const EdgeWeight INVALID_EDGE_WEIGHT = (1 << 29) - 1; // TODO: Discuss! static const EdgeWeight MAXIMAL_EDGE_DURATION = std::numeric_limits::max(); static const EdgeDistance MAXIMAL_EDGE_DISTANCE = std::numeric_limits::infinity(); static const TurnPenalty INVALID_TURN_PENALTY = std::numeric_limits::max(); diff --git a/src/engine/routing_algorithms/many_to_many.cpp b/src/engine/routing_algorithms/many_to_many.cpp index 8b6be5dca54..0f14247646c 100644 --- a/src/engine/routing_algorithms/many_to_many.cpp +++ b/src/engine/routing_algorithms/many_to_many.cpp @@ -24,7 +24,7 @@ struct NodeBucket unsigned target_id; // essentially a row in the weight matrix EdgeWeight weight; RoutingPayload payload; - NodeBucket(const unsigned target_id, const EdgeWeight weight, const RoutingPayload & payload) + NodeBucket(const unsigned target_id, const EdgeWeight weight, const RoutingPayload &payload) : target_id(target_id), weight(weight), payload(payload) { } @@ -37,7 +37,7 @@ template void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade &facade, const NodeID node, const EdgeWeight weight, - const RoutingPayload & payload, + const RoutingPayload &payload, ManyToManyQueryHeap &query_heap) { for (auto edge : facade.GetAdjacentEdgeRange(node)) @@ -47,7 +47,7 @@ void relaxOutgoingEdges(const datafacade::ContiguousInternalMemoryDataFacade 0, "edge_weight invalid"); const EdgeWeight to_weight = weight + edge_weight; @@ -79,7 +79,7 @@ void forwardRoutingStep(const datafacade::ContiguousInternalMemoryDataFacade(edge_data1.weight + weight_penalty); - auto duration = - boost::numeric_cast(edge_data1.payload.duration + duration_penalty); + auto duration = boost::numeric_cast(edge_data1.payload.duration + + duration_penalty); EdgePayload payload = edge_data1.payload; payload.duration = duration; m_edge_based_edge_list.emplace_back(edge_data1.edge_id, diff --git a/src/extractor/extraction_containers.cpp b/src/extractor/extraction_containers.cpp index f57709293fc..0f11ab7b008 100644 --- a/src/extractor/extraction_containers.cpp +++ b/src/extractor/extraction_containers.cpp @@ -402,8 +402,8 @@ void ExtractionContainers::PrepareEdges(ScriptingEnvironment &scripting_environm auto &edge = edge_iterator->result; edge.weight = std::max(1, std::round(extracted_segment.weight * weight_multiplier)); - edge.payload = MAKE_PAYLOAD(std::max(1, - std::round(extracted_segment.duration * 10.)), distance); + edge.payload = MAKE_PAYLOAD( + std::max(1, std::round(extracted_segment.duration * 10.)), distance); // assign new node id auto id_iter = external_to_internal_node_id_map.find(node_iterator->node_id); @@ -469,10 +469,8 @@ void ExtractionContainers::PrepareEdges(ScriptingEnvironment &scripting_environm NodeID source = all_edges_list[i].result.source; NodeID target = all_edges_list[i].result.target; - auto min_forward = std::make_pair(std::numeric_limits::max(), - INVALID_PAYLOAD); - auto min_backward = std::make_pair(std::numeric_limits::max(), - INVALID_PAYLOAD); + auto min_forward = std::make_pair(std::numeric_limits::max(), INVALID_PAYLOAD); + auto min_backward = std::make_pair(std::numeric_limits::max(), INVALID_PAYLOAD); std::size_t min_forward_idx = std::numeric_limits::max(); std::size_t min_backward_idx = std::numeric_limits::max(); diff --git a/src/extractor/graph_compressor.cpp b/src/extractor/graph_compressor.cpp index e7bf69c2992..dd5819728b7 100644 --- a/src/extractor/graph_compressor.cpp +++ b/src/extractor/graph_compressor.cpp @@ -122,16 +122,16 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, // Get weights before graph is modified const EdgeWeight forward_weight1 = fwd_edge_data1.weight; const EdgeWeight forward_weight2 = fwd_edge_data2.weight; - const EdgePayload & forward_payload1 = fwd_edge_data1.payload; - const EdgePayload & forward_payload2 = fwd_edge_data2.payload; + const EdgePayload &forward_payload1 = fwd_edge_data1.payload; + const EdgePayload &forward_payload2 = fwd_edge_data2.payload; BOOST_ASSERT(0 != forward_weight1); BOOST_ASSERT(0 != forward_weight2); const EdgeWeight reverse_weight1 = rev_edge_data1.weight; const EdgeWeight reverse_weight2 = rev_edge_data2.weight; - const EdgePayload & reverse_payload1 = rev_edge_data1.payload; - const EdgePayload & reverse_payload2 = rev_edge_data2.payload; + const EdgePayload &reverse_payload1 = rev_edge_data1.payload; + const EdgePayload &reverse_payload2 = rev_edge_data2.payload; BOOST_ASSERT(0 != reverse_weight1); BOOST_ASSERT(0 != reverse_weight2); @@ -142,7 +142,7 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, // add payload of e2's to e1 graph.GetEdgeData(forward_e1).payload += forward_payload2; - graph.GetEdgeData(reverse_e1).payload += reverse_payload2; + graph.GetEdgeData(reverse_e1).payload += reverse_payload2; // extend e1's to targets of e2's graph.SetTarget(forward_e1, node_w); @@ -235,7 +235,8 @@ void GraphCompressor::Compress(const std::unordered_set &barrier_nodes, { const EdgeData &data = graph.GetEdgeData(edge_id); const NodeID target = graph.GetTarget(edge_id); - geometry_compressor.AddUncompressedEdge(edge_id, target, data.weight, UncompressedEdgePayload(data.payload)); + geometry_compressor.AddUncompressedEdge( + edge_id, target, data.weight, UncompressedEdgePayload(data.payload)); } } } From 722a9494e35a67d500422940c480a265d0ad3b52 Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Thu, 9 Mar 2017 14:20:47 +0100 Subject: [PATCH 07/12] Whitespace only: clang encore --- include/engine/routing_algorithms/routing_base.hpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index 2ab9c0dbad1..2f23b80bb27 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -10,8 +10,8 @@ #include "util/coordinate_calculation.hpp" #include "util/guidance/turn_bearing.hpp" -#include "util/typedefs.hpp" #include "util/payload.hpp" +#include "util/typedefs.hpp" #include @@ -202,8 +202,7 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade(facade, node, weight, forward_heap); } -inline -EdgeWeight +inline EdgeWeight getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade &facade, NodeID node) { @@ -224,8 +223,7 @@ getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade &facade, NodeID node) { From 4f73721f69597741696c4fb68669e195ad0c7dd2 Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Fri, 10 Mar 2017 10:19:42 +0100 Subject: [PATCH 08/12] Bugfix: Do not use payload references where one shouldn't... --- src/engine/routing_algorithms/many_to_many.cpp | 2 +- src/extractor/graph_compressor.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/engine/routing_algorithms/many_to_many.cpp b/src/engine/routing_algorithms/many_to_many.cpp index 0f14247646c..8c8dad84f05 100644 --- a/src/engine/routing_algorithms/many_to_many.cpp +++ b/src/engine/routing_algorithms/many_to_many.cpp @@ -79,7 +79,7 @@ void forwardRoutingStep(const datafacade::ContiguousInternalMemoryDataFacade &barrier_nodes, // Get weights before graph is modified const EdgeWeight forward_weight1 = fwd_edge_data1.weight; const EdgeWeight forward_weight2 = fwd_edge_data2.weight; - const EdgePayload &forward_payload1 = fwd_edge_data1.payload; - const EdgePayload &forward_payload2 = fwd_edge_data2.payload; + const EdgePayload forward_payload1 = fwd_edge_data1.payload; + const EdgePayload forward_payload2 = fwd_edge_data2.payload; BOOST_ASSERT(0 != forward_weight1); BOOST_ASSERT(0 != forward_weight2); const EdgeWeight reverse_weight1 = rev_edge_data1.weight; const EdgeWeight reverse_weight2 = rev_edge_data2.weight; - const EdgePayload &reverse_payload1 = rev_edge_data1.payload; - const EdgePayload &reverse_payload2 = rev_edge_data2.payload; + const EdgePayload reverse_payload1 = rev_edge_data1.payload; + const EdgePayload reverse_payload2 = rev_edge_data2.payload; BOOST_ASSERT(0 != reverse_weight1); BOOST_ASSERT(0 != reverse_weight2); From 53c2d00497a198238185d0026f631cd1535ce368 Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Fri, 10 Mar 2017 13:04:55 +0100 Subject: [PATCH 09/12] Payloads can now get initialized with generator functions. Moved distance calculation in GeospatialQuery to generator function to disable it if distances are not required. --- include/engine/geospatial_query.hpp | 75 ++++++++++++++++++----------- include/util/payload.hpp | 33 ++++++++++++- 2 files changed, 79 insertions(+), 29 deletions(-) diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index 36ea7626da3..6339c97be62 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -373,10 +374,6 @@ template class GeospatialQuery EdgeWeight reverse_weight_offset = 0, reverse_weight = 0; EdgeWeight forward_duration_offset = 0, forward_duration = 0; EdgeWeight reverse_duration_offset = 0, reverse_duration = 0; - EdgeDistance forward_distance = EdgeDistance(); - EdgeDistance reverse_distance = EdgeDistance(); - EdgeDistance forward_distance_offset = EdgeDistance(); - EdgeDistance reverse_distance_offset = EdgeDistance(); const std::vector forward_weight_vector = datafacade.GetUncompressedForwardWeights(data.packed_geometry_id); @@ -386,25 +383,14 @@ template class GeospatialQuery datafacade.GetUncompressedForwardDurations(data.packed_geometry_id); const std::vector reverse_duration_vector = datafacade.GetUncompressedReverseDurations(data.packed_geometry_id); - const std::vector forward_node_vector = - datafacade.GetUncompressedForwardGeometry(data.packed_geometry_id); - const std::vector reverse_node_vector = - datafacade.GetUncompressedReverseGeometry(data.packed_geometry_id); for (std::size_t i = 0; i < data.fwd_segment_position; i++) { forward_weight_offset += forward_weight_vector[i]; forward_duration_offset += forward_duration_vector[i]; - - auto c1 = coordinates[forward_node_vector[i]]; - auto c2 = coordinates[forward_node_vector[i + 1]]; - forward_distance_offset += util::coordinate_calculation::greatCircleDistance(c1, c2); } forward_weight = forward_weight_vector[data.fwd_segment_position]; forward_duration = forward_duration_vector[data.fwd_segment_position]; - forward_distance = util::coordinate_calculation::greatCircleDistance( - coordinates[forward_node_vector[data.fwd_segment_position]], - coordinates[forward_node_vector[data.fwd_segment_position + 1]]); BOOST_ASSERT(data.fwd_segment_position < reverse_weight_vector.size()); @@ -414,31 +400,32 @@ template class GeospatialQuery { reverse_weight_offset += reverse_weight_vector[i]; reverse_duration_offset += reverse_duration_vector[i]; - - auto c1 = coordinates[reverse_node_vector[i]]; - auto c2 = coordinates[reverse_node_vector[i + 1]]; - reverse_distance_offset += util::coordinate_calculation::greatCircleDistance(c1, c2); } reverse_weight = reverse_weight_vector[reverse_segment_position]; reverse_duration = reverse_duration_vector[reverse_segment_position]; - reverse_distance = util::coordinate_calculation::greatCircleDistance( - coordinates[reverse_node_vector[reverse_segment_position]], - coordinates[reverse_node_vector[reverse_segment_position + 1]]); ratio = std::min(1.0, std::max(0.0, ratio)); if (data.forward_segment_id.id != SPECIAL_SEGMENTID) { forward_weight = static_cast(forward_weight * ratio); forward_duration = static_cast(forward_duration * ratio); - forward_distance = static_cast(forward_distance * ratio); } if (data.reverse_segment_id.id != SPECIAL_SEGMENTID) { reverse_weight -= static_cast(reverse_weight * ratio); reverse_duration -= static_cast(reverse_duration * ratio); - reverse_distance -= static_cast(reverse_distance * ratio); } + auto identity_functor = [](EdgeWeight d) -> EdgeWeight { return d; }; + std::function provide_forward_duration = + std::bind(identity_functor, forward_duration_offset + forward_duration); + std::function provide_reverse_duration = + std::bind(identity_functor, reverse_duration_offset + reverse_duration); + std::function provide_forward_distance = + std::bind(&GeospatialQuery::CalculateDistance, this, data, ratio); + std::function provide_reverse_distance = + std::bind(&GeospatialQuery::CalculateDistance, this, data, ratio); + auto transformed = PhantomNodeWithDistance{ PhantomNode{data, forward_weight, @@ -447,10 +434,8 @@ template class GeospatialQuery reverse_weight_offset, forward_duration, reverse_duration, - MAKE_PAYLOAD(forward_duration_offset + forward_duration, - forward_distance_offset + forward_distance), - MAKE_PAYLOAD(reverse_duration_offset + reverse_duration, - reverse_distance_offset + reverse_distance), + MAKE_PAYLOAD(provide_forward_duration, provide_forward_distance), + MAKE_PAYLOAD(provide_reverse_duration, provide_reverse_distance), point_on_segment, input_coordinate}, current_perpendicular_distance}; @@ -458,6 +443,40 @@ template class GeospatialQuery return transformed; } + template EdgeDistance CalculateDistance(const EdgeData &data, double ratio) const + { + const std::vector node_vector = + reverse ? datafacade.GetUncompressedReverseGeometry(data.packed_geometry_id) + : datafacade.GetUncompressedForwardGeometry(data.packed_geometry_id); + + EdgeDistance distance = EdgeDistance(); + EdgeDistance distance_offset = EdgeDistance(); + + const std::size_t limit = reverse ? node_vector.size() - data.fwd_segment_position - 2 + : data.fwd_segment_position; + BOOST_ASSERT(limit >= 0 && limit < node_vector.size() - 1); + + for (std::size_t i = 0; i < limit; i++) + { + distance_offset += util::coordinate_calculation::greatCircleDistance( + coordinates[node_vector[i]], coordinates[node_vector[i + 1]]); + } + + distance = util::coordinate_calculation::greatCircleDistance( + coordinates[node_vector[limit]], coordinates[node_vector[limit + 1]]); + + if (!reverse && data.forward_segment_id.id != SPECIAL_SEGMENTID) + { + distance = static_cast(distance * ratio); + } + if (reverse && data.reverse_segment_id.id != SPECIAL_SEGMENTID) + { + distance -= static_cast(distance * ratio); + } + + return distance_offset + distance; + } + bool CheckSegmentDistance(const Coordinate input_coordinate, const CandidateSegment &segment, const double max_distance) const diff --git a/include/util/payload.hpp b/include/util/payload.hpp index c8d77e5a45d..f23080fae29 100644 --- a/include/util/payload.hpp +++ b/include/util/payload.hpp @@ -109,19 +109,50 @@ static_assert(sizeof(DurationPayload) == 4, "DurationPayload is larger than expe ////////////////////////////////////////////////////// +using DurationProviderFunction = std::function; +using DistanceProviderFunction = std::function; + #ifdef PAYLOAD_TYPE_DURATIONS_AND_DISTANCES using EdgePayload = DurationDistancePayload; using UncompressedEdgePayload = DurationPayload; using RoutingPayload = DurationDistancePayload; + +static inline EdgePayload MAKE_PAYLOAD(DurationProviderFunction duration_gen, + DistanceProviderFunction distance_gen) +{ + return DurationDistancePayload(duration_gen(), distance_gen()); +} + +static inline RoutingPayload MAKE_ROUTING_PAYLOAD(DurationProviderFunction duration_gen, + DistanceProviderFunction distance_gen) +{ + return DurationDistancePayload(duration_gen(), distance_gen()); +} + #else // PAYLOAD_TYPE_DURATIONS using EdgePayload = DurationPayload; using UncompressedEdgePayload = DurationPayload; using RoutingPayload = DurationPayload; + +static inline EdgePayload MAKE_PAYLOAD(DurationProviderFunction duration_gen, + DistanceProviderFunction distance_gen) +{ + (void)distance_gen; + return DurationPayload(duration_gen()); +} + +static inline RoutingPayload MAKE_ROUTING_PAYLOAD(DurationProviderFunction duration_gen, + DistanceProviderFunction distance_gen) +{ + (void)distance_gen; + return DurationPayload(duration_gen()); +} + #endif static inline EdgePayload MAKE_PAYLOAD(EdgeWeight duration, EdgeDistance distance) { - return DurationDistancePayload(duration, distance); + return EdgePayload(duration, distance); } static inline RoutingPayload MAKE_ROUTING_PAYLOAD(EdgeWeight duration, EdgeDistance distance) From 15f0592ccc22034efdc54bf6934e22669b843453 Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Fri, 10 Mar 2017 14:23:51 +0100 Subject: [PATCH 10/12] Version bump from 'v1' to 'v2' in NodeJS --- features/support/route.js | 2 +- features/testbot/status.feature | 32 ++++++++++++++++---------------- scripts/poly2req.js | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/features/support/route.js b/features/support/route.js index e3c714bf566..19ffb4170bb 100644 --- a/features/support/route.js +++ b/features/support/route.js @@ -10,7 +10,7 @@ module.exports = function () { if (service == 'timestamp') { uri = [this.HOST, service].join('/'); } else { - uri = [this.HOST, service, 'v1', this.profile].join('/'); + uri = [this.HOST, service, 'v2', this.profile].join('/'); } return this.sendRequest(uri, params, callback); diff --git a/features/testbot/status.feature b/features/testbot/status.feature index 6320924e650..04614cf7392 100644 --- a/features/testbot/status.feature +++ b/features/testbot/status.feature @@ -51,23 +51,23 @@ Feature: Status messages When I route I should get | request | status | message | - | route/v1/driving/1,1;1,2 | 200 | | - | route/v1/driving/-74697224,5.191564 | 400 | Query string malformed close to position 18 | - | route/v1/driving/200,5.191564;44,5 | 400 | Invalid coordinate value. | + | route/v2/driving/1,1;1,2 | 200 | | + | route/v2/driving/-74697224,5.191564 | 400 | Query string malformed close to position 18 | + | route/v2/driving/200,5.191564;44,5 | 400 | Invalid coordinate value. | | nonsense | 400 | URL string malformed close to position 9: "nse" | - | nonsense/v1/driving/1,1;1,2 | 400 | Service nonsense not found! | + | nonsense/v2/driving/1,1;1,2 | 400 | Service nonsense not found! | | | 400 | URL string malformed close to position 1: "/" | | / | 400 | URL string malformed close to position 1: "//" | | ? | 400 | URL string malformed close to position 1: "/?" | - | route/v1/driving | 400 | URL string malformed close to position 17: "ing" | - | route/v1/driving/ | 400 | URL string malformed close to position 18: "ng/" | - | route/v1/driving/1 | 400 | Query string malformed close to position 19 | - | route/v1/driving/1,1 | 400 | Number of coordinates needs to be at least two. | - | route/v1/driving/1,1,1 | 400 | Query string malformed close to position 21 | - | route/v1/driving/x | 400 | Query string malformed close to position 18 | - | route/v1/driving/x,y | 400 | Query string malformed close to position 18 | - | route/v1/driving/1,1; | 400 | Query string malformed close to position 21 | - | route/v1/driving/1,1;1 | 400 | Query string malformed close to position 23 | - | route/v1/driving/1,1;1,1,1 | 400 | Query string malformed close to position 25 | - | route/v1/driving/1,1;x | 400 | Query string malformed close to position 21 | - | route/v1/driving/1,1;x,y | 400 | Query string malformed close to position 21 | + | route/v2/driving | 400 | URL string malformed close to position 17: "ing" | + | route/v2/driving/ | 400 | URL string malformed close to position 18: "ng/" | + | route/v2/driving/1 | 400 | Query string malformed close to position 19 | + | route/v2/driving/1,1 | 400 | Number of coordinates needs to be at least two. | + | route/v2/driving/1,1,1 | 400 | Query string malformed close to position 21 | + | route/v2/driving/x | 400 | Query string malformed close to position 18 | + | route/v2/driving/x,y | 400 | Query string malformed close to position 18 | + | route/v2/driving/1,1; | 400 | Query string malformed close to position 21 | + | route/v2/driving/1,1;1 | 400 | Query string malformed close to position 23 | + | route/v2/driving/1,1;1,1,1 | 400 | Query string malformed close to position 25 | + | route/v2/driving/1,1;x | 400 | Query string malformed close to position 21 | + | route/v2/driving/1,1;x,y | 400 | Query string malformed close to position 21 | diff --git a/scripts/poly2req.js b/scripts/poly2req.js index 369e8a91ede..23569d6b842 100755 --- a/scripts/poly2req.js +++ b/scripts/poly2req.js @@ -10,9 +10,9 @@ let NUM_REQUEST = 1000; let NUM_COORDS = 2; let PORT = 5000; let url_templates = { - "route_5.0": "http://127.0.0.1:{port}/route/v1/driving/{coords}?steps=false&alternatives=false", + "route_5.0": "http://127.0.0.1:{port}/route/v2/driving/{coords}?steps=false&alternatives=false", "route_4.9": "http://127.0.0.1:{port}/viaroute?{coords}&instructions=false&alt=false", - "table_5.0": "http://127.0.0.1:{port}/table/v1/driving/{coords}", + "table_5.0": "http://127.0.0.1:{port}/table/v2/driving/{coords}", "table_4.9": "http://127.0.0.1:{port}/table?{coords}" }; From 5dbc41daa822d4d6b20ab051eaecbcac275f0bb7 Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Fri, 10 Mar 2017 15:59:39 +0100 Subject: [PATCH 11/12] Fixed strongly connected component detection in trip service (By using the 'right' constant MAXIMAL_EDGE_DURATION instead of INVALID_EDGE_WEIGHT). --- src/engine/plugins/trip.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/plugins/trip.cpp b/src/engine/plugins/trip.cpp index f6374102ee8..943f5bb73e2 100644 --- a/src/engine/plugins/trip.cpp +++ b/src/engine/plugins/trip.cpp @@ -28,7 +28,7 @@ namespace plugins bool IsStronglyConnectedComponent(const util::DistTableWrapper &result_table) { - return std::find(std::begin(result_table), std::end(result_table), INVALID_EDGE_WEIGHT) == + return std::find(std::begin(result_table), std::end(result_table), MAXIMAL_EDGE_DURATION) == std::end(result_table); } From 37ad241b77166e19a32d413f6c55b6a9fb3f144c Mon Sep 17 00:00:00 2001 From: Martin Niemeier Date: Mon, 20 Mar 2017 11:01:44 +0100 Subject: [PATCH 12/12] Formatting only: Restored clang formatting that broke during the last merge with master. --- include/engine/routing_algorithms/routing_base.hpp | 6 ++++-- include/engine/routing_algorithms/routing_base_ch.hpp | 6 ++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index f97d3fb1fcb..ec61cf48250 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -70,14 +70,16 @@ void insertNodesInHeap(SearchEngineData::ManyToManyQueryHeap &heap, const Phanto heap.Insert( phantom_node.forward_segment_id.id, weight_sign * phantom_node.GetForwardWeightPlusOffset(), - {phantom_node.forward_segment_id.id, forward ? -phantom_node.GetForwardPayload() : phantom_node.GetForwardPayload()}); + {phantom_node.forward_segment_id.id, + forward ? -phantom_node.GetForwardPayload() : phantom_node.GetForwardPayload()}); } if (phantom_node.reverse_segment_id.enabled) { heap.Insert( phantom_node.reverse_segment_id.id, weight_sign * phantom_node.GetReverseWeightPlusOffset(), - {phantom_node.reverse_segment_id.id, forward ? -phantom_node.GetReversePayload() : phantom_node.GetReversePayload()}); + {phantom_node.reverse_segment_id.id, + forward ? -phantom_node.GetReversePayload() : phantom_node.GetReversePayload()}); } } diff --git a/include/engine/routing_algorithms/routing_base_ch.hpp b/include/engine/routing_algorithms/routing_base_ch.hpp index 37411a13695..aa0d5036783 100644 --- a/include/engine/routing_algorithms/routing_base_ch.hpp +++ b/include/engine/routing_algorithms/routing_base_ch.hpp @@ -185,8 +185,7 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade(facade, node, weight, forward_heap); } -inline -EdgeWeight +inline EdgeWeight getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade &facade, NodeID node) { @@ -207,8 +206,7 @@ getLoopWeight(const datafacade::ContiguousInternalMemoryDataFacade &facade, NodeID node) {