Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for vehicle 'description', 'speed_factor', 'max_tasks', 'max_travel_time' and 'max_distance' in optimization #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions openrouteservice/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,18 @@ def __init__(
self,
id,
profile="driving-car",
description=None,
start=None,
start_index=None,
end=None,
end_index=None,
capacity=None,
skills=None,
time_window=None,
speed_factor=None,
max_tasks=None,
max_travel_time=None,
max_distance=None,
):
"""
Create a Vehicle object for the optimization endpoint.
Expand All @@ -303,6 +308,9 @@ def __init__(
"cycling-electric",]. Default "driving-car".
:type profile: str

:param description: A description of the vehicle.
:type description: str

:param start: Coordinate for the vehicle to start from. If not specified, the start
location will be the first visited job, determined by the optimization engine.
:type start: list of float or tuple of float
Expand All @@ -327,11 +335,27 @@ def __init__(

:param time_window: A time_window object describing working hours for this vehicle.
:param time_window: list of int or tuple of int

:param speed_factor: a double value in the range (0, 5] used to scale all vehicle travel times (defaults to 1.),
the respected precision is limited to two digits after the decimal point
:param speed_factor: float

:param max_tasks: an integer defining the maximum number of tasks in a route for this vehicle
:param max_tasks: int

:param max_travel_time: an integer defining the maximum travel time for this vehicle
:param max_travel_time: int

:param max_distance: an integer defining the maximum distance for this vehicle
:param max_distance: int
"""

self.id = id
self.profile = profile

if description is not None:
self.description = description

if start is not None:
self.start = start

Expand All @@ -352,3 +376,15 @@ def __init__(

if time_window is not None:
self.time_window = time_window

if speed_factor is not None:
self.speed_factor = speed_factor

if max_tasks is not None:
self.max_tasks = max_tasks

if max_travel_time is not None:
self.max_travel_time = max_travel_time

if max_distance is not None:
self.max_distance = max_distance
12 changes: 12 additions & 0 deletions test/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

PARAM_INT_BIG = 500
PARAM_INT_SMALL = 50
PARAM_FLOAT_SMALL = 0.5
PARAM_FLOAT_BIG = 3.5
PARAM_LIST_ONE = [PARAM_INT_SMALL, PARAM_INT_SMALL]
PARAM_LIST_TWO = [PARAM_LIST_ONE, PARAM_LIST_ONE]

Expand Down Expand Up @@ -204,24 +206,34 @@
{
"id": 0,
"profile": "driving-car",
"description": "vehicle",
"start": PARAM_LINE[0],
"start_index": 0,
"end_index": 0,
"end": PARAM_LINE[0],
"capacity": [PARAM_INT_SMALL],
"skills": PARAM_LIST_ONE,
"time_window": PARAM_LIST_ONE,
"speed_factor": PARAM_FLOAT_SMALL,
"max_tasks": PARAM_INT_SMALL,
"max_travel_time": PARAM_INT_BIG,
"max_distance": PARAM_INT_BIG,
},
{
"id": 1,
"profile": "driving-car",
"description": "vehicle",
"start": PARAM_LINE[1],
"start_index": 1,
"end_index": 1,
"end": PARAM_LINE[1],
"capacity": [PARAM_INT_SMALL],
"skills": PARAM_LIST_ONE,
"time_window": PARAM_LIST_ONE,
"speed_factor": PARAM_FLOAT_SMALL,
"max_tasks": PARAM_INT_SMALL,
"max_travel_time": PARAM_INT_BIG,
"max_distance": PARAM_INT_BIG,
},
],
"options": {"g": False},
Expand Down
5 changes: 5 additions & 0 deletions test/test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ def _get_params(self):
Vehicle(
idx,
profile="driving-car",
description="vehicle",
start=coord,
start_index=idx,
end=coord,
end_index=idx,
capacity=[PARAM_INT_SMALL],
skills=PARAM_LIST_ONE,
time_window=PARAM_LIST_ONE,
speed_factor=PARAM_FLOAT_SMALL,
max_tasks=PARAM_INT_SMALL,
max_travel_time=PARAM_INT_BIG,
max_distance=PARAM_INT_BIG,
)
)

Expand Down