Binary Variable

54 views
Skip to first unread message

Jacob Lopez

unread,
Oct 7, 2022, 10:57:34 AM10/7/22
to AMPL Modeling Language
Hey,

i defined that y is binary variable
var y {M} binary;

if i get my result it shows:

y [*] :=
   y1          6.01527e-10
   y2          6.36915e-15
   y3             1
   y4        2.44933e-14

i need a result that for example y3 is 1 and the other are 0.

i already definded in my model that just one variable can be 1, and the rest 0.
i used the knitro solver.


if i use the minos solver i get the right presentation

y [*] :=
   y1          0
   y2          0
   y3             1
   y4        0

whats the problem with the presentation if i use the knitro solver?

AMPL Google Group

unread,
Oct 7, 2022, 6:07:16 PM10/7/22
to AMPL Modeling Language
Because numbers in the computer have only a fixed number of bits of precision, calculations are not exact. With some solvers (including Knitro), the slightly inexact calculations cause values of binary variables that should be zero to come out instead as very tiny values, like 6.01527e-10, 6.36915e-15, and 2.44933e-14. You should consider these values to be zero in the solution.

If you are using AMPL's display command, you can tell it to display very tiny values as zeros, by setting the display_eps option. For example, setting "option display_eps 1e-8;" will cause any number bigger than -1e-8 and smaller than 1e-8 to be shown as 0 by display. Then your result from Knitro will look like the one from MINOS.

If you are not using the display command, you can write trunc(y[i],8) to get the same effect.

(MINOS cannot force variables to have integer values, so when a variable is defined as binary, MINOS only requires it to be >= 0 and <= 1. For your problem, the solution just happened to come out binary anyway. MINOS and Knitro use different optimization methods, which can result in slightly different solutions as you are seeing.)


--
Robert Fourer
am...@googlegroups.com
{#HS:2031533510-112262#}

Jacob Lopez

unread,
Oct 8, 2022, 10:34:19 AM10/8/22
to AMPL Modeling Language
Thank you :-)
Reply all
Reply to author
Forward
0 new messages