Keywords: linear-programming, sparse, scipy, test-case-generator
lpgen_2d
generates test cases for linear programming, with parameters m
and n
:
m+n
constraints, mn
variables, 2mn
non-zeros. An example:
from scipy.optimize import linprog
A, b, c = lpgen_2d( m, n, sparse=True, dtype=np.float32, seed=0, verbose=1 )
# e.g.
# lpgen_2d: m 1000 n 2000 A (3000, 2000000) 4e+07 bytes sparse float32 seed 0
res = linprog( c, A_ub=A, b_ub=b, method="interior-point" ... )
# takes ~ 90 sec real time, 120 cpu time (sum of cores) on my 2.7 GHz iMac
Sec Objective Primal, Dual Feasibility Gap Step Path Parameter
0: -1.00036e+07 1 1 1 nan 1
21: -8.53131e+06 0.0013 0.0013 0.0013 0.999 0.0013
41: -75664.5 0.000467 0.000467 0.000467 0.707 0.000467
...
122: -20000 1.12e-11 1.12e-11 1.12e-11 1 1.12e-11
Lpgen_2d with integer n/m generates
assignment problems,
which have many vertices, so make pretty good test problems for LP.
The simplex method finds integer solutions;
interior-point generally does not, but is faster by a huge factor.
For example, for m=50 n=100
ip takes 0.2 seconds (real), simplex 13 seconds.
Only linprog( method="interior-point" )
handles sparse matrices;
the default method="simplex"
hits bugs (in scipy 1.2.1, April 2019).
All LP solvers have many many options ...
Sparse matrices are only ~ 1/4 smaller with float32 than float64 -- indices are 64-bit ints.
Multicore ? I see cpu and wall clock times e.g. 145 sec, 90 sec (time.clock sum all cores, time.time). The source has a "TODO: if umfpack is installed ..."
Scipy linprog interior-point
_linprog_ip.py -- 1100 lines, well commented
Assignment problem in
Knuth, Stanford Graphbase
pages 26-30, 77-87.
cheers
-- denis 27 April 2019