7
7
8
8
9
9
class TestsToy :
10
-
11
10
def setup (self ):
12
11
"""
13
12
Creates a toy graph.
@@ -58,10 +57,7 @@ def test_cspy_stops_capacity_duration(self):
58
57
"""Tests column generation procedure on toy graph
59
58
with stop, capacity and duration constraints
60
59
"""
61
- prob = VehicleRoutingProblem (self .G ,
62
- num_stops = 3 ,
63
- load_capacity = 10 ,
64
- duration = 62 )
60
+ prob = VehicleRoutingProblem (self .G , num_stops = 3 , load_capacity = 10 , duration = 62 )
65
61
prob .solve (exact = False )
66
62
assert prob .best_value == 85
67
63
assert set (prob .best_routes_duration .values ()) == {41 , 62 }
@@ -82,8 +78,7 @@ def test_cspy_stops_time_windows(self):
82
78
assert prob .arrival_time [1 ]["Sink" ] in [41 , 62 ]
83
79
84
80
def test_cspy_schedule (self ):
85
- """Tests if final schedule is time-window feasible
86
- """
81
+ """Tests if final schedule is time-window feasible"""
87
82
prob = VehicleRoutingProblem (
88
83
self .G ,
89
84
num_stops = 3 ,
@@ -93,13 +88,13 @@ def test_cspy_schedule(self):
93
88
# Check departure times
94
89
for k1 , v1 in prob .departure_time .items ():
95
90
for k2 , v2 in v1 .items ():
96
- assert ( self .G .nodes [k2 ]["lower" ] <= v2 )
97
- assert ( v2 <= self .G .nodes [k2 ]["upper" ])
91
+ assert self .G .nodes [k2 ]["lower" ] <= v2
92
+ assert v2 <= self .G .nodes [k2 ]["upper" ]
98
93
# Check arrival times
99
94
for k1 , v1 in prob .arrival_time .items ():
100
95
for k2 , v2 in v1 .items ():
101
- assert ( self .G .nodes [k2 ]["lower" ] <= v2 )
102
- assert ( v2 <= self .G .nodes [k2 ]["upper" ])
96
+ assert self .G .nodes [k2 ]["lower" ] <= v2
97
+ assert v2 <= self .G .nodes [k2 ]["upper" ]
103
98
104
99
###############
105
100
# subsolve lp #
@@ -151,13 +146,13 @@ def test_LP_schedule(self):
151
146
# Check departure times
152
147
for k1 , v1 in prob .departure_time .items ():
153
148
for k2 , v2 in v1 .items ():
154
- assert ( self .G .nodes [k2 ]["lower" ] <= v2 )
155
- assert ( v2 <= self .G .nodes [k2 ]["upper" ])
149
+ assert self .G .nodes [k2 ]["lower" ] <= v2
150
+ assert v2 <= self .G .nodes [k2 ]["upper" ]
156
151
# Check arrival times
157
152
for k1 , v1 in prob .arrival_time .items ():
158
153
for k2 , v2 in v1 .items ():
159
- assert ( self .G .nodes [k2 ]["lower" ] <= v2 )
160
- assert ( v2 <= self .G .nodes [k2 ]["upper" ])
154
+ assert self .G .nodes [k2 ]["lower" ] <= v2
155
+ assert v2 <= self .G .nodes [k2 ]["upper" ]
161
156
162
157
def test_LP_stops_elementarity (self ):
163
158
"""Tests column generation procedure on toy graph"""
@@ -188,11 +183,9 @@ def test_clarke_wright(self):
188
183
#########
189
184
190
185
def test_all (self ):
191
- prob = VehicleRoutingProblem (self .G ,
192
- num_stops = 3 ,
193
- time_windows = True ,
194
- duration = 63 ,
195
- load_capacity = 10 )
186
+ prob = VehicleRoutingProblem (
187
+ self .G , num_stops = 3 , time_windows = True , duration = 63 , load_capacity = 10
188
+ )
196
189
prob .solve (cspy = False )
197
190
lp_best = prob .best_value
198
191
prob .solve (cspy = True )
@@ -217,9 +210,7 @@ def test_knapsack(self):
217
210
218
211
def test_pricing_strategies (self ):
219
212
sol = []
220
- for strategy in [
221
- "Exact" , "BestPaths" , "BestEdges1" , "BestEdges2" , "Hyper"
222
- ]:
213
+ for strategy in ["Exact" , "BestPaths" , "BestEdges1" , "BestEdges2" , "Hyper" ]:
223
214
prob = VehicleRoutingProblem (self .G , num_stops = 4 )
224
215
prob .solve (pricing_strategy = strategy )
225
216
sol .append (prob .best_value )
@@ -294,22 +285,25 @@ def test_fixed_cost(self):
294
285
assert set (prob .best_routes_cost .values ()) == {30 + 100 , 40 + 100 }
295
286
296
287
def test_drop_nodes (self ):
297
- prob = VehicleRoutingProblem (self .G ,
298
- num_stops = 3 ,
299
- num_vehicles = 1 ,
300
- drop_penalty = 100 )
288
+ prob = VehicleRoutingProblem (
289
+ self .G , num_stops = 3 , num_vehicles = 1 , drop_penalty = 100
290
+ )
301
291
prob .solve ()
302
292
assert prob .best_value == 240
303
293
assert prob .best_routes == {1 : ["Source" , 1 , 2 , 3 , "Sink" ]}
304
294
305
295
def test_num_vehicles_use_all (self ):
306
- prob = VehicleRoutingProblem (self .G ,
307
- num_stops = 3 ,
308
- num_vehicles = 2 ,
309
- use_all_vehicles = True ,
310
- drop_penalty = 100 )
296
+ prob = VehicleRoutingProblem (
297
+ self .G , num_stops = 3 , num_vehicles = 2 , use_all_vehicles = True , drop_penalty = 100
298
+ )
311
299
prob .solve ()
312
300
assert len (prob .best_routes ) == 2
301
+ prob .num_vehicles = 3
302
+ prob .solve ()
303
+ assert len (prob .best_routes ) == 3
304
+ prob .num_vehicles = 4
305
+ prob .solve ()
306
+ assert len (prob .best_routes ) == 4
313
307
314
308
def test_periodic (self ):
315
309
self .G .nodes [2 ]["frequency" ] = 2
@@ -322,10 +316,7 @@ def test_periodic(self):
322
316
frequency += 1
323
317
assert frequency == 2
324
318
assert prob .schedule [0 ] in [[1 ], [1 , 2 ]]
325
- prob = VehicleRoutingProblem (self .G ,
326
- num_stops = 2 ,
327
- periodic = 2 ,
328
- num_vehicles = 1 )
319
+ prob = VehicleRoutingProblem (self .G , num_stops = 2 , periodic = 2 , num_vehicles = 1 )
329
320
prob .solve ()
330
321
assert prob .schedule == {}
331
322
0 commit comments