Skip to content
Merged
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
7 changes: 4 additions & 3 deletions src/bind/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ void init_vehicle(py::module_ &m) {
vroom::VehicleCosts, double, std::optional<size_t> &,
std::optional<vroom::UserDuration> &,
std::optional<vroom::UserDistance> &,
std::vector<vroom::VehicleStep> &>(),
std::vector<vroom::VehicleStep> &, 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)
Expand All @@ -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);
}
20 changes: 18 additions & 2 deletions src/vroom/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})"


Expand Down Expand Up @@ -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)
Expand All @@ -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__(
Expand All @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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", []),
Expand Down Expand Up @@ -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)

Expand Down
Loading