From 8c2e1b4933a8b6bb942b6272c41bcdee1d76d27d Mon Sep 17 00:00:00 2001 From: Diyan Ivanov Date: Tue, 13 Aug 2024 18:27:29 +0100 Subject: [PATCH 1/2] feat: Add support for vehicle 'description' in optimization --- openrouteservice/optimization.py | 7 +++++++ test/test_helper.py | 2 ++ test/test_optimization.py | 1 + 3 files changed, 10 insertions(+) diff --git a/openrouteservice/optimization.py b/openrouteservice/optimization.py index 57b337b4..c05f7885 100644 --- a/openrouteservice/optimization.py +++ b/openrouteservice/optimization.py @@ -283,6 +283,7 @@ def __init__( self, id, profile="driving-car", + description=None, start=None, start_index=None, end=None, @@ -303,6 +304,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 @@ -332,6 +336,9 @@ def __init__( self.id = id self.profile = profile + if description is not None: + self.description = description + if start is not None: self.start = start diff --git a/test/test_helper.py b/test/test_helper.py index 338c3697..d2024c34 100644 --- a/test/test_helper.py +++ b/test/test_helper.py @@ -204,6 +204,7 @@ { "id": 0, "profile": "driving-car", + "description": "vehicle", "start": PARAM_LINE[0], "start_index": 0, "end_index": 0, @@ -215,6 +216,7 @@ { "id": 1, "profile": "driving-car", + "description": "vehicle", "start": PARAM_LINE[1], "start_index": 1, "end_index": 1, diff --git a/test/test_optimization.py b/test/test_optimization.py index 6db710e7..84ad1214 100644 --- a/test/test_optimization.py +++ b/test/test_optimization.py @@ -48,6 +48,7 @@ def _get_params(self): Vehicle( idx, profile="driving-car", + description="vehicle", start=coord, start_index=idx, end=coord, From 465ba950b93bd2a7f001498461c62288eca85d63 Mon Sep 17 00:00:00 2001 From: Diyan Ivanov Date: Tue, 13 Aug 2024 19:20:27 +0100 Subject: [PATCH 2/2] feat: add support for 'speed_factor', 'max_tasks', 'max_travel_time', and 'max_distance' --- openrouteservice/optimization.py | 29 +++++++++++++++++++++++++++++ test/test_helper.py | 10 ++++++++++ test/test_optimization.py | 4 ++++ 3 files changed, 43 insertions(+) diff --git a/openrouteservice/optimization.py b/openrouteservice/optimization.py index c05f7885..871711cf 100644 --- a/openrouteservice/optimization.py +++ b/openrouteservice/optimization.py @@ -291,6 +291,10 @@ def __init__( 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. @@ -331,6 +335,19 @@ 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 @@ -359,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 diff --git a/test/test_helper.py b/test/test_helper.py index d2024c34..f3c26a90 100644 --- a/test/test_helper.py +++ b/test/test_helper.py @@ -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] @@ -212,6 +214,10 @@ "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, @@ -224,6 +230,10 @@ "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}, diff --git a/test/test_optimization.py b/test/test_optimization.py index 84ad1214..1d01c76d 100644 --- a/test/test_optimization.py +++ b/test/test_optimization.py @@ -56,6 +56,10 @@ def _get_params(self): 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, ) )