Ask Your Question

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

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

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-04 00:50:55 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

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

Nathann gravatar image

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

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-04 03:48:37 +0200 )edit

I thought we handled this in ticket 12332

ppurka gravatar imageppurka ( 2013-12-04 06:08:52 +0200 )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 08:44:56 +0200 )edit

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

kcrisman gravatar imagekcrisman ( 2013-12-04 18:25:56 +0200 )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 +0200 )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 21:22:48 +0200

Seen: 321 times

Last updated: Dec 04 '13