Params in DAT file specified as integer vs floating point affect results

30 views
Skip to first unread message

Joe DeCarolis

unread,
May 31, 2017, 4:09:19 PM5/31/17
to Pyomo Forum
Hi All,

I've noticed a discrepancy in my model results using two nearly identical DAT files as input. The only difference is that in one DAT file, some identical parameters are specified as integers rather than floating point numbers (e.g., "1" versus "1.0"). This difference in input specification leads to differences in the objective function value as well as decision variable values. I'm not sure why it would make a difference, and am wondering if anyone else has observed this behavior?

I am currently running Python 2.7.11, Pyomo 4.2.10784, and using CPLEX 12.6.1.0.

Thanks,
Joe

Gabriel Hackebeil

unread,
May 31, 2017, 4:20:32 PM5/31/17
to Pyomo Forum
Check for places where you use division. The default behavior in Python 2 is to use integer division when the denominator and numerator are both integers (e.g., 2/3 = 0). If you want to disable integer division in Python 2, add “from __future__ import division” to the very top of your model file (or any python file you write).

This behavior is fixed in Python 3. Integer division can be recovered using // rather than /.

Gabe

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicholson, Bethany L.

unread,
May 31, 2017, 4:20:51 PM5/31/17
to pyomo...@googlegroups.com

Are you ever dividing one parameter value by another? Python 2.7 does integer division by default (i.e. 1/2 = 0). You can force floating-point division by making sure at least one of the parameters is a float or by including the import statement “from __future__ import division”. In Python 3, floating-point division is the default (i.e. 1/2 = 0.5)

 

Bethany

--

Joe DeCarolis

unread,
May 31, 2017, 4:35:23 PM5/31/17
to pyomo...@googlegroups.com
Hi Gabe and Bethany,

Thanks to you both for the quick response! Adding the import statement solved the problem! (Somewhere in our 1000+ lines of equations, I must have been doing integer division.)

Best,
Joe

To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum+unsubscribe@googlegroups.com.


For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Pyomo Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyomo-forum/Mf1w-B1U3ac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyomo-forum+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages