19
19
20
20
21
21
def optimization (client ,
22
- jobs ,
23
- vehicles ,
22
+ jobs = None ,
23
+ vehicles = None ,
24
+ shipments = None ,
24
25
matrix = None ,
25
26
geometry = None ,
26
27
dry_run = None ):
@@ -40,10 +41,13 @@ def optimization(client,
40
41
>>> result = api.optimization(jobs=jobs, vehicles=vehicles)
41
42
42
43
:param jobs: The Job objects to fulfill.
43
- :type jobs: list of :class:`openrouteservice.optimization. Job`
44
+ :type jobs: list of Job
44
45
45
46
:param vehicles: The vehicles to fulfill the :class:`openrouteservice.optimization.Job`'s.
46
- :type vehicles: list of :class:`openrouteservice.optimization.Vehicle`
47
+ :type vehicles: list of Vehicle
48
+
49
+ :param shipments: The Shipment objects to fulfill.
50
+ :type shipments: list of Shipment
47
51
48
52
:param matrix: Specify a custom cost matrix. If not specified, it will be calculated with
49
53
the :meth:`openrouteservice.matrix.matrix` endpoint.
@@ -59,11 +63,30 @@ def optimization(client,
59
63
:rtype: dict
60
64
"""
61
65
62
- assert all ([isinstance (x , Job ) for x in jobs ])
63
66
assert all ([isinstance (x , Vehicle ) for x in vehicles ])
64
67
65
- params = {"jobs" : [job .__dict__ for job in jobs ],
66
- "vehicles" : [vehicle .__dict__ for vehicle in vehicles ]}
68
+ params = {"vehicles" : [vehicle .__dict__ for vehicle in vehicles ]}
69
+
70
+ if jobs :
71
+ assert all ([isinstance (x , Job ) for x in jobs ])
72
+ params ['jobs' ] = [job .__dict__ for job in jobs ]
73
+ if shipments :
74
+ assert all ([isinstance (x , Shipment ) for x in shipments ])
75
+ params ['shipments' ] = list ()
76
+
77
+ for shipment in shipments :
78
+ shipment_dict = dict ()
79
+ if getattr (shipment , 'pickup' ):
80
+ assert isinstance (shipment .pickup , ShipmentStep )
81
+ shipment_dict ['pickup' ] = shipment .pickup .__dict__
82
+ if getattr (shipment , 'delivery' ):
83
+ assert isinstance (shipment .delivery , ShipmentStep )
84
+ shipment_dict ['delivery' ] = shipment .delivery .__dict__
85
+ shipment_dict ['amount' ] = shipment .amount
86
+ shipment_dict ['skills' ] = shipment .skills
87
+ shipment_dict ['priority' ] = shipment .priority
88
+
89
+ params ['shipments' ].append (shipment_dict )
67
90
68
91
if geometry is not None :
69
92
params .update ({"options" : {"g" : geometry }})
@@ -87,6 +110,7 @@ def __init__(self,
87
110
service = None ,
88
111
amount = None ,
89
112
skills = None ,
113
+ priority = None ,
90
114
time_windows = None
91
115
):
92
116
"""
@@ -111,6 +135,9 @@ def __init__(self,
111
135
:param skills: An array of integers defining mandatory skills for this job.
112
136
:type skills: list of int or tuple of int
113
137
138
+ :param priority: An integer in the [0, 10] range describing priority level (defaults to 0).
139
+ :type priority: int
140
+
114
141
:param time_windows: An array of time_window objects describing valid slots for job service start.
115
142
:type time_windows: list of lists of int
116
143
"""
@@ -132,10 +159,109 @@ def __init__(self,
132
159
if skills is not None :
133
160
self .skills = skills
134
161
162
+ if priority is not None :
163
+ self .priority = priority
164
+
165
+ if time_windows is not None :
166
+ self .time_windows = time_windows
167
+
168
+
169
+ class ShipmentStep (object ):
170
+ """
171
+ Class to create a Shipment object for optimization endpoint.
172
+
173
+ Full documentation at https://github.com/VROOM-Project/vroom/blob/master/docs/API.md#shipments.
174
+ """
175
+ def __init__ (self ,
176
+ id = None ,
177
+ location = None ,
178
+ location_index = None ,
179
+ service = None ,
180
+ time_windows = None
181
+ ):
182
+ """
183
+ Create a shipment step object for the optimization endpoint.
184
+
185
+ :param id: Integer used as unique identifier.
186
+ :type id: int
187
+
188
+ :param location: Location of the job, as [lon, lat]. Optional if custom matrix is provided.
189
+ :type location: tuple of float or list of float
190
+
191
+ :param location_index: Index of relevant row and column in custom matrix. Mandatory if custom
192
+ matrix is provided. Irrelevant when no custom matrix is provided.
193
+ :type location_index: int
194
+
195
+ :param service: Optional job service duration in seconds
196
+ :type service: int
197
+
198
+ :param time_windows: An array of time_window objects describing valid slots for job service start.
199
+ :type time_windows: list of lists of int
200
+ """
201
+
202
+ self .id = id
203
+
204
+ if location is not None :
205
+ self .location = location
206
+
207
+ if location_index is not None :
208
+ self .location_index = location_index
209
+
210
+ if service is not None :
211
+ self .service = service
212
+
135
213
if time_windows is not None :
136
214
self .time_windows = time_windows
137
215
138
216
217
+ class Shipment (object ):
218
+ """
219
+ Class to create a Shipment object for optimization endpoint.
220
+
221
+ Full documentation at https://github.com/VROOM-Project/vroom/blob/master/docs/API.md#shipments.
222
+ """
223
+ def __init__ (self ,
224
+ pickup = None ,
225
+ delivery = None ,
226
+ amount = None ,
227
+ skills = None ,
228
+ priority = None
229
+ ):
230
+ """
231
+ Create a shipment object for the optimization endpoint.
232
+
233
+ :param pickup: a ShipmentStep object describing pickup
234
+ :type pickup: ShipmentStep
235
+
236
+ :param delivery: a ShipmentStep object describing delivery
237
+ :type delivery: ShipmentStep
238
+
239
+ :param amount: An array of integers describing multidimensional quantities.
240
+ :type amount: list of int or tuple of int
241
+
242
+ :param skills: An array of integers defining mandatory skills.
243
+ :type skills: list of int or tuple of int
244
+
245
+ :param priority: An integer in the [0, 10] range describing priority level (defaults to 0).
246
+ :type priority: int
247
+ """
248
+
249
+ if pickup is not None :
250
+ self .pickup = pickup
251
+
252
+ if delivery is not None :
253
+ self .delivery = delivery
254
+
255
+ if amount is not None :
256
+ self .amount = amount
257
+
258
+ if skills is not None :
259
+ self .skills = skills
260
+
261
+ if priority is not None :
262
+ self .priority = priority
263
+
264
+
139
265
class Vehicle (object ):
140
266
"""
141
267
Class to create a Vehicle object for optimization endpoint.
0 commit comments