1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
1 |
|
import six |
4
|
1 |
|
from enum import Enum |
5
|
|
|
|
6
|
|
|
|
7
|
1 |
|
class PEnum(Enum): |
8
|
1 |
|
@classmethod |
9
|
|
|
def parse_many(cls, value): |
10
|
|
|
""" |
11
|
|
|
Parses enum items from string/list |
12
|
|
|
|
13
|
|
|
:param value: string or enumerable with enum items |
14
|
|
|
:type value: str or list or OptimizationStateEnum |
15
|
|
|
:returns: list of parsed items |
16
|
|
|
:rtype: str or list(str) or list(OptimizationStateEnum) |
17
|
|
|
""" |
18
|
1 |
|
v = value |
19
|
|
|
|
20
|
1 |
|
if isinstance(v, six.string_types): |
21
|
1 |
|
v = [i.strip() for i in v.split(',') if i] |
22
|
|
|
else: |
23
|
1 |
|
try: |
24
|
1 |
|
v = [i for i in v] |
25
|
1 |
|
except TypeError: # as exc: |
26
|
|
|
# if 'iterable' in str(exc): |
27
|
1 |
|
v = [v] |
28
|
|
|
|
29
|
1 |
|
res = [] |
30
|
1 |
|
for i in v: |
31
|
1 |
|
try: |
32
|
1 |
|
x = cls(i) |
33
|
1 |
|
except ValueError: |
34
|
|
|
# probably, there are strings instead of int |
35
|
1 |
|
x = cls(int(i)) |
36
|
|
|
|
37
|
1 |
|
res.append(x) |
38
|
|
|
|
39
|
1 |
|
return res |
40
|
|
|
|
41
|
|
|
|
42
|
1 |
|
class AlgorithmTypeEnum(PEnum): |
43
|
|
|
""" |
44
|
|
|
The algorithm type to be used. |
45
|
|
|
""" |
46
|
|
|
|
47
|
1 |
|
TSP = 1 |
48
|
|
|
""" |
49
|
|
|
TSP |
50
|
|
|
|
51
|
|
|
.. todo:: |
52
|
|
|
add clear and understandable description |
53
|
|
|
""" |
54
|
|
|
|
55
|
1 |
|
VRP = 2 |
56
|
|
|
""" |
57
|
|
|
VRP |
58
|
|
|
|
59
|
|
|
.. todo:: |
60
|
|
|
add clear and understandable description |
61
|
|
|
""" |
62
|
|
|
|
63
|
1 |
|
CVRP_TW_SD = 3 |
64
|
|
|
""" |
65
|
|
|
CVRP_TW_SD |
66
|
|
|
|
67
|
|
|
.. todo:: |
68
|
|
|
add clear and understandable description |
69
|
|
|
""" |
70
|
|
|
|
71
|
1 |
|
CVRP_TW_MD = 4 |
72
|
|
|
""" |
73
|
|
|
CVRP_TW_MD |
74
|
|
|
|
75
|
|
|
.. todo:: |
76
|
|
|
add clear and understandable description |
77
|
|
|
""" |
78
|
|
|
|
79
|
1 |
|
TSP_TW = 5 |
80
|
|
|
""" |
81
|
|
|
TSP_TW |
82
|
|
|
|
83
|
|
|
.. todo:: |
84
|
|
|
add clear and understandable description |
85
|
|
|
""" |
86
|
|
|
|
87
|
1 |
|
TSP_TW_CR = 6 |
88
|
|
|
""" |
89
|
|
|
TSP_TW_CR |
90
|
|
|
|
91
|
|
|
.. todo:: |
92
|
|
|
add clear and understandable description |
93
|
|
|
""" |
94
|
|
|
|
95
|
1 |
|
BBCVRP = 7 |
96
|
|
|
""" |
97
|
|
|
BBCVRP |
98
|
|
|
|
99
|
|
|
.. todo:: |
100
|
|
|
add clear and understandable description |
101
|
|
|
""" |
102
|
|
|
|
103
|
1 |
|
ALG_LEGACY_DISTRIBUTED = 101 |
104
|
|
|
""" |
105
|
|
|
ALG_LEGACY_DISTRIBUTED |
106
|
|
|
|
107
|
|
|
.. todo:: |
108
|
|
|
add clear and understandable description |
109
|
|
|
""" |
110
|
|
|
|
111
|
1 |
|
ALG_NONE = 100 |
112
|
1 |
|
""" |
113
|
|
|
ALG_NONE |
114
|
|
|
|
115
|
|
|
.. todo:: |
116
|
|
|
add clear and understandable description |
117
|
|
|
""" |
118
|
|
|
|
119
|
|
|
|
120
|
1 |
|
class OptimizationFactorEnum(PEnum): |
121
|
|
|
""" |
122
|
|
|
The driving directions can be generated biased for this selection. This |
123
|
|
|
has no impact on route sequencing. |
124
|
|
|
|
125
|
|
|
.. note:: |
126
|
|
|
|
127
|
|
|
In Route4Me API this enum also known as ``optimize`` |
128
|
|
|
|
129
|
|
|
""" |
130
|
|
|
|
131
|
|
|
#: Optimize by distance |
132
|
1 |
|
DISTANCE = 'Distance' |
133
|
|
|
|
134
|
|
|
#: Optimize by time |
135
|
1 |
|
TIME = 'Time' |
136
|
|
|
|
137
|
|
|
#: Optimize by time and traffic |
138
|
1 |
|
TIME_TRAFFIC = 'timeWithTraffic' |
139
|
|
|
|
140
|
|
|
|
141
|
1 |
|
class DistanceUnitEnum(PEnum): |
142
|
|
|
""" |
143
|
|
|
:class:`~.Optimization` problem can be at one state at any given time |
144
|
|
|
""" |
145
|
|
|
|
146
|
|
|
#: Miles |
147
|
1 |
|
MILE = 'mi' |
148
|
|
|
|
149
|
|
|
#: Kilometers |
150
|
1 |
|
KILOMETER = 'km' |
151
|
|
|
|
152
|
|
|
|
153
|
1 |
|
class OptimizationStateEnum(PEnum): |
154
|
|
|
""" |
155
|
|
|
The distance measurement unit |
156
|
|
|
""" |
157
|
|
|
|
158
|
|
|
#: Initial |
159
|
1 |
|
INITIAL = 1 |
160
|
|
|
|
161
|
|
|
#: Matrix Processing |
162
|
1 |
|
MATRIX_PROCESSING = 2 |
163
|
|
|
|
164
|
|
|
#: Optimizing |
165
|
1 |
|
OPTIMIZING = 3 |
166
|
|
|
|
167
|
|
|
#: Optimized |
168
|
1 |
|
OPTIMIZED = 4 |
169
|
|
|
|
170
|
|
|
#: Error |
171
|
1 |
|
ERROR = 5 |
172
|
|
|
|
173
|
|
|
#: Computing Directions |
174
|
1 |
|
COMPUTING_DIRECTIONS = 6 |
175
|
|
|
|
176
|
|
|
|
177
|
1 |
|
class OptimizationQualityEnum(PEnum): |
178
|
|
|
""" |
179
|
|
|
Optimization Quality |
180
|
|
|
""" |
181
|
|
|
|
182
|
|
|
#: Generate Optimized Routes As Quickly as Possible |
183
|
1 |
|
FAST = 1 |
184
|
|
|
|
185
|
|
|
#: Generate Routes That Look Better On A Map |
186
|
1 |
|
MEDIUM = 2 |
187
|
|
|
|
188
|
|
|
#: Generate The Shortest And Quickest Possible Routes |
189
|
1 |
|
BEST = 3 |
190
|
|
|
|
191
|
|
|
|
192
|
1 |
|
class DeviceTypeEnum(PEnum): |
193
|
|
|
""" |
194
|
|
|
Device Type |
195
|
|
|
|
196
|
|
|
The type of the device that is creating this route |
197
|
|
|
""" |
198
|
|
|
|
199
|
|
|
#: Web |
200
|
1 |
|
WEB = 'web' |
201
|
|
|
|
202
|
|
|
#: IPhone |
203
|
1 |
|
IPHONE = 'iphone' |
204
|
|
|
|
205
|
|
|
#: IPad |
206
|
1 |
|
IPAD = 'ipad' |
207
|
|
|
|
208
|
|
|
#: Android phone |
209
|
1 |
|
ANDROID_PHONE = 'android_phone' |
210
|
|
|
|
211
|
|
|
#: Android tablet |
212
|
1 |
|
ANDROID_TABLET = 'android_tablet' |
213
|
|
|
|
214
|
|
|
|
215
|
1 |
|
class TravelModeEnum(PEnum): |
216
|
|
|
""" |
217
|
|
|
Travel Mode |
218
|
|
|
|
219
|
|
|
The mode of travel that the directions should be optimized for |
220
|
|
|
""" |
221
|
|
|
|
222
|
|
|
#: Driving |
223
|
1 |
|
DRIVING = 'Driving' |
224
|
|
|
|
225
|
|
|
#: Walking |
226
|
1 |
|
WALKING = 'Walking' |
227
|
|
|
|
228
|
|
|
#: Trucking |
229
|
1 |
|
TRUCKING = 'Trucking' |
230
|
|
|
|
231
|
|
|
#: Cycling |
232
|
1 |
|
CYCLING = 'Cycling' |
233
|
|
|
|
234
|
|
|
#: Transit |
235
|
1 |
|
TRANSIT = 'Transit' |
236
|
|
|
|
237
|
|
|
|
238
|
1 |
|
class RouteMetricEnum(PEnum): |
239
|
|
|
""" |
240
|
|
|
Metric |
241
|
|
|
""" |
242
|
|
|
|
243
|
|
|
#: Euclidean |
244
|
1 |
|
EUCLIDEAN = 1 |
245
|
|
|
|
246
|
|
|
#: Manhattan |
247
|
1 |
|
MANHATTAN = 2 |
248
|
|
|
|
249
|
|
|
#: Geodesic |
250
|
1 |
|
GEODESIC = 3 |
251
|
|
|
|
252
|
|
|
#: Matrix |
253
|
1 |
|
MATRIX = 4 |
254
|
|
|
|
255
|
|
|
#: Exact 2d |
256
|
1 |
|
EXACT2D = 5 |
257
|
|
|
|
258
|
|
|
|
259
|
1 |
|
class AddressStopTypeEnum(PEnum): |
260
|
|
|
""" |
261
|
|
|
Address stop type |
262
|
|
|
""" |
263
|
|
|
|
264
|
|
|
#: Pickup |
265
|
1 |
|
PICKUP = 'PICKUP' |
266
|
|
|
|
267
|
|
|
#: Delivery |
268
|
1 |
|
DELIVERY = 'DELIVERY' |
269
|
|
|
|
270
|
|
|
#: Break |
271
|
1 |
|
BREAK = 'BREAK' |
272
|
|
|
|
273
|
|
|
#: Meetup |
274
|
1 |
|
MEETUP = 'MEETUP' |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
# TYPE_OF_MATRIX = enum(R4M_PROPRIETARY_ROUTING=1, |
278
|
|
|
# R4M_TRAFFIC_ENGINE=3, |
279
|
|
|
# TRUCKING=6) |
280
|
|
|
|
281
|
|
|
# DIRECTIONS_METHOD = enum(R4M_PROPRIETARY_INTERNAL_NAVIGATION_SYSTEM=1, |
282
|
|
|
# TRUCKING=3) |
283
|
|
|
|
284
|
|
|
# AVOID = enum(HIGHWAYS='Highways', |
285
|
|
|
# TOLLS='Tolls', |
286
|
|
|
# MINIMIZE_HIGHWAYS='minimizeHighways', |
287
|
|
|
# MINIMIZE_TOLLS='minimizeTolls', |
288
|
|
|
# NONE='') |
289
|
|
|
|
290
|
|
|
|
291
|
|
|
# FORMAT = enum(CSV='csv', |
292
|
|
|
# SERIALIZED='serialized', |
293
|
|
|
# XML='xml', |
294
|
|
|
# JSON='json') |
295
|
|
|
|
296
|
|
|
|
297
|
|
|
# ROUTE_PATH_OUTPUT = enum(NONE='None', |
298
|
|
|
# POINTS='Points') |
299
|
|
|
|
300
|
|
|
# UTURN = auto_enum('UTURN_DEPART_SHORTEST', |
301
|
|
|
# 'UTURN_DEPART_TO_RIGHT') |
302
|
|
|
|
303
|
|
|
# LEFT_TURN = auto_enum('LEFTTURN_ALLOW', |
304
|
|
|
# 'LEFTTURN_FORBID', |
305
|
|
|
# 'LEFTTURN_MULTIAPPROACH') |
306
|
|
|
|
307
|
|
|
# TRUCK_HAZARDOUS_GOODS = enum(NONE='', |
308
|
|
|
# EXPLOSIVE='explosive', |
309
|
|
|
# GAS='gas', |
310
|
|
|
# FLAMMABLE='flammable', |
311
|
|
|
# COMBUSTIBLE='combustible', |
312
|
|
|
# ORGANIC='organic', |
313
|
|
|
# POISON='poison', |
314
|
|
|
# RADIOACTIVE='radioActive', |
315
|
|
|
# CORROSIVE='corrosive', |
316
|
|
|
# POISONOUSINHALATION='poisonousInhalation', |
317
|
|
|
# HARMFULTOWATER='harmfulToWater', |
318
|
|
|
# OTHER='other', |
319
|
|
|
# ALLHAZARDOUSGOODS='allHazardousGoods') |
320
|
|
|
|
321
|
|
|
# TERRITORY_TYPE = enum(CIRCLE='circle', |
322
|
|
|
# POLY='poly', |
323
|
|
|
# RECT='rect', ) |
324
|
|
|
|