From 7260f37d08f4dc6e3fee3094ef30b75e71892c51 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 22 May 2024 15:30:34 +0200 Subject: [PATCH 01/25] Update vroom version to 1.14.0 --- vroom | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vroom b/vroom index e2653a4..1fd711b 160000 --- a/vroom +++ b/vroom @@ -1 +1 @@ -Subproject commit e2653a46f5e84d52032f2f47788e3898d9ef98fc +Subproject commit 1fd711bc8c20326dd8e9538e2c7e4cb1ebd67bdb From 828c1d8c2e5a04392ac396ccccf255f5b8c8b1ab Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 22 May 2024 15:35:42 +0200 Subject: [PATCH 02/25] Set cxx_std = 20 --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 8d838ef..dafbf52 100644 --- a/setup.py +++ b/setup.py @@ -72,6 +72,7 @@ libraries=libraries, extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, + cxx_std=20 ), ] From 20bc7d476ceac6063cc0bb883e01834830a8eaa5 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 22 May 2024 15:36:12 +0200 Subject: [PATCH 03/25] Remove lshift operator from amount --- src/bind/amount.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/bind/amount.cpp b/src/bind/amount.cpp index 9492547..39cfd81 100644 --- a/src/bind/amount.cpp +++ b/src/bind/amount.cpp @@ -28,8 +28,6 @@ void init_amount(py::module_ &m) { py::format_descriptor::format(), 1, {a.size()}, {sizeof(int64_t)}); }) - .def("_lshift", [](const vroom::Amount &a, - const vroom::Amount &b) { return a << b; }) .def("_le", [](const vroom::Amount &a, const vroom::Amount &b) { return a <= b; }) .def("_push_back", &vroom::Amount::push_back) From e26ecea6df849eb676a5bd4b382bad38786bf167 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 22 May 2024 15:37:35 +0200 Subject: [PATCH 04/25] Update Vehicle class --- src/bind/vehicle.cpp | 17 ++++++++++------- src/vroom/vehicle.py | 4 +++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/bind/vehicle.cpp b/src/bind/vehicle.cpp index 5dde498..da9f89d 100644 --- a/src/bind/vehicle.cpp +++ b/src/bind/vehicle.cpp @@ -14,20 +14,21 @@ void init_vehicle(py::module_ &m) { .def_readonly("_per_hour", &vroom::VehicleCosts::per_hour); py::class_(m, "CostWrapper") - .def(py::init(), + .def(py::init(), "CostWrapper constructor", - py::arg("speed_factor"), py::arg("per_hour")) + py::arg("speed_factor"), py::arg("per_hour"), py::arg("per_km")) .def("set_durations_matrix", &vroom::CostWrapper::set_durations_matrix) - .def("set_costs_matrix", &vroom::CostWrapper::set_costs_matrix) - .def("_get_speed_factor", &vroom::CostWrapper::get_speed_factor) - .def("_get_per_hour", &vroom::CostWrapper::get_per_hour); + .def("set_distances_matrix", &vroom::CostWrapper::set_distances_matrix) + .def("set_costs_matrix", &vroom::CostWrapper::set_costs_matrix); py::class_(m, "Vehicle") .def(py::init &, std::optional &, std::string &, vroom::Amount &, vroom::Skills &, vroom::TimeWindow &, - std::vector &, std::string &, vroom::VehicleCosts, double, size_t, - std::optional, + std::vector &, std::string &, vroom::VehicleCosts, double, + std::optional&, + std::optional &, + std::optional &, std::vector &>(), "Vehicle constructor.", py::arg("id"), py::arg("start"), py::arg("end"), py::arg("profile"), @@ -40,6 +41,7 @@ void init_vehicle(py::module_ &m) { py::arg("speed_factor"), py::arg("max_tasks"), py::arg("max_travel_time"), + py::arg("max_distance"), py::arg("steps")) // .def("has_start", &vroom::Vehicle::has_start) // .def("has_end", &vroom::Vehicle::has_end) @@ -59,5 +61,6 @@ void init_vehicle(py::module_ &m) { // .def_readwrite("_speed_factor", &vroom::Vehicle::speed_factor) .def_readonly("_max_tasks", &vroom::Vehicle::max_tasks) .def_readonly("_max_travel_time", &vroom::Vehicle::max_travel_time) + .def_readonly("_max_distance", &vroom::Vehicle::max_distance) .def_readonly("_steps", &vroom::Vehicle::steps); } diff --git a/src/vroom/vehicle.py b/src/vroom/vehicle.py index 2fa2705..c7cc680 100644 --- a/src/vroom/vehicle.py +++ b/src/vroom/vehicle.py @@ -113,8 +113,9 @@ def __init__( description: str = "", costs: VehicleCosts = VehicleCosts(), speed_factor: float = 1.0, - max_tasks: int = MAX_UINT, + max_tasks: Optional[int] = MAX_UINT, max_travel_time: Optional[int] = None, + max_distance: Optional[int] = None, steps: Sequence[VehicleStep] = (), ) -> None: self._speed_factor = float(speed_factor) @@ -133,6 +134,7 @@ def __init__( speed_factor=self._speed_factor, max_tasks=max_tasks, max_travel_time=max_travel_time, + max_distance=max_distance, steps=steps, ) assert isinstance(self.capacity, Amount) From fd9ae44c3e9292e4a53b9fec6cb714162e53c6a2 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 22 May 2024 15:38:39 +0200 Subject: [PATCH 05/25] Update solution package classes --- src/bind/solution/route.cpp | 24 ++++++++++++++++-------- src/bind/solution/solution.cpp | 23 ++++++++++------------- src/bind/solution/summary.cpp | 2 +- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/bind/solution/route.cpp b/src/bind/solution/route.cpp index 5c507bf..11371dd 100644 --- a/src/bind/solution/route.cpp +++ b/src/bind/solution/route.cpp @@ -8,25 +8,33 @@ void init_route(py::module_ &m) { py::class_(m, "Route") .def(py::init<>()) - .def(py::init([](vroom::Id vehicle, std::vector &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 &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) diff --git a/src/bind/solution/solution.cpp b/src/bind/solution/solution.cpp index d392f1f..e12ff6c 100644 --- a/src/bind/solution/solution.cpp +++ b/src/bind/solution/solution.cpp @@ -33,11 +33,10 @@ void init_solution(py::module_ &m) { py::class_(m, "Solution") .def(py::init([](vroom::Solution s) { return s; })) - .def(py::init()) - .def(py::init([](unsigned code, unsigned amount_size, + .def(py::init([](const vroom::Amount& zero_amount, std::vector &routes, std::vector &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", @@ -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 @@ -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); diff --git a/src/bind/solution/summary.cpp b/src/bind/solution/summary.cpp index 51acd77..bd0f5bc 100644 --- a/src/bind/solution/summary.cpp +++ b/src/bind/solution/summary.cpp @@ -8,7 +8,7 @@ void init_summary(py::module_ &m) { py::class_(m, "Summary") .def(py::init<>()) - .def(py::init()) + .def(py::init()) .def_readwrite("cost", &vroom::Summary::cost) .def_readonly("routes", &vroom::Summary::routes) .def_readonly("unassigned", &vroom::Summary::unassigned) From fda87e9f4c1c27d26a9a985a749e0e6e74aa40a3 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 22 May 2024 15:39:00 +0200 Subject: [PATCH 06/25] Fix matrix.cpp import --- src/bind/generic/matrix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bind/generic/matrix.cpp b/src/bind/generic/matrix.cpp index bb65194..f7c7260 100644 --- a/src/bind/generic/matrix.cpp +++ b/src/bind/generic/matrix.cpp @@ -1,6 +1,6 @@ #include -#include "structures/generic/matrix.cpp" +#include "structures/generic/matrix.h" namespace py = pybind11; From 309384651f2d1de63fe7ba72d8606af93730f206 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 22 May 2024 15:39:35 +0200 Subject: [PATCH 07/25] Remove const from Violations init --- src/_vroom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_vroom.cpp b/src/_vroom.cpp index 3f62b2e..203690a 100644 --- a/src/_vroom.cpp +++ b/src/_vroom.cpp @@ -137,7 +137,7 @@ PYBIND11_MODULE(_vroom, m) { .def(py::init<>()) .def(py::init([](const vroom::Duration lead_time, const vroom::Duration delay, - const std::unordered_set types) { + std::unordered_set types) { return new vroom::Violations(lead_time, delay, std::move(types)); })) .def(py::self += py::self) From d1784ac7a9bdc64927493a703b56c427eebee451 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 22 May 2024 16:08:54 +0200 Subject: [PATCH 08/25] Lint and format --- Makefile | 2 +- src/_vroom.cpp | 4 ++-- src/bind/break.cpp | 9 ++++---- src/bind/location.cpp | 3 ++- src/bind/solution/route.cpp | 32 +++++++++++---------------- src/bind/solution/solution.cpp | 2 +- src/bind/solution/summary.cpp | 2 +- src/bind/time_window.cpp | 6 +++-- src/bind/utils.cpp | 22 +++++-------------- src/bind/vehicle.cpp | 39 ++++++++++++++------------------- src/vroom/__init__.py | 1 + src/vroom/amount.py | 3 ++- src/vroom/break_.py | 3 +-- src/vroom/input/input.py | 7 +++--- src/vroom/input/vehicle_step.py | 2 +- src/vroom/solution/solution.py | 7 +++--- src/vroom/time_window.py | 3 +-- src/vroom/vehicle.py | 1 + 18 files changed, 66 insertions(+), 82 deletions(-) diff --git a/Makefile b/Makefile index be418aa..04e9e9e 100644 --- a/Makefile +++ b/Makefile @@ -26,4 +26,4 @@ format: @echo format python code with black @python -m black src/vroom @echo format c++ code with clang-format - @find src -type f -name '*.cpp' | xargs -I{} clang-format-10 -i -style=file {} + @find src -type f -name '*.cpp' | xargs -I{} clang-format-14 -i -style=file {} diff --git a/src/_vroom.cpp b/src/_vroom.cpp index 203690a..1b082eb 100644 --- a/src/_vroom.cpp +++ b/src/_vroom.cpp @@ -57,8 +57,8 @@ #include "problems/cvrp/operators/intra_exchange.cpp" #include "problems/cvrp/operators/intra_mixed_exchange.cpp" #include "problems/cvrp/operators/intra_or_opt.cpp" -#include "problems/cvrp/operators/intra_two_opt.cpp" #include "problems/cvrp/operators/intra_relocate.cpp" +#include "problems/cvrp/operators/intra_two_opt.cpp" #include "problems/cvrp/operators/mixed_exchange.cpp" #include "problems/cvrp/operators/or_opt.cpp" #include "problems/cvrp/operators/pd_shift.cpp" @@ -76,8 +76,8 @@ #include "problems/vrptw/operators/intra_exchange.cpp" #include "problems/vrptw/operators/intra_mixed_exchange.cpp" #include "problems/vrptw/operators/intra_or_opt.cpp" -#include "problems/vrptw/operators/intra_two_opt.cpp" #include "problems/vrptw/operators/intra_relocate.cpp" +#include "problems/vrptw/operators/intra_two_opt.cpp" #include "problems/vrptw/operators/mixed_exchange.cpp" #include "problems/vrptw/operators/or_opt.cpp" #include "problems/vrptw/operators/pd_shift.cpp" diff --git a/src/bind/break.cpp b/src/bind/break.cpp index 2c0543a..ef3397a 100644 --- a/src/bind/break.cpp +++ b/src/bind/break.cpp @@ -8,10 +8,11 @@ void init_break(py::module_ &m) { py::class_(m, "Break") .def(py::init([](vroom::Break &b) { return b; }), py::arg("break")) - .def(py::init &, - vroom::Duration, std::string &, std::optional &>(), - py::arg("id"), py::arg("time_windows"), py::arg("service"), - py::arg("description"), py::arg("max_load")) + .def( + py::init &, vroom::Duration, + std::string &, std::optional &>(), + py::arg("id"), py::arg("time_windows"), py::arg("service"), + py::arg("description"), py::arg("max_load")) .def("_is_valid_start", &vroom::Break::is_valid_start, py::arg("time")) .def_readwrite("_id", &vroom::Break::id) .def_readwrite("_time_windows", &vroom::Break::tws) diff --git a/src/bind/location.cpp b/src/bind/location.cpp index 85dced8..0002bd5 100644 --- a/src/bind/location.cpp +++ b/src/bind/location.cpp @@ -5,7 +5,8 @@ void init_location(py::module_ &m) { py::class_(m, "Coordinates") - .def(py::init(), py::arg("lon"), py::arg("lat")); + .def(py::init(), py::arg("lon"), + py::arg("lat")); py::class_(m, "Location") .def(py::init(), py::arg("index")) diff --git a/src/bind/solution/route.cpp b/src/bind/solution/route.cpp index 11371dd..b8b1f1a 100644 --- a/src/bind/solution/route.cpp +++ b/src/bind/solution/route.cpp @@ -8,25 +8,19 @@ void init_route(py::module_ &m) { py::class_(m, "Route") .def(py::init<>()) - .def(py::init([](vroom::Id vehicle, - std::vector &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 std::string &description, - 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(py::init( + [](vroom::Id vehicle, std::vector &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 std::string &description, 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) diff --git a/src/bind/solution/solution.cpp b/src/bind/solution/solution.cpp index e12ff6c..bec30d9 100644 --- a/src/bind/solution/solution.cpp +++ b/src/bind/solution/solution.cpp @@ -33,7 +33,7 @@ void init_solution(py::module_ &m) { py::class_(m, "Solution") .def(py::init([](vroom::Solution s) { return s; })) - .def(py::init([](const vroom::Amount& zero_amount, + .def(py::init([](const vroom::Amount &zero_amount, std::vector &routes, std::vector &unassigned) { return new vroom::Solution(zero_amount, std::move(routes), diff --git a/src/bind/solution/summary.cpp b/src/bind/solution/summary.cpp index bd0f5bc..fda1e72 100644 --- a/src/bind/solution/summary.cpp +++ b/src/bind/solution/summary.cpp @@ -8,7 +8,7 @@ void init_summary(py::module_ &m) { py::class_(m, "Summary") .def(py::init<>()) - .def(py::init()) + .def(py::init()) .def_readwrite("cost", &vroom::Summary::cost) .def_readonly("routes", &vroom::Summary::routes) .def_readonly("unassigned", &vroom::Summary::unassigned) diff --git a/src/bind/time_window.cpp b/src/bind/time_window.cpp index 618d322..3fb0920 100644 --- a/src/bind/time_window.cpp +++ b/src/bind/time_window.cpp @@ -10,10 +10,12 @@ void init_time_window(py::module_ &m) { .def(py::init([]() { return new vroom::TimeWindow(); })) .def(py::init([](vroom::Duration start, vroom::Duration end) { return new vroom::TimeWindow(start, end); - }), py::arg("start"), py::arg("end")) + }), + py::arg("start"), py::arg("end")) .def("_is_default", &vroom::TimeWindow::is_default) .def(py::self < py::self) .def_readwrite("_start", &vroom::TimeWindow::start) .def_readwrite("_end", &vroom::TimeWindow::end) - .def_readonly_static("_DEFAULT_LENGTH", &vroom::TimeWindow::default_length); + .def_readonly_static("_DEFAULT_LENGTH", + &vroom::TimeWindow::default_length); } diff --git a/src/bind/utils.cpp b/src/bind/utils.cpp index 56a3682..23c2742 100644 --- a/src/bind/utils.cpp +++ b/src/bind/utils.cpp @@ -4,20 +4,10 @@ void init_utils(py::module_ &m) { - m.def( - "scale_from_user_duration", - &vroom::utils::scale_from_user_duration, - py::arg("duration") - ); - m.def( - "scale_to_user_duration", - &vroom::utils::scale_to_user_duration, - py::arg("duration") - ); - m.def( - "scale_to_user_cost", - &vroom::utils::scale_to_user_cost, - py::arg("cost") - ); - + m.def("scale_from_user_duration", &vroom::utils::scale_from_user_duration, + py::arg("duration")); + m.def("scale_to_user_duration", &vroom::utils::scale_to_user_duration, + py::arg("duration")); + m.def("scale_to_user_cost", &vroom::utils::scale_to_user_cost, + py::arg("cost")); } diff --git a/src/bind/vehicle.cpp b/src/bind/vehicle.cpp index da9f89d..1658893 100644 --- a/src/bind/vehicle.cpp +++ b/src/bind/vehicle.cpp @@ -7,42 +7,35 @@ namespace py = pybind11; void init_vehicle(py::module_ &m) { py::class_(m, "VehicleCosts") - .def(py::init(), - "VehicleCost constructor.", - py::arg("fixed") = 0, py::arg("per_hour") = 3600) + .def(py::init(), + "VehicleCost constructor.", py::arg("fixed") = 0, + py::arg("per_hour") = 3600) .def_readonly("_fixed", &vroom::VehicleCosts::fixed) .def_readonly("_per_hour", &vroom::VehicleCosts::per_hour); py::class_(m, "CostWrapper") - .def(py::init(), - "CostWrapper constructor", - py::arg("speed_factor"), py::arg("per_hour"), py::arg("per_km")) - .def("set_durations_matrix", &vroom::CostWrapper::set_durations_matrix) - .def("set_distances_matrix", &vroom::CostWrapper::set_distances_matrix) - .def("set_costs_matrix", &vroom::CostWrapper::set_costs_matrix); + .def(py::init(), + "CostWrapper constructor", py::arg("speed_factor"), + py::arg("per_hour"), py::arg("per_km")) + .def("set_durations_matrix", &vroom::CostWrapper::set_durations_matrix) + .def("set_distances_matrix", &vroom::CostWrapper::set_distances_matrix) + .def("set_costs_matrix", &vroom::CostWrapper::set_costs_matrix); py::class_(m, "Vehicle") .def(py::init &, std::optional &, std::string &, vroom::Amount &, vroom::Skills &, vroom::TimeWindow &, - std::vector &, std::string &, vroom::VehicleCosts, double, - std::optional&, + std::vector &, std::string &, + vroom::VehicleCosts, double, std::optional &, std::optional &, std::optional &, std::vector &>(), "Vehicle constructor.", py::arg("id"), py::arg("start"), - py::arg("end"), py::arg("profile"), - py::arg("capacity"), - py::arg("skills"), - py::arg("time_window"), - py::arg("breaks"), - py::arg("description"), - py::arg("costs"), - py::arg("speed_factor"), - py::arg("max_tasks"), - py::arg("max_travel_time"), - py::arg("max_distance"), - py::arg("steps")) + py::arg("end"), py::arg("profile"), py::arg("capacity"), + py::arg("skills"), py::arg("time_window"), py::arg("breaks"), + py::arg("description"), py::arg("costs"), py::arg("speed_factor"), + py::arg("max_tasks"), py::arg("max_travel_time"), + py::arg("max_distance"), py::arg("steps")) // .def("has_start", &vroom::Vehicle::has_start) // .def("has_end", &vroom::Vehicle::has_end) .def("_has_same_locations", &vroom::Vehicle::has_same_locations) diff --git a/src/vroom/__init__.py b/src/vroom/__init__.py index 3e8209e..7293df9 100644 --- a/src/vroom/__init__.py +++ b/src/vroom/__init__.py @@ -1,4 +1,5 @@ """Vehicle routing open-source optimization machine (VROOM).""" + import sys from typing import Optional, Sequence from ._vroom import _main, JOB_TYPE, STEP_TYPE # type: ignore diff --git a/src/vroom/amount.py b/src/vroom/amount.py index 675f906..1724206 100644 --- a/src/vroom/amount.py +++ b/src/vroom/amount.py @@ -1,4 +1,5 @@ """An array of integers describing multidimensional quantities.""" + from __future__ import annotations from typing import Sequence, Union @@ -41,7 +42,7 @@ class Amount(_vroom.Amount): def __init__( self, - amount: Union[Amount, Sequence[int]] = (), + amount: Union[Amount, Sequence[int], numpy.ndarray] = (), ) -> None: """ Initialize. diff --git a/src/vroom/break_.py b/src/vroom/break_.py index 4528cf8..56bfdb2 100644 --- a/src/vroom/break_.py +++ b/src/vroom/break_.py @@ -109,8 +109,7 @@ def max_load(self, value: Union[None, Amount, Sequence[int]]) -> None: def is_valid_start(self, time: int): """Check if break has a valid start time.""" - return self._is_valid_start( - time=_vroom.scale_from_user_duration(time)) + return self._is_valid_start(time=_vroom.scale_from_user_duration(time)) def __repr__(self) -> str: args = [f"{self.id}"] diff --git a/src/vroom/input/input.py b/src/vroom/input/input.py index 26bc509..3fe8581 100644 --- a/src/vroom/input/input.py +++ b/src/vroom/input/input.py @@ -1,4 +1,5 @@ """VROOM input definition.""" + from __future__ import annotations from typing import Dict, Optional, Sequence, Set, Union from pathlib import Path @@ -75,8 +76,9 @@ def __repr__(self) -> str: args.append(f"router={self._router}") return f"{self.__class__.__name__}({', '.join(args)})" - @staticmethod + @classmethod def from_json( + cls, filepath: Path, servers: Optional[Dict[str, Union[str, _vroom.Server]]] = None, router: _vroom.ROUTER = _vroom.ROUTER.OSRM, @@ -107,7 +109,7 @@ def from_json( if geometry is None: geometry = servers is not None if geometry: - self._set_geometry(True) + cls._set_geometry(True) instance = Input(servers=servers, router=router) with open(filepath) as handle: instance._from_json(handle.read(), geometry) @@ -317,7 +319,6 @@ def solve( exploration_level=exploration_level, nb_threads=nb_threads, ) - ) solution._geometry = self._geometry return solution diff --git a/src/vroom/input/vehicle_step.py b/src/vroom/input/vehicle_step.py index 003ddc3..803deb1 100644 --- a/src/vroom/input/vehicle_step.py +++ b/src/vroom/input/vehicle_step.py @@ -466,7 +466,7 @@ def __new__( if step_type._step_type in (_vroom.STEP_TYPE.START, _vroom.STEP_TYPE.END): assert id == 0 id = None - + service_at = step_type._forced_service._service_at service_after = step_type._forced_service._service_after service_before = step_type._forced_service._service_before diff --git a/src/vroom/solution/solution.py b/src/vroom/solution/solution.py index 7a2c0ba..036a2c4 100644 --- a/src/vroom/solution/solution.py +++ b/src/vroom/solution/solution.py @@ -1,4 +1,5 @@ """The computed solutions.""" + from typing import Any, Dict, Union from pathlib import Path import io @@ -72,9 +73,9 @@ def routes(self) -> pandas.DataFrame: "service": array["service"], "waiting_time": array["waiting_time"], "location_index": array["location_index"], - "longitude": pandas.array(array["longitude"]), - "latitude": pandas.array(array["latitude"]), - "id": pandas.array(array["id"], dtype="Int64"), + "longitude": pandas.array(array["longitude"].tolist()), + "latitude": pandas.array(array["latitude"].tolist()), + "id": pandas.array(array["id"].tolist(), dtype="Int64"), "description": array["description"].astype("U40"), } ) diff --git a/src/vroom/time_window.py b/src/vroom/time_window.py index bdfa845..1125d50 100644 --- a/src/vroom/time_window.py +++ b/src/vroom/time_window.py @@ -1,9 +1,8 @@ """Time window for when a delivery/pickup/task is possible.""" + from __future__ import annotations from typing import Any, Optional, Sequence, Union -import numpy - from . import _vroom diff --git a/src/vroom/vehicle.py b/src/vroom/vehicle.py index c7cc680..b62b3fd 100644 --- a/src/vroom/vehicle.py +++ b/src/vroom/vehicle.py @@ -172,6 +172,7 @@ def __repr__(self) -> str: ("speed_factor", 1.0), ("max_tasks", MAX_UINT), ("max_travel_time", _vroom.scale_to_user_duration(MAX_INT)), + ("max_distance", MAX_UINT), ("steps", []), ]: attribute = getattr(self, name) From b8a5301333716cc6b709ae8782b5b11078ec1e4e Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 22 May 2024 17:53:14 +0200 Subject: [PATCH 09/25] Add set_distances_matrix --- src/bind/input/input.cpp | 6 ++++++ src/vroom/input/input.py | 20 ++++++++++++++++++++ src/vroom/vehicle.py | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/src/bind/input/input.cpp b/src/bind/input/input.cpp index 35316e8..b95b4a7 100644 --- a/src/bind/input/input.cpp +++ b/src/bind/input/input.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -32,6 +33,11 @@ void init_input(py::module_ &m) { vroom::Matrix &m) { self.set_durations_matrix(profile, std::move(m)); }) + .def("_set_distances_matrix", + [](vroom::Input &self, const std::string &profile, + vroom::Matrix &m) { + self.set_distances_matrix(profile, std::move(m)); + }) .def("_set_costs_matrix", [](vroom::Input &self, const std::string &profile, vroom::Matrix &m) { diff --git a/src/vroom/input/input.py b/src/vroom/input/input.py index 3fe8581..1e886bb 100644 --- a/src/vroom/input/input.py +++ b/src/vroom/input/input.py @@ -289,6 +289,26 @@ def set_durations_matrix( matrix_input = _vroom.Matrix(numpy.asarray(matrix_input, dtype="uint32")) self._set_durations_matrix(profile, matrix_input) + def set_distances_matrix( + self, + profile: str, + matrix_input: ArrayLike, + ) -> None: + """Set distances matrix. + + Args: + profile: + Name of the transportation category profile in question. + Typically "car", "truck", etc. + matrix_input: + A square matrix consisting of distances between each location of + interest. Diagonal is canonically set to 0. + """ + assert isinstance(profile, str) + if not isinstance(matrix_input, _vroom.Matrix): + matrix_input = _vroom.Matrix(numpy.asarray(matrix_input, dtype="uint32")) + self._set_distances_matrix(profile, matrix_input) + def set_costs_matrix( self, profile: str, diff --git a/src/vroom/vehicle.py b/src/vroom/vehicle.py index b62b3fd..8264327 100644 --- a/src/vroom/vehicle.py +++ b/src/vroom/vehicle.py @@ -240,6 +240,10 @@ def max_tasks(self) -> str: def max_travel_time(self) -> str: return _vroom.scale_to_user_duration(self._max_travel_time) + @property + def max_distance(self) -> str: + return self._max_distance + @property def steps(self) -> List[VehicleStep]: return [VehicleStep(step) for step in self._steps] From 347b5c4bc06a9be4ff1e80b1ccffb9a2efe7d0e8 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 22 May 2024 20:44:10 +0200 Subject: [PATCH 10/25] Add missing includes --- src/_vroom.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/_vroom.cpp b/src/_vroom.cpp index 1b082eb..776e588 100644 --- a/src/_vroom.cpp +++ b/src/_vroom.cpp @@ -30,6 +30,7 @@ #include "algorithms/heuristics/heuristics.cpp" #include "algorithms/local_search/local_search.cpp" #include "algorithms/local_search/operator.cpp" +#include "algorithms/local_search/top_insertions.cpp" #include "algorithms/validation/check.h" // #include "routing/libosrm_wrapper.cpp" @@ -41,6 +42,7 @@ #include "structures/typedefs.h" #include "structures/generic/edge.cpp" +#include "structures/generic/matrix.cpp" #include "structures/generic/undirected_graph.cpp" #include "structures/vroom/cost_wrapper.cpp" @@ -50,6 +52,7 @@ #include "structures/vroom/solution/computing_times.cpp" #include "structures/vroom/solution/violations.cpp" +#include "structures/vroom/bbox.cpp" #include "problems/cvrp/cvrp.cpp" #include "problems/cvrp/operators/cross_exchange.cpp" @@ -62,11 +65,13 @@ #include "problems/cvrp/operators/mixed_exchange.cpp" #include "problems/cvrp/operators/or_opt.cpp" #include "problems/cvrp/operators/pd_shift.cpp" +#include "problems/cvrp/operators/priority_replace.cpp" #include "problems/cvrp/operators/relocate.cpp" #include "problems/cvrp/operators/reverse_two_opt.cpp" #include "problems/cvrp/operators/route_exchange.cpp" #include "problems/cvrp/operators/route_split.cpp" #include "problems/cvrp/operators/swap_star.cpp" +#include "problems/cvrp/operators/tsp_fix.cpp" #include "problems/cvrp/operators/two_opt.cpp" #include "problems/cvrp/operators/unassigned_exchange.cpp" #include "problems/vrp.cpp" @@ -81,11 +86,13 @@ #include "problems/vrptw/operators/mixed_exchange.cpp" #include "problems/vrptw/operators/or_opt.cpp" #include "problems/vrptw/operators/pd_shift.cpp" +#include "problems/vrptw/operators/priority_replace.cpp" #include "problems/vrptw/operators/relocate.cpp" #include "problems/vrptw/operators/reverse_two_opt.cpp" #include "problems/vrptw/operators/route_exchange.cpp" #include "problems/vrptw/operators/route_split.cpp" #include "problems/vrptw/operators/swap_star.cpp" +#include "problems/vrptw/operators/tsp_fix.cpp" #include "problems/vrptw/operators/two_opt.cpp" #include "problems/vrptw/operators/unassigned_exchange.cpp" #include "problems/vrptw/vrptw.cpp" @@ -94,7 +101,7 @@ #include "problems/tsp/heuristics/local_search.cpp" #include "problems/tsp/tsp.cpp" -#include "utils/helpers.h" +#include "utils/helpers.cpp" #include "utils/version.cpp" namespace py = pybind11; From e728155bf452d080f69d5f0ac40352eb6c2b8eeb Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Thu, 23 May 2024 12:28:01 +0200 Subject: [PATCH 11/25] Re-add _lshift --- src/bind/amount.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bind/amount.cpp b/src/bind/amount.cpp index 39cfd81..e6470cb 100644 --- a/src/bind/amount.cpp +++ b/src/bind/amount.cpp @@ -28,6 +28,8 @@ void init_amount(py::module_ &m) { py::format_descriptor::format(), 1, {a.size()}, {sizeof(int64_t)}); }) + .def("_lshift", + [](const vroom::Amount &a, const vroom::Amount &b) { return a < b; }) .def("_le", [](const vroom::Amount &a, const vroom::Amount &b) { return a <= b; }) .def("_push_back", &vroom::Amount::push_back) From da6ca51e791618b13d708ca2a1505502aa663f7f Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Thu, 23 May 2024 12:28:56 +0200 Subject: [PATCH 12/25] Fix error involving location and has_coordinates --- src/bind/solution/solution.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/bind/solution/solution.cpp b/src/bind/solution/solution.cpp index bec30d9..a3f6c7d 100644 --- a/src/bind/solution/solution.cpp +++ b/src/bind/solution/solution.cpp @@ -71,12 +71,16 @@ 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_value() - ? step.location.value().lat() - : NA_SUBSTITUTE; - ptr[idx].latitude = step.location.has_value() - ? step.location.value().lat() - : NA_SUBSTITUTE; + ptr[idx].longitude = + step.location.has_value() && + step.location.value().has_coordinates() + ? step.location.value().coordinates().lon + : NA_SUBSTITUTE; + ptr[idx].latitude = + step.location.has_value() && + step.location.value().has_coordinates() + ? step.location.value().coordinates().lat + : NA_SUBSTITUTE; ptr[idx].location_index = step.location.has_value() ? step.location.value().index() : NA_SUBSTITUTE; From c9fbcd37102094e0a5f10b09757833130db80934 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Thu, 23 May 2024 12:30:14 +0200 Subject: [PATCH 13/25] Fix default value for max_distance --- src/_vroom.cpp | 2 +- src/vroom/vehicle.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/_vroom.cpp b/src/_vroom.cpp index 776e588..1988d6a 100644 --- a/src/_vroom.cpp +++ b/src/_vroom.cpp @@ -50,9 +50,9 @@ #include "structures/vroom/solution_state.cpp" #include "structures/vroom/tw_route.cpp" +#include "structures/vroom/bbox.cpp" #include "structures/vroom/solution/computing_times.cpp" #include "structures/vroom/solution/violations.cpp" -#include "structures/vroom/bbox.cpp" #include "problems/cvrp/cvrp.cpp" #include "problems/cvrp/operators/cross_exchange.cpp" diff --git a/src/vroom/vehicle.py b/src/vroom/vehicle.py index 8264327..2c0d6a8 100644 --- a/src/vroom/vehicle.py +++ b/src/vroom/vehicle.py @@ -11,8 +11,9 @@ from . import _vroom -MAX_UINT = int(numpy.iinfo(numpy.uintp).max) +MAX_UINT = int(numpy.iinfo(numpy.uint).max) MAX_INT = int(numpy.iinfo(numpy.intp).max) +MAX_UINT32 = int(numpy.iinfo(numpy.uint32).max) class VehicleCosts(_vroom.VehicleCosts): @@ -91,6 +92,10 @@ class Vehicle(_vroom.Vehicle): the default. max_tasks: The maximum number of tasks this vehicle can perform. + max_travel_time: + An integer defining the maximum travel time for this vehicle. + max_distance: + An integer defining the maximum distance for this vehicle. steps: Set of custom steps this vehicle should take. @@ -115,7 +120,7 @@ def __init__( speed_factor: float = 1.0, max_tasks: Optional[int] = MAX_UINT, max_travel_time: Optional[int] = None, - max_distance: Optional[int] = None, + max_distance: Optional[int] = MAX_UINT32, steps: Sequence[VehicleStep] = (), ) -> None: self._speed_factor = float(speed_factor) @@ -172,7 +177,7 @@ def __repr__(self) -> str: ("speed_factor", 1.0), ("max_tasks", MAX_UINT), ("max_travel_time", _vroom.scale_to_user_duration(MAX_INT)), - ("max_distance", MAX_UINT), + ("max_distance", MAX_UINT32), ("steps", []), ]: attribute = getattr(self, name) From 1ea9dad83efef259bffb8755ddb12c4e803d26c5 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Thu, 23 May 2024 12:30:21 +0200 Subject: [PATCH 14/25] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index edaf6e8..433945b 100644 --- a/README.rst +++ b/README.rst @@ -96,7 +96,7 @@ Usage with a routing engine >>> sol = problem_instance.solve(exploration_level=5, nb_threads=4) >>> print(sol.summary.duration) - 2704 + 2702 Installation ------------ From ee59f994d9c3a2e891188cb960d5345ff98c6fe0 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Thu, 23 May 2024 14:21:10 +0200 Subject: [PATCH 15/25] Show distance column in solution only when required --- src/vroom/input/input.py | 3 +++ src/vroom/solution/solution.py | 9 ++++++--- test/test_libvroom_examples.py | 9 +++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/vroom/input/input.py b/src/vroom/input/input.py index 1e886bb..75eff3b 100644 --- a/src/vroom/input/input.py +++ b/src/vroom/input/input.py @@ -31,6 +31,7 @@ class Input(_vroom.Input): """ _geometry: bool = False + _distances: bool = False def __init__( self, @@ -308,6 +309,7 @@ def set_distances_matrix( if not isinstance(matrix_input, _vroom.Matrix): matrix_input = _vroom.Matrix(numpy.asarray(matrix_input, dtype="uint32")) self._set_distances_matrix(profile, matrix_input) + self._distances = True def set_costs_matrix( self, @@ -341,4 +343,5 @@ def solve( ) ) solution._geometry = self._geometry + solution._distances = self._distances return solution diff --git a/src/vroom/solution/solution.py b/src/vroom/solution/solution.py index 036a2c4..c87c873 100644 --- a/src/vroom/solution/solution.py +++ b/src/vroom/solution/solution.py @@ -24,6 +24,7 @@ class Solution(_vroom.Solution): """ _geometry: bool = False + _distances: bool = False @property def routes(self) -> pandas.DataFrame: @@ -58,6 +59,8 @@ def routes(self) -> pandas.DataFrame: The identifier for the task that was performed. description: Text description provided to this step. + distance: + Total route distance. """ array = numpy.asarray(self._routes_numpy()) frame = pandas.DataFrame( @@ -84,7 +87,7 @@ def routes(self) -> pandas.DataFrame: del frame[column] else: frame.loc[frame[column] == NA_SUBSTITUTE, column] = pandas.NA - if self._geometry: + if self._geometry or self._distances: frame["distance"] = array["distance"] return frame @@ -92,7 +95,7 @@ def to_dict(self) -> Dict[str, Any]: """Convert solution into VROOM compatible dictionary.""" stream = io.StringIO() with redirect_stdout(stream): - if self._geometry: + if self._geometry or self._distances: self._geometry_solution_json() else: self._solution_json() @@ -102,7 +105,7 @@ def to_json(self, filepath: Union[str, Path]) -> None: """Store solution into VROOM compatible JSON file.""" with open(filepath, "w") as handler: with redirect_stdout(handler): - if self._geometry: + if self._geometry or self._distances: self._geometry_solution_json() else: self._solution_json() diff --git a/test/test_libvroom_examples.py b/test/test_libvroom_examples.py index d7f35b4..dc7baa5 100644 --- a/test/test_libvroom_examples.py +++ b/test/test_libvroom_examples.py @@ -15,6 +15,13 @@ def test_example_with_custom_matrix(): [197, 2256, 0, 1102], [1299, 3153, 1102, 0]], ) + problem_instance.set_distances_matrix( + profile="car", + matrix_input=[[0, 21040, 1970, 12990], + [21030, 0, 22550, 31520], + [1970, 22560, 0, 11020], + [12990, 31530, 11020, 0]], + ) problem_instance.add_vehicle([vroom.Vehicle(7, start=0, end=0), vroom.Vehicle(8, start=2, end=2)]) problem_instance.add_job([vroom.Job(id=1414, location=0), @@ -37,3 +44,5 @@ def test_example_with_custom_matrix(): assert numpy.all(routes.arrival == [0, 2104, 4207, 4207, 0, 1102, 2204, 2204]) assert numpy.all(routes.location_index == [0, 1, 0, 0, 2, 3, 2, 2]) + assert numpy.all(routes.distance == [0, 21040, 42070, 42070, + 0, 11020, 22040, 22040]) \ No newline at end of file From 6b1012b670e7d0078ec5aa248b1576eb30a48622 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Thu, 23 May 2024 14:21:49 +0200 Subject: [PATCH 16/25] Add tests for max_distance and max_travel_time --- test/test_vehicle.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test_vehicle.py b/test/test_vehicle.py index 6a4b188..c26b41c 100644 --- a/test/test_vehicle.py +++ b/test/test_vehicle.py @@ -19,6 +19,10 @@ def test_repr(): == "vroom.Vehicle(3, end=7, speed_factor=2.0)") assert (repr(vroom.Vehicle(3, start=7, max_tasks=17)) == "vroom.Vehicle(3, start=7, max_tasks=17)") + assert (repr(vroom.Vehicle(3, start=7, max_distance=17)) + == "vroom.Vehicle(3, start=7, max_distance=17)") + assert (repr(vroom.Vehicle(3, start=7, max_travel_time=17)) + == "vroom.Vehicle(3, start=7, max_travel_time=17)") assert (repr(vroom.Vehicle(3, end=7, steps=[vroom.VehicleStep("single", 3)])) == """vroom.Vehicle(3, end=7, \ steps=[vroom.VehicleStepStart(), vroom.VehicleStepSingle(3), vroom.VehicleStepEnd()])""") From eaea1bfae811b20e02b38c293c4800e63127c0fc Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Thu, 23 May 2024 16:50:10 +0200 Subject: [PATCH 17/25] Update checkout, setup-python, and codecov actions --- .github/workflows/main_push.yml | 4 ++-- .github/workflows/pull_request.yml | 8 ++++---- .github/workflows/release.yml | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main_push.yml b/.github/workflows/main_push.yml index 74a4d57..940911d 100644 --- a/.github/workflows/main_push.yml +++ b/.github/workflows/main_push.yml @@ -21,7 +21,7 @@ jobs: platform: windows steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive @@ -36,7 +36,7 @@ jobs: key: conan-${{ matrix.image }}-${{ hashFiles('conanfile.txt') }} - name: Configure Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 if: matrix.platform == 'windows' && steps.cache-conan.outputs.cache-hit != 'true' with: python-version: '3.x' diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 64e70e7..e28ccec 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -14,11 +14,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: "3.7" @@ -40,7 +40,7 @@ jobs: run: make test - name: "Upload python coverage" - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.codecov_token }} files: 'coverage/coverage.xml' @@ -48,7 +48,7 @@ jobs: fail_ci_if_error: true - name: "Upload binding coverage" - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.codecov_token }} files: 'coverage/*.gcov' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8e758c7..d3e9c95 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: name: sdist runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Build sdist run: pipx run build --sdist @@ -39,7 +39,7 @@ jobs: platform: windows steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive @@ -54,7 +54,7 @@ jobs: key: conan-${{ matrix.image }}-${{ hashFiles('conanfile.txt') }} - name: Configure Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 if: matrix.platform == 'windows' && steps.cache-conan.outputs.cache-hit != 'true' with: python-version: '3.x' @@ -89,7 +89,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/setup-python@v2 + - uses: actions/setup-python@v5 - uses: actions/download-artifact@v3 with: From e7372f2c204f9b401fde2ef28f2c050d0b71d22f Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Mon, 10 Jun 2024 19:30:56 +0200 Subject: [PATCH 18/25] Update LLVM@18 to support C++20 --- .github/workflows/release.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d3e9c95..bf02a85 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -70,9 +70,23 @@ jobs: conan config set "storage.path=$env:GITHUB_WORKSPACE/conan_data" conan install --build=openssl --install-folder conan_build . - - uses: pypa/cibuildwheel@v2.16.5 + - name: Install llvm@18 and link asio on macOS + if: matrix.platform == 'macos' + run: | + brew install llvm@18 + echo "$(brew --prefix)/opt/llvm/bin" >> $GITHUB_PATH + echo "LDFLAGS=-L$(brew --prefix)/opt/llvm/lib -L$(brew --prefix)/opt/llvm/lib/c++ -L/opt/homebrew/lib -Wl,-rpath,$(brew --prefix)/opt/llvm/lib/c++" >> "$GITHUB_ENV" + echo "CPPFLAGS=-I$(brew --prefix)/opt/llvm/include -I/opt/homebrew/include -fexperimental-library" >> "$GITHUB_ENV" + echo "CC=clang" >> "$GITHUB_ENV" + echo "CXX=clang++" >> "$GITHUB_ENV" + echo "OBJC=clang" >> "$GITHUB_ENV" + echo "CC_LD=lld" >> "$GITHUB_ENV" + echo "CXX_LD=lld" >> "$GITHUB_ENV" + echo "OBJC_LD=lld" >> "$GITHUB_ENV" + + - uses: pypa/cibuildwheel@v2.18.1 env: - MACOSX_DEPLOYMENT_TARGET: 10.14 + MACOSX_DEPLOYMENT_TARGET: 14 - name: Verify clean directory run: git diff --exit-code From 65788596a0873e4390b9ae48e2c3df55f9b0e336 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Mon, 10 Jun 2024 19:35:44 +0200 Subject: [PATCH 19/25] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 433945b..6149ac3 100644 --- a/README.rst +++ b/README.rst @@ -96,7 +96,7 @@ Usage with a routing engine >>> sol = problem_instance.solve(exploration_level=5, nb_threads=4) >>> print(sol.summary.duration) - 2702 + 2714 Installation ------------ From cccfb159e95c412bb47ad6b59ac99112368ccc60 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 3 Jul 2024 01:05:50 +0200 Subject: [PATCH 20/25] Update release.yml --- .github/workflows/release.yml | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dd5c776..00187ca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,10 +2,8 @@ name: release on: push: - tags: - - '*' - branches-ignore: - - '*' + branches: + - mac-os-test jobs: build_sdist: @@ -78,6 +76,27 @@ jobs: with: platforms: all + - name: Install llvm@18 + if: matrix.platform == 'macos-intel' || matrix.platform == 'macos-arm' + run: | + echo "$(brew --prefix)/opt/llvm/bin" >> $GITHUB_PATH + + echo " + LDFLAGS=-L$(brew --prefix)/opt/llvm/lib + -L$(brew --prefix)/opt/llvm/lib/c++ + -L/opt/homebrew/lib + -Wl, + -rpath,$(brew --prefix)/opt/llvm/lib/c++" >> "$GITHUB_ENV" + echo "CPPFLAGS=-I$(brew --prefix)/opt/llvm/include + -I/opt/homebrew/include + -fexperimental-library" >> "$GITHUB_ENV" + echo "CC=clang" >> "$GITHUB_ENV" + echo "CXX=clang++" >> "$GITHUB_ENV" + echo "OBJC=clang" >> "$GITHUB_ENV" + echo "CC_LD=lld" >> "$GITHUB_ENV" + echo "CXX_LD=lld" >> "$GITHUB_ENV" + echo "OBJC_LD=lld" >> "$GITHUB_ENV" + - name: Build wheels if: matrix.platform != 'macos-arm' uses: pypa/cibuildwheel@v2.19.1 From cf79781e1c503604895c6786a5709e66f35040bf Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 3 Jul 2024 01:08:52 +0200 Subject: [PATCH 21/25] Update release.yml --- .github/workflows/release.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 00187ca..143e5db 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -79,17 +79,10 @@ jobs: - name: Install llvm@18 if: matrix.platform == 'macos-intel' || matrix.platform == 'macos-arm' run: | + brew install llvm@18 echo "$(brew --prefix)/opt/llvm/bin" >> $GITHUB_PATH - - echo " - LDFLAGS=-L$(brew --prefix)/opt/llvm/lib - -L$(brew --prefix)/opt/llvm/lib/c++ - -L/opt/homebrew/lib - -Wl, - -rpath,$(brew --prefix)/opt/llvm/lib/c++" >> "$GITHUB_ENV" - echo "CPPFLAGS=-I$(brew --prefix)/opt/llvm/include - -I/opt/homebrew/include - -fexperimental-library" >> "$GITHUB_ENV" + echo "LDFLAGS=-L$(brew --prefix)/opt/llvm/lib -L$(brew --prefix)/opt/llvm/lib/c++ -L/opt/homebrew/lib -Wl,-rpath,$(brew --prefix)/opt/llvm/lib/c++" >> "$GITHUB_ENV" + echo "CPPFLAGS=-I$(brew --prefix)/opt/llvm/include -I/opt/homebrew/include -fexperimental-library" >> "$GITHUB_ENV" echo "CC=clang" >> "$GITHUB_ENV" echo "CXX=clang++" >> "$GITHUB_ENV" echo "OBJC=clang" >> "$GITHUB_ENV" From 1cd7911f6e3dab40c6d236bd61c8477c0179817e Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 3 Jul 2024 01:12:17 +0200 Subject: [PATCH 22/25] Update release.yml --- .github/workflows/release.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 143e5db..ecfe5a7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,8 +2,10 @@ name: release on: push: - branches: - - mac-os-test + tags: + - '*' + branches-ignore: + - '*' jobs: build_sdist: From 16822edb91c1ff5826c2150abda79563c492af3d Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Wed, 3 Jul 2024 14:07:44 +0200 Subject: [PATCH 23/25] Move flags envs and install --- .github/workflows/release.yml | 28 +++++++++++++++++----------- pyproject.toml | 2 ++ setup.py | 5 +++++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ecfe5a7..577ce93 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -78,19 +78,12 @@ jobs: with: platforms: all - - name: Install llvm@18 - if: matrix.platform == 'macos-intel' || matrix.platform == 'macos-arm' + + - name: Link LLVM@18 + if: matrix.platform == 'macos-intel' run: | - brew install llvm@18 echo "$(brew --prefix)/opt/llvm/bin" >> $GITHUB_PATH - echo "LDFLAGS=-L$(brew --prefix)/opt/llvm/lib -L$(brew --prefix)/opt/llvm/lib/c++ -L/opt/homebrew/lib -Wl,-rpath,$(brew --prefix)/opt/llvm/lib/c++" >> "$GITHUB_ENV" - echo "CPPFLAGS=-I$(brew --prefix)/opt/llvm/include -I/opt/homebrew/include -fexperimental-library" >> "$GITHUB_ENV" - echo "CC=clang" >> "$GITHUB_ENV" - echo "CXX=clang++" >> "$GITHUB_ENV" - echo "OBJC=clang" >> "$GITHUB_ENV" - echo "CC_LD=lld" >> "$GITHUB_ENV" - echo "CXX_LD=lld" >> "$GITHUB_ENV" - echo "OBJC_LD=lld" >> "$GITHUB_ENV" + - name: Build wheels if: matrix.platform != 'macos-arm' @@ -98,12 +91,25 @@ jobs: env: MACOSX_DEPLOYMENT_TARGET: 13.0 CIBW_ARCHS_LINUX: x86_64 aarch64 + CC: clang + CXX: clang++ + OBJC: clang + CC_LD: lld + CXX_LD: lld + OBJC_LD: lld + - name: Build wheels if: matrix.platform == 'macos-arm' uses: pypa/cibuildwheel@v2.19.1 env: MACOSX_DEPLOYMENT_TARGET: 14.0 + CC: clang + CXX: clang++ + OBJC: clang + CC_LD: lld + CXX_LD: lld + OBJC_LD: lld - name: Verify clean directory run: git diff --exit-code diff --git a/pyproject.toml b/pyproject.toml index 76f20ed..1f4d0ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,4 +48,6 @@ apk add openssl-dev before-all = """ brew install openssl@1.1 brew install --ignore-dependencies asio +brew install llvm@18 +brew link --overwrite -f llvm@18 """ diff --git a/setup.py b/setup.py index 09082e7..c406247 100644 --- a/setup.py +++ b/setup.py @@ -51,8 +51,13 @@ prefix = run(["brew", "--prefix"], capture_output=True).stdout.decode("utf-8")[:-1] include_dirs.append(f"{prefix}/opt/openssl@1.1/include") include_dirs.append(f"{prefix}/include") + include_dirs.append(f"{prefix}/opt/llvm/include") extra_link_args.insert(0, f"-L{prefix}/lib") extra_link_args.insert(0, f"-L{prefix}/opt/openssl@1.1/lib") + extra_link_args.insert(0, f"-L{prefix}/opt/llvm/lib") + extra_link_args.insert(0, f"-L{prefix}/opt/llvm/lib/c++") + extra_link_args.append(f"-Wl,-rpath,{prefix}/opt/llvm/lib/c++") + extra_compile_args.append("-fexperimental-library") # try conan dependency resolution conanfile = tuple(Path(__file__).parent.resolve().rglob("conanbuildinfo.json")) From 97744d241991bc261093b84b76b3a3c95e076551 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Sun, 7 Jul 2024 12:13:08 +0200 Subject: [PATCH 24/25] Use gcc-13 on macos (#6) * Move flags envs and install * Revert "Update release.yml" This reverts commit 1cd7911f6e3dab40c6d236bd61c8477c0179817e. * Update setup.py * Update release.yml * Update release.yml * Update release.yml * Test brew link * Cleaning * Revert "Cleaning" This reverts commit a131e0bd4ca078dc35dc6b4d0ed58099ba159f79. * Update release.yml * Cleaning * Update release.yml * Update release.yml * Fix error on macos-intel * Update release.yml * Cross compile * Update release.yml * Update setup.py * Update * Only build for OSX Arm * Ad universal2 * x86_64 * Update pyproject.toml * Update pyproject.toml * Use openssl@1.1 * Remove openssl@1.1 * Play with openssl * Test * Clean * Try gcc * Update pyproject.toml * Update release.yml * Update release.yml * Update release.yml * Update setup.py * Remove extra instructions * Update pyproject.toml --- .github/workflows/release.yml | 37 +++++++++-------------------------- README.rst | 2 +- pyproject.toml | 3 --- setup.py | 6 +----- 4 files changed, 11 insertions(+), 37 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 577ce93..1784040 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,10 +2,8 @@ name: release on: push: - tags: - - '*' - branches-ignore: - - '*' + branches: + - mac-os-test jobs: build_sdist: @@ -78,38 +76,21 @@ jobs: with: platforms: all - - - name: Link LLVM@18 - if: matrix.platform == 'macos-intel' - run: | - echo "$(brew --prefix)/opt/llvm/bin" >> $GITHUB_PATH - - - name: Build wheels if: matrix.platform != 'macos-arm' - uses: pypa/cibuildwheel@v2.19.1 + uses: pypa/cibuildwheel@v2.19.2 env: MACOSX_DEPLOYMENT_TARGET: 13.0 - CIBW_ARCHS_LINUX: x86_64 aarch64 - CC: clang - CXX: clang++ - OBJC: clang - CC_LD: lld - CXX_LD: lld - OBJC_LD: lld - - + CC: gcc-13 + CXX: g++-13 + - name: Build wheels if: matrix.platform == 'macos-arm' - uses: pypa/cibuildwheel@v2.19.1 + uses: pypa/cibuildwheel@v2.19.2 env: MACOSX_DEPLOYMENT_TARGET: 14.0 - CC: clang - CXX: clang++ - OBJC: clang - CC_LD: lld - CXX_LD: lld - OBJC_LD: lld + CC: gcc-13 + CXX: g++-13 - name: Verify clean directory run: git diff --exit-code diff --git a/README.rst b/README.rst index 3ece7d1..89fd73c 100644 --- a/README.rst +++ b/README.rst @@ -113,7 +113,7 @@ Installation of the pre-compiled releases should be as simple as: The current minimal requirements are as follows: * Python at least version 3.9. -* Intel MacOS (or Rosetta2) at least version 13.0. +* Intel MacOS (or Rosetta2) at least version 14.0. * Apple Silicon MacOS at least version 14.0. * Windows on AMD64. * Linux on x86_64 and Aarch64 given glibc at least version 2.28. diff --git a/pyproject.toml b/pyproject.toml index 1f4d0ca..dddddfa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,8 +46,5 @@ apk add openssl-dev [tool.cibuildwheel.macos] before-all = """ -brew install openssl@1.1 brew install --ignore-dependencies asio -brew install llvm@18 -brew link --overwrite -f llvm@18 """ diff --git a/setup.py b/setup.py index c406247..eb6f328 100644 --- a/setup.py +++ b/setup.py @@ -51,13 +51,9 @@ prefix = run(["brew", "--prefix"], capture_output=True).stdout.decode("utf-8")[:-1] include_dirs.append(f"{prefix}/opt/openssl@1.1/include") include_dirs.append(f"{prefix}/include") - include_dirs.append(f"{prefix}/opt/llvm/include") extra_link_args.insert(0, f"-L{prefix}/lib") extra_link_args.insert(0, f"-L{prefix}/opt/openssl@1.1/lib") - extra_link_args.insert(0, f"-L{prefix}/opt/llvm/lib") - extra_link_args.insert(0, f"-L{prefix}/opt/llvm/lib/c++") - extra_link_args.append(f"-Wl,-rpath,{prefix}/opt/llvm/lib/c++") - extra_compile_args.append("-fexperimental-library") + extra_link_args.append(f"-Wl,-ld_classic") # try conan dependency resolution conanfile = tuple(Path(__file__).parent.resolve().rglob("conanbuildinfo.json")) From 4449941276d090bf06f464c49c06e3d9fa1e5063 Mon Sep 17 00:00:00 2001 From: Sebastiano Milardo Date: Sun, 7 Jul 2024 12:20:49 +0200 Subject: [PATCH 25/25] Update release.yml --- .github/workflows/release.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1784040..09534fe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,8 +2,10 @@ name: release on: push: - branches: - - mac-os-test + tags: + - '*' + branches-ignore: + - '*' jobs: build_sdist: