Sage: Ticket #10505: Round values returned by CPLEX when the variable's type is integer/binary
https://trac.sagemath.org/ticket/10505
<p>
CPLEX is a funny guy who does not understand that 1.546846847 e-17 is not a proper value for a binary variable. As I often forgot to replace test <code></code>== 1<code></code> by <code></code>> .5<code></code> and as it is anyway what CPLEX should return, this patch rounds values given to the variables before returning them when it is sound. It amounts to copying two lines from <code></code>is_variable_continuous<code></code> in the <code></code>get_variable_value<code></code> method, and doctests pass better with CPLEX (which is not the case with the new patch for TSP <a class="closed ticket" href="https://trac.sagemath.org/ticket/10497" title="enhancement: Constraint Generation for TSP/Hamiltonian Cycle (closed: fixed)">#10497</a>)
</p>
<p>
Nathann
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/10505
Trac 1.1.6ncohenMon, 20 Dec 2010 16:14:10 GMTstatus changed
https://trac.sagemath.org/ticket/10505#comment:1
https://trac.sagemath.org/ticket/10505#comment:1
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
</ul>
TicketdcoudertFri, 14 Oct 2011 09:08:23 GMTstatus changed; reviewer set
https://trac.sagemath.org/ticket/10505#comment:2
https://trac.sagemath.org/ticket/10505#comment:2
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_info</em>
</li>
<li><strong>reviewer</strong>
set to <em>David Coudert</em>
</li>
</ul>
<p>
The returned value is not of integer type (2.0 instead of 2). Should we cast it to Integer, or int, or leave it like that ?
</p>
TicketncohenFri, 14 Oct 2011 09:25:49 GMTstatus changed
https://trac.sagemath.org/ticket/10505#comment:3
https://trac.sagemath.org/ticket/10505#comment:3
<ul>
<li><strong>status</strong>
changed from <em>needs_info</em> to <em>needs_review</em>
</li>
</ul>
<p>
Oops... You are right !
</p>
<p>
The thing is that casting it to Integer would mean having to create a new object for each returned variable, even when using the code from the C level. And casting it to a Python int would mean that you can not divide is safely anymore (1/2 becomes 0).
</p>
<p>
What do you think of letting it stay like that ? The goal was really to be able to test (variable == 0) without fearing that variable (declared as binary in the LP) would have 0.0000001 as a value.
</p>
<p>
We can still *really* cast the values to integer in situations where the user expect it, like in <a class="closed ticket" href="https://trac.sagemath.org/ticket/11367" title="enhancement: Rounding values, and inconsistencies in graph methods (closed: fixed)">#11367</a> which just got reviewed.
</p>
<p>
While I was at it, though, I noticed a mistake in the documentation generated from the mip.pyx file : the first line contained a math equation which was not properly written.. I just updated the patch to fix it ! <code>:-)</code>
</p>
<p>
Nathann
</p>
TicketdcoudertFri, 14 Oct 2011 09:43:17 GMTstatus changed
https://trac.sagemath.org/ticket/10505#comment:4
https://trac.sagemath.org/ticket/10505#comment:4
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_info</em>
</li>
</ul>
<p>
OK, you can live it like this, but it should be clearly indicated in the documentation to avoid confusion. Users can cast afterwards depending of their needs.
</p>
<p>
Concerning the documentation, I don't see any improvement. In fact, most of the math equations are not properly displayed in the page. I see only the latex code (e.g., w_i \in \mathbb{Z}).
</p>
TicketncohenFri, 14 Oct 2011 10:17:58 GMTstatus changed
https://trac.sagemath.org/ticket/10505#comment:5
https://trac.sagemath.org/ticket/10505#comment:5
<ul>
<li><strong>status</strong>
changed from <em>needs_info</em> to <em>needs_review</em>
</li>
</ul>
<blockquote class="citation">
<p>
OK, you can live it like this, but it should be clearly indicated in the documentation to avoid confusion. Users can cast afterwards depending of their needs.
</p>
</blockquote>
<p>
Patch updated. I added a note in the documentation of <code></code><a class="missing wiki">MixedIntegerLinearProgram?</a>.get_values<code></code>.
</p>
<blockquote class="citation">
<p>
Concerning the documentation, I don't see any improvement. In fact, most of the math equations are not properly displayed in the page. I see only the latex code (e.g., w_i \in \mathbb{Z}).
</p>
</blockquote>
<p>
Are you talking of the HTML documentation ? The LaTeX formula will of course never appear in the console ! In my version of it, I find nothing wrong with the others formulas contained in this page. <code>O_o</code>
</p>
<p>
Nathann
</p>
TicketncohenFri, 14 Oct 2011 10:18:13 GMTattachment set
https://trac.sagemath.org/ticket/10505
https://trac.sagemath.org/ticket/10505
<ul>
<li><strong>attachment</strong>
set to <em>trac_10505.patch</em>
</li>
</ul>
TicketdcoudertFri, 14 Oct 2011 11:43:35 GMTstatus changed
https://trac.sagemath.org/ticket/10505#comment:6
https://trac.sagemath.org/ticket/10505#comment:6
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
</ul>
<p>
I'm now satisfied with this patch.
</p>
TicketjdemeyerSun, 16 Oct 2011 15:39:14 GMTmilestone changed
https://trac.sagemath.org/ticket/10505#comment:7
https://trac.sagemath.org/ticket/10505#comment:7
<ul>
<li><strong>milestone</strong>
changed from <em>sage-4.7.2</em> to <em>sage-4.7.3</em>
</li>
</ul>
TicketjdemeyerTue, 18 Oct 2011 20:14:42 GMTstatus changed; resolution, merged set
https://trac.sagemath.org/ticket/10505#comment:8
https://trac.sagemath.org/ticket/10505#comment:8
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>merged</strong>
set to <em>sage-4.7.3.alpha0</em>
</li>
</ul>
TicketjdemeyerThu, 03 Nov 2011 16:14:43 GMTmilestone deleted
https://trac.sagemath.org/ticket/10505#comment:9
https://trac.sagemath.org/ticket/10505#comment:9
<ul>
<li><strong>milestone</strong>
<em>sage-4.7.3</em> deleted
</li>
</ul>
<p>
Milestone sage-4.7.3 deleted
</p>
TicketjdemeyerThu, 03 Nov 2011 16:16:28 GMTmerged changed; milestone set
https://trac.sagemath.org/ticket/10505#comment:10
https://trac.sagemath.org/ticket/10505#comment:10
<ul>
<li><strong>merged</strong>
changed from <em>sage-4.7.3.alpha0</em> to <em>sage-4.8.alpha0</em>
</li>
<li><strong>milestone</strong>
set to <em>sage-4.8</em>
</li>
</ul>
Ticket