Skip to content

Commit

Permalink
Update solution package classes
Browse files Browse the repository at this point in the history
  • Loading branch information
SebMilardo committed May 22, 2024
1 parent e26ecea commit fd9ae44
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
24 changes: 16 additions & 8 deletions src/bind/solution/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,33 @@ void init_route(py::module_ &m) {

py::class_<vroom::Route>(m, "Route")
.def(py::init<>())
.def(py::init([](vroom::Id vehicle, std::vector<vroom::Step> &steps,
vroom::Cost cost, vroom::Duration setup,
vroom::Duration service, vroom::Duration duration,
vroom::Duration waiting_time, vroom::Priority priority,
.def(py::init([](vroom::Id vehicle,
std::vector<vroom::Step> &steps,
vroom::UserCost cost,
vroom::UserDuration duration,
vroom::UserDistance distance,
vroom::UserDuration setup,
vroom::UserDuration service,
vroom::UserDuration waiting_time,
vroom::Priority priority,
const vroom::Amount &delivery,
const vroom::Amount &pickup, const std::string &profile,
const vroom::Amount &pickup,
const std::string &profile,
const std::string &description,
const vroom::Violations &violations) {
return new vroom::Route(vehicle, std::move(steps), cost, setup, service,
duration, waiting_time, priority, delivery,
vroom::Violations &violations) {
return new vroom::Route(vehicle, std::move(steps), cost, duration, distance,
setup, service, waiting_time, priority, delivery,
pickup, profile, description,
std::move(violations));
}))

.def_readwrite("vehicle", &vroom::Route::vehicle)
.def_readonly("steps", &vroom::Route::steps)
.def_readwrite("cost", &vroom::Route::cost)
.def_readwrite("setup", &vroom::Route::setup)
.def_readwrite("service", &vroom::Route::service)
.def_readwrite("duration", &vroom::Route::duration)
.def_readwrite("distance", &vroom::Route::distance)
.def_readwrite("waiting_time", &vroom::Route::waiting_time)
.def_readwrite("priority", &vroom::Route::priority)
.def_readwrite("delivery", &vroom::Route::delivery)
Expand Down
23 changes: 10 additions & 13 deletions src/bind/solution/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ void init_solution(py::module_ &m) {

py::class_<vroom::Solution>(m, "Solution")
.def(py::init([](vroom::Solution s) { return s; }))
.def(py::init<unsigned, std::string>())
.def(py::init([](unsigned code, unsigned amount_size,
.def(py::init([](const vroom::Amount& zero_amount,
std::vector<vroom::Route> &routes,
std::vector<vroom::Job> &unassigned) {
return new vroom::Solution(code, amount_size, std::move(routes),
return new vroom::Solution(zero_amount, std::move(routes),
std::move(unassigned));
}))
.def("_routes_numpy",
Expand Down Expand Up @@ -72,14 +71,14 @@ void init_solution(py::module_ &m) {
strncpy(ptr[idx].type, type.c_str(), 9);
strncpy(ptr[idx].description, step.description.c_str(), 40);

ptr[idx].longitude = step.location.has_coordinates()
? step.location.lon()
ptr[idx].longitude = step.location.has_value()
? step.location.value().lat()
: NA_SUBSTITUTE;
ptr[idx].latitude = step.location.has_coordinates()
? step.location.lat()
ptr[idx].latitude = step.location.has_value()
? step.location.value().lat()
: NA_SUBSTITUTE;
ptr[idx].location_index = step.location.user_index()
? step.location.index()
ptr[idx].location_index = step.location.has_value()
? step.location.value().index()
: NA_SUBSTITUTE;

ptr[idx].id = (step.step_type == vroom::STEP_TYPE::JOB or
Expand All @@ -103,16 +102,14 @@ void init_solution(py::module_ &m) {
[](vroom::Solution solution) {
py::scoped_ostream_redirect stream(
std::cout, py::module_::import("sys").attr("stdout"));
vroom::io::write_to_json(solution, false, "");
vroom::io::write_to_json(solution, "", false);
})
.def("_geometry_solution_json",
[](vroom::Solution solution) {
py::scoped_ostream_redirect stream(
std::cout, py::module_::import("sys").attr("stdout"));
vroom::io::write_to_json(solution, true, "");
vroom::io::write_to_json(solution, "", true);
})
.def_readwrite("code", &vroom::Solution::code)
.def_readwrite("error", &vroom::Solution::error)
.def_readonly("summary", &vroom::Solution::summary)
.def_readonly("_routes", &vroom::Solution::routes)
.def_readonly("unassigned", &vroom::Solution::unassigned);
Expand Down
2 changes: 1 addition & 1 deletion src/bind/solution/summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void init_summary(py::module_ &m) {

py::class_<vroom::Summary>(m, "Summary")
.def(py::init<>())
.def(py::init<unsigned, unsigned, unsigned>())
.def(py::init<unsigned, unsigned, const vroom::Amount&>())
.def_readwrite("cost", &vroom::Summary::cost)
.def_readonly("routes", &vroom::Summary::routes)
.def_readonly("unassigned", &vroom::Summary::unassigned)
Expand Down

0 comments on commit fd9ae44

Please sign in to comment.