0

I'm trying to use scipy.optimize.linprog and it's not working for me in a simple case. I must be doing something wrong -- help me out to find it please.

Here are the inputs and the expected solution and a test that the expected solution is feasible

import numpy, scipy.optimize
print "A", A_ub
print "b", b_ub
print "c", c
print "x_expected", x_expected
print "expected optimum", numpy.dot(c, x_expected)
print "feasibility test", numpy.dot(A_ub, x_expected) <= b_ub

This prints

A [[-1. -0.  0.  1.]
   [-0. -1.  1.  1.]
   [-1. -0. -0. -1.]
   [-0. -1. -1. -1.]]
b [ 2.  1. -2. -1.]
c [ 1.  1.  0.  0.]
x_expected [ 0  0 -1  2]
expected optimum 0.0
feasibility test [ True  True  True  True]

When I call linprog I get a feasible solution, but it seems to not be as optimal as the one I expected above.

r = scipy.optimize.linprog(c, A_ub, b_ub)
x_derived = r.x
print "x_derived", x_derived
print "derived optimum", numpy.dot(c, x_derived)
print "derived feasibility", numpy.dot(A_ub, x_derived) <= b_ub

This prints

x_derived [ 1.  0.  0.  1.]
derived optimum 1.0
derived feasibility [ True  True  True  True]

Is there something wrong in my reasoning that I should be getting the expected solution (or a better one if there is one) instead of the one I get? If I'm not wrong, how do I make linprog get it for me? Thanks!

2
  • Are you trying to maximize or minimize here? Commented Oct 1, 2015 at 13:01
  • I'm trying to minimize numpy.dot(c, x). Commented Oct 1, 2015 at 13:28

1 Answer 1

1

Linprog by default assumes usual linear programming lower bound x >= 0, which your "expected" solution does not satisfy. See the bounds keyword argument to change the bounds.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.