Ask Your Question

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

asked 2013-12-03 14:22:48 -0500

Behzad gravatar image

In this cell, I have a linear programming problem:

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


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-03 17:50:55 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-12-03 20:19:17 -0500

Nathann gravatar image

updated 2013-12-03 20:56:24 -0500

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 :


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


edit flag offensive delete link more


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

Nathann gravatar imageNathann ( 2013-12-03 20:48:37 -0500 )edit

I thought we handled this in ticket 12332

ppurka gravatar imageppurka ( 2013-12-03 23:08:52 -0500 )edit

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 to make it more visible.

Nathann gravatar imageNathann ( 2013-12-04 01:44:56 -0500 )edit

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

kcrisman gravatar imagekcrisman ( 2013-12-04 11:25:56 -0500 )edit

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

Behzad gravatar imageBehzad ( 2013-12-04 16:10:14 -0500 )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


Asked: 2013-12-03 14:22:48 -0500

Seen: 89 times

Last updated: Dec 03 '13