# Why do I get the wrong answer from this LP problem?

In this cell, I have a linear programming problem: http://sagecell.sagemath.org/?q=oatgsd

However, the answer is wrong. The optimal objective has to be 1 whereas it is 0. The optimal values for x and y lie on the line between (-2,1) and (1,-2). I have shown the values of the constraints for the point (-1,0)

edit retag close merge delete

I'm baffled here. The only suggestion I have is that somehow it doesn't like maximizing functions that have many negative values - I get similar problems with anything negative for coefficients.

( 2013-12-04 00:50:55 +0100 )edit

Sort by ยป oldest newest most voted

Helloooooooooooooooooooooo !!

That's because all variables are assumed to be >= 0 by default unless specified otherwise. Sorry for that, it's something that all LP solvers that I know assume too (and that's why we do, too), and it's pretty hard to advertise in the doc and make sure that everybody sees it O_o

So if you want to make this work with negative values, you have to add lines like :

p.set_min(p['x'],None)
p.set_min(p['y'],None)


in your code. And it will work, at least it does on my computer.

Perhaps I should add warnings everywhere in the doc O_o

Nathann

more

By the way, you can show it with your code by adding a p.show() at the end. It will tell you that your variables are nonnegative things.

( 2013-12-04 03:48:37 +0100 )edit

I thought we handled this in ticket 12332

( 2013-12-04 06:08:52 +0100 )edit
1

Well, the doc mentions it since 12332. But printing stuff in the doc is not always enough, especially when the LP above does not even call new_variable :-/ I created http://trac.sagemath.org/ticket/15482 to make it more visible.

( 2013-12-04 08:44:56 +0100 )edit

That's ... quite a convention. See my comments on that ticket.

( 2013-12-04 18:25:56 +0100 )edit

Thanks for the answer. Maybe it's better to leave the constraints to the user.

( 2013-12-04 23:10:14 +0100 )edit