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 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/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 474de70e3..72fca9d47 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; @@ -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); @@ -256,11 +262,25 @@ 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(); + 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/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..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; } @@ -139,11 +140,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["trip"]["legs"][i]["shape"].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..4b34a36fb 100644 --- a/src/routing/valhalla_wrapper.h +++ b/src/routing/valhalla_wrapper.h @@ -41,13 +41,20 @@ 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: - 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); 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);