Problem using linprog

"Montgomery-Smith, Stephen" <[email protected]>
Newsgroups gmane.comp.python.scientific.user
Message-ID <[email protected]>
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)

_______________________________________________
SciPy-User mailing list
[email protected]
https://mail.python.org/mailman/listinfo/scipy-user
test.py (text/x-python, 1.2 KB)
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)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.