@@ -264,7 +264,13 @@ def test_network_flow_limited_capacity():
264
264
[0 , p , p , 0 , n ],
265
265
[0 , 0 , 0 , p , p ]]
266
266
b_eq = [- 4 , 0 , 0 , 4 ]
267
- res = linprog (c = cost , A_eq = A_eq , b_eq = b_eq , bounds = bounds )
267
+ # Including the callback here ensures the solution can be
268
+ # calculated correctly, even when phase 1 terminated
269
+ # with some of the artificial variables as pivots
270
+ # (i.e. basis[:m] contains elements corresponding to
271
+ # the artificial variables)
272
+ res = linprog (c = cost , A_eq = A_eq , b_eq = b_eq , bounds = bounds ,
273
+ callback = lambda x , ** kwargs : None )
268
274
_assert_success (res , desired_fun = 14 )
269
275
270
276
@@ -301,14 +307,16 @@ def test_enzo_example():
301
307
def test_enzo_example_b ():
302
308
# rescued from https://github.com/scipy/scipy/pull/218
303
309
c = [2.8 , 6.3 , 10.8 , - 2.8 , - 6.3 , - 10.8 ]
304
- A_eq = [
305
- [- 1 , - 1 , - 1 , 0 , 0 , 0 ],
310
+ A_eq = [[- 1 , - 1 , - 1 , 0 , 0 , 0 ],
306
311
[0 , 0 , 0 , 1 , 1 , 1 ],
307
312
[1 , 0 , 0 , 1 , 0 , 0 ],
308
313
[0 , 1 , 0 , 0 , 1 , 0 ],
309
314
[0 , 0 , 1 , 0 , 0 , 1 ]]
310
315
b_eq = [- 0.5 , 0.4 , 0.3 , 0.3 , 0.3 ]
311
- res = linprog (c = c , A_eq = A_eq , b_eq = b_eq )
316
+ # Including the callback here ensures the solution can be
317
+ # calculated correctly.
318
+ res = linprog (c = c , A_eq = A_eq , b_eq = b_eq ,
319
+ callback = lambda x , ** kwargs : None )
312
320
_assert_success (res , desired_fun = - 1.77 ,
313
321
desired_x = [0.3 , 0.2 , 0.0 , 0.0 , 0.1 , 0.3 ])
314
322
@@ -426,5 +434,21 @@ def test_invalid_inputs():
426
434
assert_raises (ValueError , linprog , [1 ,2 ], A_ub = np .zeros ((1 ,1 ,3 )), b_eq = 1 )
427
435
428
436
437
+ def test_basic_artificial_vars ():
438
+ # Test if linprog succeeds when at the end of Phase 1 some artificial
439
+ # variables remain basic, and the row in T corresponding to the
440
+ # artificial variables is not all zero.
441
+ c = np .array ([- 0.1 , - 0.07 , 0.004 , 0.004 , 0.004 , 0.004 ])
442
+ A_ub = np .array ([[1.0 , 0 , 0 , 0 , 0 , 0 ], [- 1.0 , 0 , 0 , 0 , 0 , 0 ],
443
+ [0 , - 1.0 , 0 , 0 , 0 , 0 ], [0 , 1.0 , 0 , 0 , 0 , 0 ],
444
+ [1.0 , 1.0 , 0 , 0 , 0 , 0 ]])
445
+ b_ub = np .array ([3.0 , 3.0 , 3.0 , 3.0 , 20.0 ])
446
+ A_eq = np .array ([[1.0 , 0 , - 1 , 1 , - 1 , 1 ], [0 , - 1.0 , - 1 , 1 , - 1 , 1 ]])
447
+ b_eq = np .array ([0 , 0 ])
448
+ res = linprog (c , A_ub = A_ub , b_ub = b_ub , A_eq = A_eq , b_eq = b_eq ,
449
+ callback = lambda x , ** kwargs : None )
450
+ _assert_success (res , desired_fun = 0 , desired_x = np .zeros_like (c ))
451
+
452
+
429
453
if __name__ == '__main__' :
430
454
run_module_suite ()
0 commit comments