Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Solve very simple linear program

I have tried to figure out the docs at the optimization docs and cannot for the life of me figure out how to program this very simple LP. The problem is that everything has to be written as a minimization, and figuring out what should be minus is a real headache - especially when it doesn't work as expected!

This is in an interact.

@interact
def _(M = matrix(RR,[[1,-1],[-1,1]]),auto_update=False):
    f1(p) = (M[1,0] - M[0,0])*p+M[0,0]
    f2(p) = (M[1,1] - M[0,1])*p+M[0,1]
#    sol1 = find_maximum_on_interval(lambda y: min_symbolic(f1(y),f2(y)),0,1)[0]
    sol1 = linear_program(vector([0,1]),matrix([[-1,0],[1,0],[M[1,0] - M[0,0],-1],[M[1,1] - M[0,1],-1]]),vector([0,1,-M[0,0],-M[0,1]]))['x'][0]
    print sol1

E.g., M=[[1,2],[0,-1]] is just trying to maximize $y$ for below the lines $1-p$ and $2-3p$. (This is a basic zero-sum game I'm trying to demonstrate the solution of, for context.)

For the matrix [[1,2],[0,-1]], it should give p=0, but instead gives the minimum of the opposite.

It would be nice to not have to do quite as much work. Also, the find_maximum_on_interval function doesn't seem to give what I want here either.