Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding independent geometry for each step #873

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions input.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
1 change: 1 addition & 0 deletions libvroom_examples/libvroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ int main(int argc, char** argv) {
std::vector<std::string> host_args;
std::vector<std::string> port_args;
std::string router_arg;
std::string extra_args;
std::string limit_arg;
std::vector<std::string> heuristic_params_arg;

Expand Down Expand Up @@ -71,6 +72,9 @@ int main(int argc, char** argv) {
("r,router",
"osrm, libosrm, ors or valhalla",
cxxopts::value<std::string>(router_arg)->default_value("osrm"))
("E,extra_args",
"extra args",
cxxopts::value<std::string>(cl_args.extra_args))
("t,threads",
"number of available threads",
cxxopts::value<unsigned>(cl_args.nb_threads)->default_value(std::to_string(vroom::DEFAULT_THREADS_NUMBER)))
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 21 additions & 1 deletion src/routing/http_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ All rights reserved (see LICENSE).

#include <asio.hpp>
#include <asio/ssl.hpp>

#include "routing/http_wrapper.h"
#include "../../include/polylineencoder/src/polylineencoder.h"

using asio::ip::tcp;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/routing/http_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/routing/ors_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 6 additions & 0 deletions src/routing/ors_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 11 additions & 1 deletion src/routing/osrm_routed_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
}

Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 6 additions & 0 deletions src/routing/osrm_routed_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 14 additions & 3 deletions src/routing/valhalla_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -62,7 +63,7 @@ ValhallaWrapper::get_route_query(const std::vector<Location>& locations,
}
query.pop_back(); // Remove trailing ','.

query += "],\"costing\":\"" + profile + "\"";
query += "],\"costing\":\"" + profile + "\",\"directions_type\":\"none\"";
if (!extra_args.empty()) {
query += "," + extra_args;
}
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/routing/valhalla_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/structures/cl_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/structures/vroom/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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) {
}

Expand Down Expand Up @@ -114,7 +115,7 @@ void Input::add_routing_wrapper(const std::string& profile) {
throw InputException("Invalid profile: " + profile + ".");
}
routing_wrapper =
std::make_unique<routing::ValhallaWrapper>(profile, search->second);
std::make_unique<routing::ValhallaWrapper>(profile, search->second, _extra_args);
} break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/structures/vroom/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Input {

const io::Servers _servers;
const ROUTER _router;
const std::string& _extra_args;

std::unique_ptr<VRP> get_problem() const;

Expand All @@ -92,7 +93,7 @@ class Input {
std::unordered_map<Id, Index> pickup_id_to_rank;
std::unordered_map<Id, Index> 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);

Expand Down
1 change: 1 addition & 0 deletions src/structures/vroom/solution/step.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct Step {
UserDuration duration;
UserDuration waiting_time;
Distance distance;
std::string geometry;

Violations violations;

Expand Down
Loading