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.Thu, 23 Jun 2016 12:21:34 +0200Finding an assignment that satisfies a set of inequalitieshttps://ask.sagemath.org/question/32788/finding-an-assignment-that-satisfies-a-set-of-inequalities/ I have the following simple set of inequalities:
var('x,y')
assume(x,'integer')
assume(y,'integer')
assume(x>0)
assume(y>0)
ineq = [x<y, y<3]
I would like to find an assignment that satisfies this set of inequalities. In this case there is one such assignment:
x=1, y=2
In general there may be many assignments; I only need to find one. Is there a way to do this in SageMath?Sun, 13 Mar 2016 09:59:52 +0100https://ask.sagemath.org/question/32788/finding-an-assignment-that-satisfies-a-set-of-inequalities/Answer by tmonteil for <p>I have the following simple set of inequalities:</p>
<pre><code>var('x,y')
assume(x,'integer')
assume(y,'integer')
assume(x>0)
assume(y>0)
ineq = [x<y, y<3]
</code></pre>
<p>I would like to find an assignment that satisfies this set of inequalities. In this case there is one such assignment:</p>
<pre><code>x=1, y=2
</code></pre>
<p>In general there may be many assignments; I only need to find one. Is there a way to do this in SageMath?</p>
https://ask.sagemath.org/question/32788/finding-an-assignment-that-satisfies-a-set-of-inequalities/?answer=32790#post-id-32790Since your equations are linear, and your constraints about the variables is that they are integer, i strongly suggest to look at linear programming in Sage:
- http://doc.sagemath.org/html/en/thematic_tutorials/linear_programming.html
- http://doc.sagemath.org/html/en/reference/numerical/sage/numerical/mip.html
Do not hesitate to ask for more details if something is not clear (with your attempts so that we can discuss them).
Sun, 13 Mar 2016 11:57:36 +0100https://ask.sagemath.org/question/32788/finding-an-assignment-that-satisfies-a-set-of-inequalities/?answer=32790#post-id-32790Comment by Erel Segal-Halevi for <p>Since your equations are linear, and your constraints about the variables is that they are integer, i strongly suggest to look at linear programming in Sage:</p>
<ul>
<li><a href="http://doc.sagemath.org/html/en/thematic_tutorials/linear_programming.html">http://doc.sagemath.org/html/en/thema...</a></li>
<li><a href="http://doc.sagemath.org/html/en/reference/numerical/sage/numerical/mip.html">http://doc.sagemath.org/html/en/refer...</a></li>
</ul>
<p>Do not hesitate to ask for more details if something is not clear (with your attempts so that we can discuss them).</p>
https://ask.sagemath.org/question/32788/finding-an-assignment-that-satisfies-a-set-of-inequalities/?comment=33893#post-id-33893I read the manual about linear programming, but, apparently it talks about maximization problems. I am not interested in maximization - I only want to find a single assignment that satisfies the inequalities. Can you show me how to solve a simple example, e.g, "find x and y such that x<y and y<3"?Thu, 23 Jun 2016 12:21:34 +0200https://ask.sagemath.org/question/32788/finding-an-assignment-that-satisfies-a-set-of-inequalities/?comment=33893#post-id-33893