Ask Your Question
1

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

asked 11 years ago

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)

Preview: (hide)

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 ( 11 years ago )

1 Answer

Sort by » oldest newest most voted
4

answered 11 years ago

Nathann gravatar image

updated 11 years ago

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

Preview: (hide)
link

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 ( 11 years ago )

I thought we handled this in ticket 12332

ppurka gravatar imageppurka ( 11 years ago )
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 ( 11 years ago )

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

kcrisman gravatar imagekcrisman ( 11 years ago )

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

Behzad gravatar imageBehzad ( 11 years ago )

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: 11 years ago

Seen: 444 times

Last updated: Dec 04 '13