Skip to content

Commit

Permalink
Allow for capacities to be determined post init.
Browse files Browse the repository at this point in the history
Instead of pre-declaring amount_capacity in init, allow it to be None,
and instead verify it after it when the vehicles come in.
  • Loading branch information
jonathf committed Apr 25, 2022
1 parent 8c04882 commit fc918dd
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/vroom/input/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Input(_vroom.Input):

def __init__(
self,
amount_size: int = 0,
amount_size: Optional[int] = None,
servers: Optional[Dict[str, Union[str, _vroom.Server]]] = None,
router: _vroom.ROUTER = _vroom.ROUTER.OSRM,
) -> None:
Expand Down Expand Up @@ -59,13 +59,13 @@ def __init__(
self._servers = servers
self._router = router
_vroom.Input.__init__(self, servers=servers, router=router)
if amount_size:
if amount_size is not None:
self._set_amount_size(amount_size)

def __repr__(self) -> str:
"""String representation."""
args = []
if self._amount_size:
if self._amount_size is not None:
args.append(f"amount_size={self._amount_size}")
if self._servers:
args.append(f"servers={self._servers}")
Expand Down Expand Up @@ -131,8 +131,28 @@ def add_vehicle(
self,
vehicle: Union[Vehicle, Sequence[Vehicle]],
) -> None:
"""Add vehicle.
Args:
vehicle:
Vehicles to use to solve the vehicle problem. Vehicle type must
have a recognized profile, and all added vehicle must have the
same capacity.
"""
if isinstance(vehicle, _vroom.Vehicle):
vehicle = [vehicle]
if not vehicle:
return
amount_sizes = {len(vehicle_.capacity) for vehicle_ in vehicle}
if self._amount_size is not None:
amount_sizes.add(self._amount_size)
if len(amount_sizes) > 1:
raise _vroom.VroomInputException(
f"Incosistent capacity lengths: {amount_sizes}")
if self._amount_size is None:
size = amount_sizes.pop()
self._amount_size = size
self._set_amount_size(size)
for vehicle_ in vehicle:
self._add_vehicle(vehicle_)

Expand Down

0 comments on commit fc918dd

Please sign in to comment.