ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 06 Dec 2013 11:18:33 +0100Why do I get the wrong answer from this LP problem?https://ask.sagemath.org/question/10800/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)Tue, 03 Dec 2013 21:22:48 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/Comment by kcrisman for <p>In this cell, I have a linear programming problem:
<a href="http://sagecell.sagemath.org/?q=oatgsd">http://sagecell.sagemath.org/?q=oatgsd</a></p>
<p>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)</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16579#post-id-16579I'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.Wed, 04 Dec 2013 00:50:55 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16579#post-id-16579Answer by Nathann for <p>In this cell, I have a linear programming problem:
<a href="http://sagecell.sagemath.org/?q=oatgsd">http://sagecell.sagemath.org/?q=oatgsd</a></p>
<p>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)</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?answer=15756#post-id-15756Helloooooooooooooooooooooo !!
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`
NathannWed, 04 Dec 2013 03:19:17 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?answer=15756#post-id-15756Comment by Nathann for <p>Helloooooooooooooooooooooo !!</p>
<p>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 <code>O_o</code></p>
<p>So if you want to make this work with negative values, you have to add lines like :</p>
<pre><code>p.set_min(p['x'],None)
p.set_min(p['y'],None)
</code></pre>
<p>in your code. And it will work, at least it does on my computer.</p>
<p>Perhaps I should add warnings everywhere in the doc <code>O_o</code></p>
<p>Nathann</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16578#post-id-16578By 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.Wed, 04 Dec 2013 03:48:37 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16578#post-id-16578Comment by kcrisman for <p>Helloooooooooooooooooooooo !!</p>
<p>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 <code>O_o</code></p>
<p>So if you want to make this work with negative values, you have to add lines like :</p>
<pre><code>p.set_min(p['x'],None)
p.set_min(p['y'],None)
</code></pre>
<p>in your code. And it will work, at least it does on my computer.</p>
<p>Perhaps I should add warnings everywhere in the doc <code>O_o</code></p>
<p>Nathann</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16574#post-id-16574That's ... quite a convention. See my comments on that ticket.Wed, 04 Dec 2013 18:25:56 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16574#post-id-16574Comment by Behzad for <p>Helloooooooooooooooooooooo !!</p>
<p>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 <code>O_o</code></p>
<p>So if you want to make this work with negative values, you have to add lines like :</p>
<pre><code>p.set_min(p['x'],None)
p.set_min(p['y'],None)
</code></pre>
<p>in your code. And it will work, at least it does on my computer.</p>
<p>Perhaps I should add warnings everywhere in the doc <code>O_o</code></p>
<p>Nathann</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16571#post-id-16571Thanks for the answer. Maybe it's better to leave the constraints to the user.Wed, 04 Dec 2013 23:10:14 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16571#post-id-16571Comment by Nathann for <p>Helloooooooooooooooooooooo !!</p>
<p>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 <code>O_o</code></p>
<p>So if you want to make this work with negative values, you have to add lines like :</p>
<pre><code>p.set_min(p['x'],None)
p.set_min(p['y'],None)
</code></pre>
<p>in your code. And it will work, at least it does on my computer.</p>
<p>Perhaps I should add warnings everywhere in the doc <code>O_o</code></p>
<p>Nathann</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16563#post-id-16563http://www.mathworks.es/es/help/optim/ug/linprog.html and http://www.mathworks.es/discovery/linear-programming.html and http://www.maplesoft.com/support/help/AddOns/view.aspx?path=Optimization/LPSolveFri, 06 Dec 2013 06:33:14 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16563#post-id-16563Comment by Nathann for <p>Helloooooooooooooooooooooo !!</p>
<p>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 <code>O_o</code></p>
<p>So if you want to make this work with negative values, you have to add lines like :</p>
<pre><code>p.set_min(p['x'],None)
p.set_min(p['y'],None)
</code></pre>
<p>in your code. And it will work, at least it does on my computer.</p>
<p>Perhaps I should add warnings everywhere in the doc <code>O_o</code></p>
<p>Nathann</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16576#post-id-16576Well, 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.Wed, 04 Dec 2013 08:44:56 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16576#post-id-16576Comment by kcrisman for <p>Helloooooooooooooooooooooo !!</p>
<p>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 <code>O_o</code></p>
<p>So if you want to make this work with negative values, you have to add lines like :</p>
<pre><code>p.set_min(p['x'],None)
p.set_min(p['y'],None)
</code></pre>
<p>in your code. And it will work, at least it does on my computer.</p>
<p>Perhaps I should add warnings everywhere in the doc <code>O_o</code></p>
<p>Nathann</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16566#post-id-16566I would agree except that having Sage work like other programs is important too. @Nathann - what do LP solvers in Mma, Maple, Matlab do? (As opposed to specialty programs like CPLEX.)Thu, 05 Dec 2013 13:37:46 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16566#post-id-16566Comment by ppurka for <p>Helloooooooooooooooooooooo !!</p>
<p>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 <code>O_o</code></p>
<p>So if you want to make this work with negative values, you have to add lines like :</p>
<pre><code>p.set_min(p['x'],None)
p.set_min(p['y'],None)
</code></pre>
<p>in your code. And it will work, at least it does on my computer.</p>
<p>Perhaps I should add warnings everywhere in the doc <code>O_o</code></p>
<p>Nathann</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16560#post-id-16560Mathematica does not assume nonnegativity either. See this [wolfram alpha link](http://www.wolframalpha.com/input/?i=NMaximize%5B-x-y%2C+%7B1%2Bx%2By%3E%3D0%2C+2%2Bx%2F2-y%3E%3D0%2C+4-2x%2By%3E%3D0%7D%2C+%7Bx%2Cy%7D%5D)Fri, 06 Dec 2013 11:18:33 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16560#post-id-16560Comment by kcrisman for <p>Helloooooooooooooooooooooo !!</p>
<p>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 <code>O_o</code></p>
<p>So if you want to make this work with negative values, you have to add lines like :</p>
<pre><code>p.set_min(p['x'],None)
p.set_min(p['y'],None)
</code></pre>
<p>in your code. And it will work, at least it does on my computer.</p>
<p>Perhaps I should add warnings everywhere in the doc <code>O_o</code></p>
<p>Nathann</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16561#post-id-16561I'm going to start a thread about this on sage-devel. Now is the time to decide what our default should be.Fri, 06 Dec 2013 10:49:11 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16561#post-id-16561Comment by ppurka for <p>Helloooooooooooooooooooooo !!</p>
<p>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 <code>O_o</code></p>
<p>So if you want to make this work with negative values, you have to add lines like :</p>
<pre><code>p.set_min(p['x'],None)
p.set_min(p['y'],None)
</code></pre>
<p>in your code. And it will work, at least it does on my computer.</p>
<p>Perhaps I should add warnings everywhere in the doc <code>O_o</code></p>
<p>Nathann</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16577#post-id-16577I thought we handled this in ticket 12332Wed, 04 Dec 2013 06:08:52 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16577#post-id-16577Comment by Nathann for <p>Helloooooooooooooooooooooo !!</p>
<p>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 <code>O_o</code></p>
<p>So if you want to make this work with negative values, you have to add lines like :</p>
<pre><code>p.set_min(p['x'],None)
p.set_min(p['y'],None)
</code></pre>
<p>in your code. And it will work, at least it does on my computer.</p>
<p>Perhaps I should add warnings everywhere in the doc <code>O_o</code></p>
<p>Nathann</p>
https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16564#post-id-16564I've never used them, but it looks like they behave better. They don't seem to assume it, though you have a "assume=nonnegative" keyword in Maple that makes it easy to set (when calling solve() )Fri, 06 Dec 2013 06:32:45 +0100https://ask.sagemath.org/question/10800/why-do-i-get-the-wrong-answer-from-this-lp-problem/?comment=16564#post-id-16564