Ask Your Question
1

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

asked 2013-12-03 21:22:48 +0100

Behzad gravatar image

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 flag offensive close merge delete

Comments

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.

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

1 Answer

Sort by ยป oldest newest most voted
4

answered 2013-12-04 03:19:17 +0100

Nathann gravatar image

updated 2013-12-04 03:56:24 +0100

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

edit flag offensive delete link more

Comments

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.

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

I thought we handled this in ticket 12332

ppurka gravatar imageppurka ( 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.

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

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

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

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-12-03 21:22:48 +0100

Seen: 395 times

Last updated: Dec 04 '13