[SciPy-User] Problem using linprog

Montgomery-Smith, Stephen stephen at missouri.edu
Mon Nov 26 15:40:33 EST 2018


I am trying to solve a linear programming problem.  The constraint is of
the form A.x <= 0.  But linprog gives an answer that doesn't satisfy the
constraint.

The attached program gives A.x as

[-2.32109228  2.32017594  4.71436317  3.6433767  -4.26629574  2.32384597
 -1.96166184 -4.96206197]

which definitely doesn't satisfy the constraint.  Is this a bug, or some
subtle floating point error?

Program follows (also as attachment):

from scipy.optimize import linprog
import numpy as np

A = [[0.5919650431077654, -0.5271408402306996, 0.6096719792636803,
1.2379670854947114, 0.2656040423387233, -0.972363043155988],
[-0.5914974900295467, -0.5266568950860249, 0.6105433925177587,
1.258297461476007, -0.285688537323182, 0.9726089241528251],
[-0.593015674004932, 0.5280764198909397, 0.6078385518701857,
-1.1964319796886902, -0.2223431679788034, -0.9740888117098865],
[0.5935986604093653, 0.5285277328950352, 0.6068764832493029,
-1.1752312553140132, 0.19916734259906424, 0.976063912714949],
[0.593015674004932, -0.5280764198909397, -0.6078385518701857,
-1.1964319796886902, -0.2223431679788034, -0.9740888117098865],
[-0.5935986604093653, -0.5285277328950352, -0.6068764832493029,
-1.1752312553140132, 0.19916734259906424, 0.976063912714949],
[-0.5919650431077654, 0.5271408402306996, -0.6096719792636803,
1.2379670854947114, 0.2656040423387233, -0.972363043155988],
[0.5914974900295467, 0.5266568950860249, -0.6105433925177587,
1.258297461476007, -0.285688537323182, 0.9726089241528251]]
e = [0, 0, 0, 0, 0, -1]
bounds = [(None, None), (None, None), (None, None), (None, None), (None,
None), (0, 1)]
b = [0]*len(A)
result = linprog(e, A_ub = A, b_ub = b, bounds = bounds)
print np.matmul(A, result.x)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: text/x-python
Size: 1274 bytes
Desc: test.py
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20181126/59142d27/attachment.py>


More information about the SciPy-User mailing list