From 5b57dca90aa27adc4e491494d1235717207a04db Mon Sep 17 00:00:00 2001 From: jcoupey Date: Wed, 18 May 2022 14:14:33 +0200 Subject: [PATCH 1/7] Build with NDEBUG. --- src/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/makefile b/src/makefile index 30aa89cc4..adfbe7f05 100644 --- a/src/makefile +++ b/src/makefile @@ -6,7 +6,7 @@ # Variables. CXX ?= g++ USE_ROUTING ?= true -CXXFLAGS = -MMD -MP -I. -std=c++17 -Wextra -Wpedantic -Wall -O3 -DASIO_STANDALONE -DUSE_ROUTING=$(USE_ROUTING) +CXXFLAGS = -MMD -MP -I. -std=c++17 -Wextra -Wpedantic -Wall -O3 -DASIO_STANDALONE -DUSE_ROUTING=$(USE_ROUTING) -DNDEBUG LDLIBS = -lpthread # Using all cpp files in current directory. From 4195cf62e5af70fa2a533eea6d0a16605502cf1c Mon Sep 17 00:00:00 2001 From: jcoupey Date: Wed, 18 May 2022 14:16:39 +0200 Subject: [PATCH 2/7] Bump version number for rc.1. --- CHANGELOG.md | 2 +- src/utils/version.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdf36033f..72b3c6a1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [Unreleased] +## [v1.12.0-rc.1] - 2022-05-18 ### Added diff --git a/src/utils/version.h b/src/utils/version.h index ccf1646bf..7bbf95dbc 100644 --- a/src/utils/version.h +++ b/src/utils/version.h @@ -13,8 +13,8 @@ All rights reserved (see LICENSE). #define MAJOR 1 #define MINOR 12 #define PATCH 0 -#define DEV 1 -#define RC 0 +#define DEV 0 +#define RC 1 #include From d3abd6b22fe4afc0daa64d6b905911999b12dcdd Mon Sep 17 00:00:00 2001 From: jcoupey Date: Tue, 31 May 2022 10:27:20 +0200 Subject: [PATCH 3/7] Bump version for final release. --- CHANGELOG.md | 2 +- src/utils/version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72b3c6a1f..7867494f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [v1.12.0-rc.1] - 2022-05-18 +## [v1.12.0] - 2022-05-31 ### Added diff --git a/src/utils/version.h b/src/utils/version.h index 7bbf95dbc..6bb7dda71 100644 --- a/src/utils/version.h +++ b/src/utils/version.h @@ -14,7 +14,7 @@ All rights reserved (see LICENSE). #define MINOR 12 #define PATCH 0 #define DEV 0 -#define RC 1 +#define RC 0 #include From c4418c8c9f36774a3de89bfc2537efc81b2433c5 Mon Sep 17 00:00:00 2001 From: dhiego Date: Tue, 17 Jan 2023 15:11:34 -0300 Subject: [PATCH 4/7] feat:adding independent geometry for each step --- input.json | 77 ++++++++++++++++++++++++++++ libvroom_examples/libvroom.cpp | 1 + src/routing/http_wrapper.cpp | 14 ++++- src/routing/http_wrapper.h | 5 ++ src/routing/ors_wrapper.cpp | 9 ++++ src/routing/ors_wrapper.h | 6 +++ src/routing/osrm_routed_wrapper.cpp | 12 ++++- src/routing/osrm_routed_wrapper.h | 6 +++ src/routing/valhalla_wrapper.cpp | 10 ++++ src/routing/valhalla_wrapper.h | 7 +++ src/structures/vroom/solution/step.h | 1 + src/utils/output_json.cpp | 7 +++ 12 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 input.json diff --git a/input.json b/input.json new file mode 100644 index 000000000..db35b4305 --- /dev/null +++ b/input.json @@ -0,0 +1,77 @@ +{ + "options": { + "g": true, + "c": false + }, + "jobs": [ + { + "id": 0, + "description": "636d04c8470642cb5a9555cc", + "location": [ + -48.87455813874452,-26.28461496470875 + ], + "service": 60 + }, + { + "id": 1, + "description": "aaaaaaaa", + "location": [ + -48.87750123470842,-26.27487378830072 + ], + "service": 60 + } + ], + "vehicles": [ + { + "id": 1060, + "description": "Adesao 1060", + "start": [ + -48.87589286745765, + -26.27276577714968 + ], + "time_window": [ + 1668078000, + 1668110100 + ], + "time_window_with_break": [ + [ + 1668078000, + 1668092400 + ], + [ + 1668096300, + 1668114000 + ] + ], + "breaks": [], + "steps": [], + "speed_factor": 0.9 + } + , + { + "id": 1030, + "description": "Adesao 1030", + "start": [ + -48.87589286745765, + -26.27276577714968 + ], + "time_window": [ + 1668078000, + 1668110100 + ], + "time_window_with_break": [ + [ + 1668078000, + 1668092400 + ], + [ + 1668096300, + 1668114000 + ] + ], + "breaks": [], + "steps": [], + "speed_factor": 0.9 + } + ] +} diff --git a/libvroom_examples/libvroom.cpp b/libvroom_examples/libvroom.cpp index fa649d948..b286d270f 100644 --- a/libvroom_examples/libvroom.cpp +++ b/libvroom_examples/libvroom.cpp @@ -69,6 +69,7 @@ void log_solution(const vroom::Solution& sol, bool geometry) { std::cout << " - " << step.location.lon() << ";" << step.location.lat(); } + std::cout << " - geometry: " << step.geometry; std::cout << " - arrival: " << step.arrival; std::cout << " - duration: " << step.duration; std::cout << " - service: " << step.service; diff --git a/src/routing/http_wrapper.cpp b/src/routing/http_wrapper.cpp index 0809eb7b4..f0ca08571 100644 --- a/src/routing/http_wrapper.cpp +++ b/src/routing/http_wrapper.cpp @@ -9,8 +9,8 @@ All rights reserved (see LICENSE). #include #include - #include "routing/http_wrapper.h" +#include "../../include/polylineencoder/src/polylineencoder.h" using asio::ip::tcp; @@ -251,8 +251,20 @@ void HttpWrapper::add_route_info(Route& route) const { } } + gepaf::PolylineEncoder<> encoder; + auto nb_steps = get_steps_number(json_result, i); + + for (rapidjson::SizeType s = 0; s < nb_steps; ++s) { + auto polylines = gepaf::PolylineEncoder<>::decode(get_geometry_for_leg(json_result,i, s)); + + for (const auto& p : polylines) { + encoder.addPoint(p.latitude(), p.longitude()); + } + } + sum_distance += next_distance; next_step.distance = round_cost(sum_distance); + next_step.geometry = encoder.encode(); steps_rank += number_breaks_after[i] + 1; } diff --git a/src/routing/http_wrapper.h b/src/routing/http_wrapper.h index d1b99b494..11722f9e3 100644 --- a/src/routing/http_wrapper.h +++ b/src/routing/http_wrapper.h @@ -64,9 +64,14 @@ class HttpWrapper : public Wrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const = 0; + virtual unsigned get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const = 0; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const = 0; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const = 0; + virtual std::string get_geometry(rapidjson::Value& result) const = 0; virtual void add_route_info(Route& route) const override; diff --git a/src/routing/ors_wrapper.cpp b/src/routing/ors_wrapper.cpp index f354dc33e..27f21218e 100644 --- a/src/routing/ors_wrapper.cpp +++ b/src/routing/ors_wrapper.cpp @@ -84,11 +84,20 @@ unsigned OrsWrapper::get_legs_number(const rapidjson::Value& result) const { return result["routes"][0]["segments"].Size(); } +unsigned OrsWrapper::get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const { + return result["routes"][0]["segments"].Size(); +} + double OrsWrapper::get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const { return result["routes"][0]["segments"][i]["distance"].GetDouble(); } +std::string OrsWrapper::get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const { + return result["routes"][0]["legs"][i]["steps"][s]["geometry"].GetString(); +} + std::string OrsWrapper::get_geometry(rapidjson::Value& result) const { return result["routes"][0]["geometry"].GetString(); } diff --git a/src/routing/ors_wrapper.h b/src/routing/ors_wrapper.h index 5d0385815..8588f578e 100644 --- a/src/routing/ors_wrapper.h +++ b/src/routing/ors_wrapper.h @@ -36,9 +36,15 @@ class OrsWrapper : public HttpWrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const override; + virtual unsigned + get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const override; + virtual std::string get_geometry(rapidjson::Value& result) const override; public: diff --git a/src/routing/osrm_routed_wrapper.cpp b/src/routing/osrm_routed_wrapper.cpp index ae8c6dfe6..3f37e037d 100644 --- a/src/routing/osrm_routed_wrapper.cpp +++ b/src/routing/osrm_routed_wrapper.cpp @@ -19,7 +19,7 @@ OsrmRoutedWrapper::OsrmRoutedWrapper(const std::string& profile, "table", "durations", "route", - "alternatives=false&steps=false&overview=full&continue_" + "alternatives=false&steps=true&overview=full&continue_" "straight=false") { } @@ -79,11 +79,21 @@ OsrmRoutedWrapper::get_legs_number(const rapidjson::Value& result) const { return result["routes"][0]["legs"].Size(); } +unsigned +OsrmRoutedWrapper::get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const { + return result["routes"][0]["legs"][i]["steps"].Size(); +} + double OsrmRoutedWrapper::get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const { return result["routes"][0]["legs"][i]["distance"].GetDouble(); } +std::string OsrmRoutedWrapper::get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const { + return result["routes"][0]["legs"][i]["steps"][s]["geometry"].GetString(); +} + std::string OsrmRoutedWrapper::get_geometry(rapidjson::Value& result) const { return result["routes"][0]["geometry"].GetString(); } diff --git a/src/routing/osrm_routed_wrapper.h b/src/routing/osrm_routed_wrapper.h index 14577c944..db1630189 100644 --- a/src/routing/osrm_routed_wrapper.h +++ b/src/routing/osrm_routed_wrapper.h @@ -36,9 +36,15 @@ class OsrmRoutedWrapper : public HttpWrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const override; + virtual unsigned + get_steps_number(const rapidjson::Value& result, rapidjson::SizeType ) const override; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const override; + virtual std::string get_geometry(rapidjson::Value& result) const override; public: diff --git a/src/routing/valhalla_wrapper.cpp b/src/routing/valhalla_wrapper.cpp index 4bd487681..11072c4ad 100644 --- a/src/routing/valhalla_wrapper.cpp +++ b/src/routing/valhalla_wrapper.cpp @@ -139,11 +139,21 @@ ValhallaWrapper::get_legs_number(const rapidjson::Value& result) const { return result["trip"]["legs"].Size(); } +unsigned +ValhallaWrapper::get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const { + return result["trip"]["legs"].Size(); +} + double ValhallaWrapper::get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const { return 1000 * result["trip"]["legs"][i]["summary"]["length"].GetDouble(); } +std::string ValhallaWrapper::get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const { + return result["routes"][0]["legs"][i]["steps"][s]["geometry"].GetString(); +} + std::string ValhallaWrapper::get_geometry(rapidjson::Value& result) const { // Valhalla returns one polyline per route leg so we need to merge // them. Also taking the opportunity to adjust the encoding diff --git a/src/routing/valhalla_wrapper.h b/src/routing/valhalla_wrapper.h index 80022154b..b3c1bc22f 100644 --- a/src/routing/valhalla_wrapper.h +++ b/src/routing/valhalla_wrapper.h @@ -41,9 +41,16 @@ class ValhallaWrapper : public HttpWrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const override; + virtual unsigned + get_steps_number(const rapidjson::Value& result, + rapidjson::SizeType i) const override; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const override; + virtual std::string get_geometry(rapidjson::Value& result) const override; public: diff --git a/src/structures/vroom/solution/step.h b/src/structures/vroom/solution/step.h index f3f6654ea..0835e64d4 100644 --- a/src/structures/vroom/solution/step.h +++ b/src/structures/vroom/solution/step.h @@ -33,6 +33,7 @@ struct Step { Duration duration; Duration waiting_time; Distance distance; + std::string geometry; Violations violations; diff --git a/src/utils/output_json.cpp b/src/utils/output_json.cpp index 7105c8a7a..4baa63788 100644 --- a/src/utils/output_json.cpp +++ b/src/utils/output_json.cpp @@ -315,6 +315,13 @@ rapidjson::Value to_json(const Step& s, } json_step.AddMember("setup", s.setup, allocator); + + if (!s.geometry.empty()) { + json_step.AddMember("geometry", s.setup, allocator); + json_step["geometry"].SetString(s.geometry.c_str(), + s.geometry.size()); + } + json_step.AddMember("service", s.service, allocator); json_step.AddMember("waiting_time", s.waiting_time, allocator); From e471524bf1bc55561aa47919cc541216d3dfd814 Mon Sep 17 00:00:00 2001 From: dhiego Date: Tue, 17 Jan 2023 15:11:34 -0300 Subject: [PATCH 5/7] feat:adding independent geometry for each step --- libvroom_examples/libvroom.cpp | 1 + src/routing/http_wrapper.cpp | 14 +++++++++++++- src/routing/http_wrapper.h | 5 +++++ src/routing/ors_wrapper.cpp | 9 +++++++++ src/routing/ors_wrapper.h | 6 ++++++ src/routing/osrm_routed_wrapper.cpp | 12 +++++++++++- src/routing/osrm_routed_wrapper.h | 6 ++++++ src/routing/valhalla_wrapper.cpp | 10 ++++++++++ src/routing/valhalla_wrapper.h | 7 +++++++ src/structures/vroom/solution/step.h | 1 + src/utils/output_json.cpp | 7 +++++++ 11 files changed, 76 insertions(+), 2 deletions(-) diff --git a/libvroom_examples/libvroom.cpp b/libvroom_examples/libvroom.cpp index fa649d948..b286d270f 100644 --- a/libvroom_examples/libvroom.cpp +++ b/libvroom_examples/libvroom.cpp @@ -69,6 +69,7 @@ void log_solution(const vroom::Solution& sol, bool geometry) { std::cout << " - " << step.location.lon() << ";" << step.location.lat(); } + std::cout << " - geometry: " << step.geometry; std::cout << " - arrival: " << step.arrival; std::cout << " - duration: " << step.duration; std::cout << " - service: " << step.service; diff --git a/src/routing/http_wrapper.cpp b/src/routing/http_wrapper.cpp index 0809eb7b4..f0ca08571 100644 --- a/src/routing/http_wrapper.cpp +++ b/src/routing/http_wrapper.cpp @@ -9,8 +9,8 @@ All rights reserved (see LICENSE). #include #include - #include "routing/http_wrapper.h" +#include "../../include/polylineencoder/src/polylineencoder.h" using asio::ip::tcp; @@ -251,8 +251,20 @@ void HttpWrapper::add_route_info(Route& route) const { } } + gepaf::PolylineEncoder<> encoder; + auto nb_steps = get_steps_number(json_result, i); + + for (rapidjson::SizeType s = 0; s < nb_steps; ++s) { + auto polylines = gepaf::PolylineEncoder<>::decode(get_geometry_for_leg(json_result,i, s)); + + for (const auto& p : polylines) { + encoder.addPoint(p.latitude(), p.longitude()); + } + } + sum_distance += next_distance; next_step.distance = round_cost(sum_distance); + next_step.geometry = encoder.encode(); steps_rank += number_breaks_after[i] + 1; } diff --git a/src/routing/http_wrapper.h b/src/routing/http_wrapper.h index d1b99b494..11722f9e3 100644 --- a/src/routing/http_wrapper.h +++ b/src/routing/http_wrapper.h @@ -64,9 +64,14 @@ class HttpWrapper : public Wrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const = 0; + virtual unsigned get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const = 0; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const = 0; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const = 0; + virtual std::string get_geometry(rapidjson::Value& result) const = 0; virtual void add_route_info(Route& route) const override; diff --git a/src/routing/ors_wrapper.cpp b/src/routing/ors_wrapper.cpp index f354dc33e..27f21218e 100644 --- a/src/routing/ors_wrapper.cpp +++ b/src/routing/ors_wrapper.cpp @@ -84,11 +84,20 @@ unsigned OrsWrapper::get_legs_number(const rapidjson::Value& result) const { return result["routes"][0]["segments"].Size(); } +unsigned OrsWrapper::get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const { + return result["routes"][0]["segments"].Size(); +} + double OrsWrapper::get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const { return result["routes"][0]["segments"][i]["distance"].GetDouble(); } +std::string OrsWrapper::get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const { + return result["routes"][0]["legs"][i]["steps"][s]["geometry"].GetString(); +} + std::string OrsWrapper::get_geometry(rapidjson::Value& result) const { return result["routes"][0]["geometry"].GetString(); } diff --git a/src/routing/ors_wrapper.h b/src/routing/ors_wrapper.h index 5d0385815..8588f578e 100644 --- a/src/routing/ors_wrapper.h +++ b/src/routing/ors_wrapper.h @@ -36,9 +36,15 @@ class OrsWrapper : public HttpWrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const override; + virtual unsigned + get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const override; + virtual std::string get_geometry(rapidjson::Value& result) const override; public: diff --git a/src/routing/osrm_routed_wrapper.cpp b/src/routing/osrm_routed_wrapper.cpp index ae8c6dfe6..3f37e037d 100644 --- a/src/routing/osrm_routed_wrapper.cpp +++ b/src/routing/osrm_routed_wrapper.cpp @@ -19,7 +19,7 @@ OsrmRoutedWrapper::OsrmRoutedWrapper(const std::string& profile, "table", "durations", "route", - "alternatives=false&steps=false&overview=full&continue_" + "alternatives=false&steps=true&overview=full&continue_" "straight=false") { } @@ -79,11 +79,21 @@ OsrmRoutedWrapper::get_legs_number(const rapidjson::Value& result) const { return result["routes"][0]["legs"].Size(); } +unsigned +OsrmRoutedWrapper::get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const { + return result["routes"][0]["legs"][i]["steps"].Size(); +} + double OsrmRoutedWrapper::get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const { return result["routes"][0]["legs"][i]["distance"].GetDouble(); } +std::string OsrmRoutedWrapper::get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const { + return result["routes"][0]["legs"][i]["steps"][s]["geometry"].GetString(); +} + std::string OsrmRoutedWrapper::get_geometry(rapidjson::Value& result) const { return result["routes"][0]["geometry"].GetString(); } diff --git a/src/routing/osrm_routed_wrapper.h b/src/routing/osrm_routed_wrapper.h index 14577c944..db1630189 100644 --- a/src/routing/osrm_routed_wrapper.h +++ b/src/routing/osrm_routed_wrapper.h @@ -36,9 +36,15 @@ class OsrmRoutedWrapper : public HttpWrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const override; + virtual unsigned + get_steps_number(const rapidjson::Value& result, rapidjson::SizeType ) const override; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const override; + virtual std::string get_geometry(rapidjson::Value& result) const override; public: diff --git a/src/routing/valhalla_wrapper.cpp b/src/routing/valhalla_wrapper.cpp index 4bd487681..11072c4ad 100644 --- a/src/routing/valhalla_wrapper.cpp +++ b/src/routing/valhalla_wrapper.cpp @@ -139,11 +139,21 @@ ValhallaWrapper::get_legs_number(const rapidjson::Value& result) const { return result["trip"]["legs"].Size(); } +unsigned +ValhallaWrapper::get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const { + return result["trip"]["legs"].Size(); +} + double ValhallaWrapper::get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const { return 1000 * result["trip"]["legs"][i]["summary"]["length"].GetDouble(); } +std::string ValhallaWrapper::get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const { + return result["routes"][0]["legs"][i]["steps"][s]["geometry"].GetString(); +} + std::string ValhallaWrapper::get_geometry(rapidjson::Value& result) const { // Valhalla returns one polyline per route leg so we need to merge // them. Also taking the opportunity to adjust the encoding diff --git a/src/routing/valhalla_wrapper.h b/src/routing/valhalla_wrapper.h index 80022154b..b3c1bc22f 100644 --- a/src/routing/valhalla_wrapper.h +++ b/src/routing/valhalla_wrapper.h @@ -41,9 +41,16 @@ class ValhallaWrapper : public HttpWrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const override; + virtual unsigned + get_steps_number(const rapidjson::Value& result, + rapidjson::SizeType i) const override; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const override; + virtual std::string get_geometry(rapidjson::Value& result) const override; public: diff --git a/src/structures/vroom/solution/step.h b/src/structures/vroom/solution/step.h index f3f6654ea..0835e64d4 100644 --- a/src/structures/vroom/solution/step.h +++ b/src/structures/vroom/solution/step.h @@ -33,6 +33,7 @@ struct Step { Duration duration; Duration waiting_time; Distance distance; + std::string geometry; Violations violations; diff --git a/src/utils/output_json.cpp b/src/utils/output_json.cpp index 7105c8a7a..4baa63788 100644 --- a/src/utils/output_json.cpp +++ b/src/utils/output_json.cpp @@ -315,6 +315,13 @@ rapidjson::Value to_json(const Step& s, } json_step.AddMember("setup", s.setup, allocator); + + if (!s.geometry.empty()) { + json_step.AddMember("geometry", s.setup, allocator); + json_step["geometry"].SetString(s.geometry.c_str(), + s.geometry.size()); + } + json_step.AddMember("service", s.service, allocator); json_step.AddMember("waiting_time", s.waiting_time, allocator); From 2220bd617a4aca6f1a89df45d20350f04464e51e Mon Sep 17 00:00:00 2001 From: dhiego Date: Wed, 18 Jan 2023 08:04:51 -0300 Subject: [PATCH 6/7] feat: adding independent geometry for each step --- libvroom_examples/libvroom.cpp | 1 + src/routing/http_wrapper.cpp | 14 +++++++++++++- src/routing/http_wrapper.h | 5 +++++ src/routing/ors_wrapper.cpp | 9 +++++++++ src/routing/ors_wrapper.h | 6 ++++++ src/routing/osrm_routed_wrapper.cpp | 12 +++++++++++- src/routing/osrm_routed_wrapper.h | 6 ++++++ src/routing/valhalla_wrapper.cpp | 10 ++++++++++ src/routing/valhalla_wrapper.h | 7 +++++++ src/structures/vroom/solution/step.h | 1 + src/utils/output_json.cpp | 7 +++++++ 11 files changed, 76 insertions(+), 2 deletions(-) diff --git a/libvroom_examples/libvroom.cpp b/libvroom_examples/libvroom.cpp index 70a941e61..847547e2e 100644 --- a/libvroom_examples/libvroom.cpp +++ b/libvroom_examples/libvroom.cpp @@ -69,6 +69,7 @@ void log_solution(const vroom::Solution& sol, bool geometry) { std::cout << " - " << step.location.lon() << ";" << step.location.lat(); } + std::cout << " - geometry: " << step.geometry; std::cout << " - arrival: " << step.arrival; std::cout << " - duration: " << step.duration; std::cout << " - service: " << step.service; diff --git a/src/routing/http_wrapper.cpp b/src/routing/http_wrapper.cpp index 474de70e3..1b2e2553c 100644 --- a/src/routing/http_wrapper.cpp +++ b/src/routing/http_wrapper.cpp @@ -9,8 +9,8 @@ All rights reserved (see LICENSE). #include #include - #include "routing/http_wrapper.h" +#include "../../include/polylineencoder/src/polylineencoder.h" using asio::ip::tcp; @@ -256,8 +256,20 @@ void HttpWrapper::add_route_info(Route& route) const { } } + gepaf::PolylineEncoder<> encoder; + auto nb_steps = get_steps_number(json_result, i); + + for (rapidjson::SizeType s = 0; s < nb_steps; ++s) { + auto polylines = gepaf::PolylineEncoder<>::decode(get_geometry_for_leg(json_result,i, s)); + + for (const auto& p : polylines) { + encoder.addPoint(p.latitude(), p.longitude()); + } + } + sum_distance += next_distance; next_step.distance = round_cost(sum_distance); + next_step.geometry = encoder.encode(); steps_rank += number_breaks_after[i] + 1; } diff --git a/src/routing/http_wrapper.h b/src/routing/http_wrapper.h index 9481ba07b..370166d9d 100644 --- a/src/routing/http_wrapper.h +++ b/src/routing/http_wrapper.h @@ -64,9 +64,14 @@ class HttpWrapper : public Wrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const = 0; + virtual unsigned get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const = 0; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const = 0; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const = 0; + virtual std::string get_geometry(rapidjson::Value& result) const = 0; virtual void add_route_info(Route& route) const override; diff --git a/src/routing/ors_wrapper.cpp b/src/routing/ors_wrapper.cpp index 85a14f00a..b2da6f2b0 100644 --- a/src/routing/ors_wrapper.cpp +++ b/src/routing/ors_wrapper.cpp @@ -84,11 +84,20 @@ unsigned OrsWrapper::get_legs_number(const rapidjson::Value& result) const { return result["routes"][0]["segments"].Size(); } +unsigned OrsWrapper::get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const { + return result["routes"][0]["segments"].Size(); +} + double OrsWrapper::get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const { return result["routes"][0]["segments"][i]["distance"].GetDouble(); } +std::string OrsWrapper::get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const { + return result["routes"][0]["legs"][i]["steps"][s]["geometry"].GetString(); +} + std::string OrsWrapper::get_geometry(rapidjson::Value& result) const { return result["routes"][0]["geometry"].GetString(); } diff --git a/src/routing/ors_wrapper.h b/src/routing/ors_wrapper.h index efe00a774..2a07e2216 100644 --- a/src/routing/ors_wrapper.h +++ b/src/routing/ors_wrapper.h @@ -36,9 +36,15 @@ class OrsWrapper : public HttpWrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const override; + virtual unsigned + get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const override; + virtual std::string get_geometry(rapidjson::Value& result) const override; public: diff --git a/src/routing/osrm_routed_wrapper.cpp b/src/routing/osrm_routed_wrapper.cpp index a1154f4d0..ff5a07378 100644 --- a/src/routing/osrm_routed_wrapper.cpp +++ b/src/routing/osrm_routed_wrapper.cpp @@ -19,7 +19,7 @@ OsrmRoutedWrapper::OsrmRoutedWrapper(const std::string& profile, "table", "durations", "route", - "alternatives=false&steps=false&overview=full&continue_" + "alternatives=false&steps=true&overview=full&continue_" "straight=false") { } @@ -79,11 +79,21 @@ OsrmRoutedWrapper::get_legs_number(const rapidjson::Value& result) const { return result["routes"][0]["legs"].Size(); } +unsigned +OsrmRoutedWrapper::get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const { + return result["routes"][0]["legs"][i]["steps"].Size(); +} + double OsrmRoutedWrapper::get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const { return result["routes"][0]["legs"][i]["distance"].GetDouble(); } +std::string OsrmRoutedWrapper::get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const { + return result["routes"][0]["legs"][i]["steps"][s]["geometry"].GetString(); +} + std::string OsrmRoutedWrapper::get_geometry(rapidjson::Value& result) const { return result["routes"][0]["geometry"].GetString(); } diff --git a/src/routing/osrm_routed_wrapper.h b/src/routing/osrm_routed_wrapper.h index db80c66b3..882fcfc63 100644 --- a/src/routing/osrm_routed_wrapper.h +++ b/src/routing/osrm_routed_wrapper.h @@ -36,9 +36,15 @@ class OsrmRoutedWrapper : public HttpWrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const override; + virtual unsigned + get_steps_number(const rapidjson::Value& result, rapidjson::SizeType ) const override; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const override; + virtual std::string get_geometry(rapidjson::Value& result) const override; public: diff --git a/src/routing/valhalla_wrapper.cpp b/src/routing/valhalla_wrapper.cpp index 0c27508d8..ea81758a5 100644 --- a/src/routing/valhalla_wrapper.cpp +++ b/src/routing/valhalla_wrapper.cpp @@ -139,11 +139,21 @@ ValhallaWrapper::get_legs_number(const rapidjson::Value& result) const { return result["trip"]["legs"].Size(); } +unsigned +ValhallaWrapper::get_steps_number(const rapidjson::Value& result, rapidjson::SizeType i) const { + return result["trip"]["legs"].Size(); +} + double ValhallaWrapper::get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const { return 1000 * result["trip"]["legs"][i]["summary"]["length"].GetDouble(); } +std::string ValhallaWrapper::get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const { + return result["routes"][0]["legs"][i]["steps"][s]["geometry"].GetString(); +} + std::string ValhallaWrapper::get_geometry(rapidjson::Value& result) const { // Valhalla returns one polyline per route leg so we need to merge // them. Also taking the opportunity to adjust the encoding diff --git a/src/routing/valhalla_wrapper.h b/src/routing/valhalla_wrapper.h index 0bfc445a4..ea8f9bea9 100644 --- a/src/routing/valhalla_wrapper.h +++ b/src/routing/valhalla_wrapper.h @@ -41,9 +41,16 @@ class ValhallaWrapper : public HttpWrapper { virtual unsigned get_legs_number(const rapidjson::Value& result) const override; + virtual unsigned + get_steps_number(const rapidjson::Value& result, + rapidjson::SizeType i) const override; + virtual double get_distance_for_leg(const rapidjson::Value& result, rapidjson::SizeType i) const override; + virtual std::string get_geometry_for_leg(const rapidjson::Value& result, + rapidjson::SizeType i, rapidjson::SizeType s) const override; + virtual std::string get_geometry(rapidjson::Value& result) const override; public: diff --git a/src/structures/vroom/solution/step.h b/src/structures/vroom/solution/step.h index 5948b0870..3189df9c8 100644 --- a/src/structures/vroom/solution/step.h +++ b/src/structures/vroom/solution/step.h @@ -33,6 +33,7 @@ struct Step { UserDuration duration; UserDuration waiting_time; Distance distance; + std::string geometry; Violations violations; diff --git a/src/utils/output_json.cpp b/src/utils/output_json.cpp index a22ea5436..654330f0b 100644 --- a/src/utils/output_json.cpp +++ b/src/utils/output_json.cpp @@ -321,6 +321,13 @@ rapidjson::Value to_json(const Step& s, } json_step.AddMember("setup", s.setup, allocator); + + if (!s.geometry.empty()) { + json_step.AddMember("geometry", s.setup, allocator); + json_step["geometry"].SetString(s.geometry.c_str(), + s.geometry.size()); + } + json_step.AddMember("service", s.service, allocator); json_step.AddMember("waiting_time", s.waiting_time, allocator); From f615ae3d8f9d9209b7fd9c785bc30faa5d8c9d71 Mon Sep 17 00:00:00 2001 From: dhiego Date: Fri, 31 Mar 2023 11:06:49 -0300 Subject: [PATCH 7/7] =?UTF-8?q?feat:altera=C3=A7=C3=A3o=20para=20informar?= =?UTF-8?q?=20parmetros=20extras=20e=20geometria=20em=20cada=20ponto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input.json | 54 ++++++++++++++++++++++++++++ src/main.cpp | 6 +++- src/routing/http_wrapper.cpp | 22 ++++++++---- src/routing/valhalla_wrapper.cpp | 9 ++--- src/routing/valhalla_wrapper.h | 2 +- src/structures/cl_args.h | 1 + src/structures/vroom/input/input.cpp | 5 +-- src/structures/vroom/input/input.h | 3 +- 8 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 input.json diff --git a/input.json b/input.json new file mode 100644 index 000000000..22bcb650b --- /dev/null +++ b/input.json @@ -0,0 +1,54 @@ +{ + "options": { + "g": true, + "c": false + }, + "jobs": [ + { + "id": 0, + "description": "636d04c8470642cb5a9555cc", + "location": [ + -48.87455813874452, + -26.28461496470875 + ], + "service": 60 + }, + { + "id": 1, + "description": "aaaaaaaa", + "location": [ + -48.87750123470842, + -26.27487378830072 + ], + "service": 60 + } + ], + "vehicles": [ + { + "profile": "auto", + "id": 1060, + "description": "Adesao 1060", + "start": [ + -48.87589286745765, + -26.27276577714968 + ], + "time_window": [ + 1668078000, + 1668119100 + ], + "time_window_with_break": [ + [ + 1668078000, + 1668092400 + ], + [ + 1668096300, + 1668114000 + ] + ], + "breaks": [], + "steps": [], + "speed_factor": 0.9 + } + ] +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 43b108337..d00ce5d36 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,7 @@ int main(int argc, char** argv) { std::vector host_args; std::vector port_args; std::string router_arg; + std::string extra_args; std::string limit_arg; std::vector heuristic_params_arg; @@ -71,6 +72,9 @@ int main(int argc, char** argv) { ("r,router", "osrm, libosrm, ors or valhalla", cxxopts::value(router_arg)->default_value("osrm")) + ("E,extra_args", + "extra args", + cxxopts::value(cl_args.extra_args)) ("t,threads", "number of available threads", cxxopts::value(cl_args.nb_threads)->default_value(std::to_string(vroom::DEFAULT_THREADS_NUMBER))) @@ -183,7 +187,7 @@ int main(int argc, char** argv) { try { // Build problem. - vroom::Input problem_instance(cl_args.servers, cl_args.router); + vroom::Input problem_instance(cl_args.servers, cl_args.router, cl_args.extra_args); vroom::io::parse(problem_instance, cl_args.input, cl_args.geometry); vroom::Solution sol = (cl_args.check) diff --git a/src/routing/http_wrapper.cpp b/src/routing/http_wrapper.cpp index 1b2e2553c..72fca9d47 100644 --- a/src/routing/http_wrapper.cpp +++ b/src/routing/http_wrapper.cpp @@ -212,9 +212,15 @@ void HttpWrapper::add_route_info(Route& route) const { std::string query = build_query(non_break_locations, _route_service, _extra_args); + + // printf("query: %s\n\n\n", query.c_str()); + std::string json_string = this->run_query(query); + // printf("resultado: %s\n\n\n\n", json_string.c_str()); + + rapidjson::Document json_result; parse_response(json_result, json_string); this->check_response(json_result, _route_service); @@ -259,20 +265,22 @@ void HttpWrapper::add_route_info(Route& route) const { gepaf::PolylineEncoder<> encoder; auto nb_steps = get_steps_number(json_result, i); - for (rapidjson::SizeType s = 0; s < nb_steps; ++s) { - auto polylines = gepaf::PolylineEncoder<>::decode(get_geometry_for_leg(json_result,i, s)); + // for (rapidjson::SizeType s = 0; s < nb_steps; ++s) { + // auto polylines = gepaf::PolylineEncoder<>::decode(get_geometry_for_leg(json_result,i, s)); - for (const auto& p : polylines) { - encoder.addPoint(p.latitude(), p.longitude()); - } - } + // for (const auto& p : polylines) { + // encoder.addPoint(p.latitude(), p.longitude()); + // } + // } sum_distance += next_distance; next_step.distance = round_cost(sum_distance); - next_step.geometry = encoder.encode(); + // next_step.geometry = encoder.encode(); + next_step.geometry = get_geometry_for_leg(json_result,i, 0); steps_rank += number_breaks_after[i] + 1; } + // printf("top\n\n\n\n"); } } // namespace routing diff --git a/src/routing/valhalla_wrapper.cpp b/src/routing/valhalla_wrapper.cpp index ea81758a5..8d30e2354 100644 --- a/src/routing/valhalla_wrapper.cpp +++ b/src/routing/valhalla_wrapper.cpp @@ -15,13 +15,14 @@ namespace vroom { namespace routing { ValhallaWrapper::ValhallaWrapper(const std::string& profile, - const Server& server) + const Server& server, const std::string& extra_args) : HttpWrapper(profile, server, "sources_to_targets", "sources_to_targets", "route", - "\"directions_type\":\"none\"") { + extra_args + ) { } std::string ValhallaWrapper::get_matrix_query( @@ -62,7 +63,7 @@ ValhallaWrapper::get_route_query(const std::vector& locations, } query.pop_back(); // Remove trailing ','. - query += "],\"costing\":\"" + profile + "\""; + query += "],\"costing\":\"" + profile + "\",\"directions_type\":\"none\""; if (!extra_args.empty()) { query += "," + extra_args; } @@ -151,7 +152,7 @@ double ValhallaWrapper::get_distance_for_leg(const rapidjson::Value& result, std::string ValhallaWrapper::get_geometry_for_leg(const rapidjson::Value& result, rapidjson::SizeType i, rapidjson::SizeType s) const { - return result["routes"][0]["legs"][i]["steps"][s]["geometry"].GetString(); + return result["trip"]["legs"][i]["shape"].GetString(); } std::string ValhallaWrapper::get_geometry(rapidjson::Value& result) const { diff --git a/src/routing/valhalla_wrapper.h b/src/routing/valhalla_wrapper.h index ea8f9bea9..4b34a36fb 100644 --- a/src/routing/valhalla_wrapper.h +++ b/src/routing/valhalla_wrapper.h @@ -54,7 +54,7 @@ class ValhallaWrapper : public HttpWrapper { virtual std::string get_geometry(rapidjson::Value& result) const override; public: - ValhallaWrapper(const std::string& profile, const Server& server); + ValhallaWrapper(const std::string& profile, const Server& server, const std::string& extra_args); }; } // namespace routing diff --git a/src/structures/cl_args.h b/src/structures/cl_args.h index 51e9c5118..71fe1db04 100644 --- a/src/structures/cl_args.h +++ b/src/structures/cl_args.h @@ -32,6 +32,7 @@ struct CLArgs { std::string output_file; // -o ROUTER router; // -r std::string input; // cl arg + std::string extra_args; // -E unsigned nb_threads; // -t unsigned exploration_level; // -x diff --git a/src/structures/vroom/input/input.cpp b/src/structures/vroom/input/input.cpp index 60c638bce..fe0f16988 100644 --- a/src/structures/vroom/input/input.cpp +++ b/src/structures/vroom/input/input.cpp @@ -28,7 +28,7 @@ All rights reserved (see LICENSE). namespace vroom { -Input::Input(const io::Servers& servers, ROUTER router) +Input::Input(const io::Servers& servers, ROUTER router, const std::string& extra_args) : _start_loading(std::chrono::high_resolution_clock::now()), _no_addition_yet(true), _has_skills(false), @@ -47,6 +47,7 @@ Input::Input(const io::Servers& servers, ROUTER router) _amount_size(0), _zero(0), _servers(servers), + _extra_args(extra_args), _router(router) { } @@ -114,7 +115,7 @@ void Input::add_routing_wrapper(const std::string& profile) { throw InputException("Invalid profile: " + profile + "."); } routing_wrapper = - std::make_unique(profile, search->second); + std::make_unique(profile, search->second, _extra_args); } break; } } diff --git a/src/structures/vroom/input/input.h b/src/structures/vroom/input/input.h index 6a4594276..23747432e 100644 --- a/src/structures/vroom/input/input.h +++ b/src/structures/vroom/input/input.h @@ -66,6 +66,7 @@ class Input { const io::Servers _servers; const ROUTER _router; + const std::string& _extra_args; std::unique_ptr get_problem() const; @@ -92,7 +93,7 @@ class Input { std::unordered_map pickup_id_to_rank; std::unordered_map delivery_id_to_rank; - Input(const io::Servers& servers = {}, ROUTER router = ROUTER::OSRM); + Input(const io::Servers& servers = {}, ROUTER router = ROUTER::OSRM, const std::string& extra_args = ""); void set_amount_size(unsigned amount_size);