Skip to content

Commit

Permalink
Adds the input
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-quintero committed Dec 7, 2023
1 parent 2252a45 commit 03569cf
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 25 deletions.
54 changes: 54 additions & 0 deletions nextmv/nextroute/schema/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Defines the input class"""

from dataclasses import dataclass
from typing import Any

from .stop import AlternateStop, Stop, StopDefaults
from .vehicle import Vehicle, VehicleDefaults


@dataclass
class Defaults:
"""Default values for vehicles and stops."""

stops: StopDefaults | None
"""Default values for stops."""
vehicles: VehicleDefaults | None
"""Default values for vehicles."""


@dataclass
class DurationGroup:
"""Represents a group of stops that get additional duration whenever a stop
of the group is approached for the first time."""

group: list[str] | None
"""Stop IDs contained in the group."""
duration: int | None
"""Duration to add when visiting the group."""


@dataclass
class Input:
"""Input schema for Nextroute."""

alternate_stops: list[AlternateStop] | None
"""A set of alternate stops for the vehicles."""
custom_data: Any | None
"""Arbitrary data associated with the input."""
defaults: Defaults | None
"""Default values for vehicles and stops."""
distance_matrix: list[list[float]] | None
"""Matrix of travel distances in meters between stops."""
duratrion_groups: list[DurationGroup] | None
"""Duration in seconds added when approaching the group."""
duration_matrix: list[list[float]] | None
"""Matrix of travel durations in seconds between stops."""
options: Any | None
"""Arbitrary options."""
stop_groups: list[list[str]] | None
"""Groups of stops that must be part of the same route."""
stops: list[Stop] | None
"""Stops that must be visited by the vehicles."""
vehicles: list[Vehicle] | None
"""Vehicles that service the stops."""
2 changes: 1 addition & 1 deletion nextmv/nextroute/schema/location.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Defines the Location class."""
"""Defines the location class."""


from dataclasses import dataclass
Expand Down
50 changes: 34 additions & 16 deletions nextmv/nextroute/schema/stop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Defines the Stop class."""
"""Defines the stop class."""


from dataclasses import dataclass
Expand All @@ -9,37 +9,55 @@


@dataclass
class Stop:
"""Stop is a location that must be visited by a vehicle in a Vehicle
Routing Problem (VRP.)"""
class StopDefaults:
"""Default values for a stop."""

compatibility_attributes: list[str] | None
"""Attributes that the stop is compatible with."""
custom_data: Any | None
"""Arbitrary data associated with the stop."""
duration: int | None
"""Duration of the stop in seconds."""
early_arrival_time_penalty: float | None
"""Penalty per second for arriving at the stop before the target arrival time."""
id: str
"""Unique identifier for the stop."""
late_arrival_time_penalty: float | None
"""Penalty per second for arriving at the stop after the target arrival time."""
location: Location
"""Location of the stop."""
max_wait: int | None
"""Maximum waiting duration in seconds at the stop."""
mixing_items: Any | None
"""Defines the items that are inserted or removed from the vehicle when visiting the stop."""
precedes: Any | None
"""Stops that must be visited after this one on the same route."""
quantity: Any | None
"""Quantity of the stop."""
start_time_window: Any | None
"""Time window in which the stop can start service."""
succeeds: Any | None
"""Stops that must be visited before this one on the same route."""
target_arrival_time: datetime | None
"""Target arrival time at the stop."""
unplanned_penalty: int | None
"""Penalty for not planning a stop."""


@dataclass
class Stop(StopDefaults):
"""Stop is a location that must be visited by a vehicle in a Vehicle
Routing Problem (VRP.)"""

custom_data: Any | None
"""Arbitrary data associated with the stop."""
id: str
"""Unique identifier for the stop."""
location: Location
"""Location of the stop."""
mixing_items: Any | None
"""Defines the items that are inserted or removed from the vehicle when visiting the stop."""
precedes: Any | None
"""Stops that must be visited after this one on the same route."""
succeeds: Any | None
"""Stops that must be visited before this one on the same route."""


@dataclass
class AlternateStop(StopDefaults):
"""An alternate stop can be serviced instead of another stop."""

custom_data: Any | None
"""Arbitrary data associated with the stop."""
id: str
"""Unique identifier for the stop."""
location: Location
"""Location of the stop."""
22 changes: 14 additions & 8 deletions nextmv/nextroute/schema/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class InitialStop:


@dataclass
class Vehicle:
"""A vehicle services stops in a Vehicle Routing Problem (VRP)."""
class VehicleDefaults:
"""Default values for vehicles."""

activation_penalty: int | None
"""Penalty of using the vehicle."""
Expand All @@ -30,16 +30,10 @@ class Vehicle:
"""Capacity of the vehicle."""
compatibility_attributes: list[str] | None
"""Attributes that the vehicle is compatible with."""
custom_data: Any | None
"""Arbitrary custom data."""
end_location: Location | None
"""Location where the vehicle ends."""
end_time: datetime | None
"""Latest time at which the vehicle ends its route."""
id: str
"""Unique identifier of the vehicle."""
initial_stops: list[InitialStop] | None
"""Initial stops planned on the vehicle."""
max_distance: int | None
"""Maximum distance in meters that the vehicle can travel."""
max_duration: int | None
Expand All @@ -60,5 +54,17 @@ class Vehicle:
"""Location where the vehicle starts."""
start_time: datetime | None
"""Time when the vehicle starts its route."""


@dataclass
class Vehicle(VehicleDefaults):
"""A vehicle services stops in a Vehicle Routing Problem (VRP)."""

custom_data: Any | None
"""Arbitrary custom data."""
id: str
"""Unique identifier of the vehicle."""
initial_stops: list[InitialStop] | None
"""Initial stops planned on the vehicle."""
stop_duration_multiplier: float | None
"""Multiplier for the duration of stops."""

0 comments on commit 03569cf

Please sign in to comment.