diff --git a/src/bind/vehicle.cpp b/src/bind/vehicle.cpp index 6d3011f..7c02221 100644 --- a/src/bind/vehicle.cpp +++ b/src/bind/vehicle.cpp @@ -30,13 +30,13 @@ void init_vehicle(py::module_ &m) { vroom::VehicleCosts, double, std::optional &, std::optional &, std::optional &, - std::vector &>(), + std::vector &, std::string &>(), "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("max_distance"), py::arg("steps"), py::arg("type_str") = "") // .def("has_start", &vroom::Vehicle::has_start) // .def("has_end", &vroom::Vehicle::has_end) .def("_has_same_locations", &vroom::Vehicle::has_same_locations) @@ -56,5 +56,6 @@ void init_vehicle(py::module_ &m) { .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); + .def_readonly("_steps", &vroom::Vehicle::steps) + .def_readonly("_type_str", &vroom::Vehicle::type_str); } diff --git a/src/vroom/vehicle.py b/src/vroom/vehicle.py index 6848f33..31396f6 100644 --- a/src/vroom/vehicle.py +++ b/src/vroom/vehicle.py @@ -58,7 +58,11 @@ def __bool__(self) -> bool: return self.fixed != 0 or self.per_hour != 3600 or self.per_km != 0 def __repr__(self): - args = f"fixed={self.fixed}, per_hour={self.per_hour}, per_km={self.per_km}" if self else "" + args = ( + f"fixed={self.fixed}, per_hour={self.per_hour}, per_km={self.per_km}" + if self + else "" + ) return f"{self.__class__.__name__}({args})" @@ -105,6 +109,8 @@ class Vehicle(_vroom.Vehicle): An integer defining the maximum distance for this vehicle. steps: Set of custom steps this vehicle should take. + type: + A string describing the vehicle type. Examples: >>> vroom.Vehicle(1, end=1) @@ -129,6 +135,7 @@ def __init__( max_travel_time: Optional[int] = None, max_distance: Optional[int] = MAX_UINT32, steps: Sequence[VehicleStep] = (), + type: str = "", ) -> None: self._speed_factor = float(speed_factor) _vroom.Vehicle.__init__( @@ -139,7 +146,9 @@ def __init__( profile=str(profile), capacity=Amount(capacity), skills=(set([]) if skills is None else skills), - time_window=(TimeWindow() if time_window is None else TimeWindow(time_window)), + time_window=( + TimeWindow() if time_window is None else TimeWindow(time_window) + ), breaks=[Break(break_) for break_ in breaks], description=str(description), costs=costs, @@ -148,6 +157,7 @@ def __init__( max_travel_time=max_travel_time, max_distance=max_distance, steps=steps, + type_str=type, ) assert isinstance(self.capacity, Amount) @@ -177,6 +187,8 @@ def __repr__(self) -> str: args.append(f"time_window={self.time_window.start, self.time_window.end}") if self.costs: args.append(f"costs={self.costs}") + if self.type: + args.append(f"type={self.type}") for name, default in [ ("breaks", []), @@ -261,6 +273,10 @@ def max_distance(self) -> str: def steps(self) -> List[VehicleStep]: return [VehicleStep(step) for step in self._steps] + @property + def type(self) -> str: + self._type_str + def has_same_locations(self, vehicle: Vehicle) -> bool: return self._has_same_locations(vehicle)