# (Jump, Gurobi)Binary Variables end up with values no equal 1 or 0

Hello,
i try to opimise something and have the variable

``````    @variable(m, Taskstartstation[1:Stationnumber, 1:Ordernumber, 1:Tasknumbertotal], binary=true);
``````

or

``````@variable(m, Taskstartstation[1:Stationnumber, 1:Ordernumber, 1:Tasknumbertotal], bin);
``````

and somehow the solution is for example.

``````julia>     Oldtaskstartstation = JuMP.value.(Taskstartstation)
6×10×13 Array{Float64, 3}:
[:, :, 1] =
0.0  0.0         0.0  0.0         0.0          0.0  0.0         0.0         0.0         0.0
0.0  0.0         0.0  0.0         0.0          0.0  0.0         0.0         0.0         0.0
1.0  3.37834e-6  0.0  7.99834e-6  7.99834e-6   1.0  0.999997    7.99834e-6  7.99834e-6  7.99834e-6
0.0  0.0         0.0  0.0         0.0          0.0  0.0         0.0         0.0         0.0
0.0  0.0         0.0  0.0         0.0          0.0  0.0         0.0         0.0         0.0
-0.0  0.999997    1.0  0.999992    0.999992    -0.0  3.37834e-6  0.999992    0.999992    0.999992
``````

Why are there values not equal to 1 or 0?!

1 Like

Someone else can probably give a more accurate answer, but I think the underlying solver considers the result within tolerances. If Jump reports the problem as solved you should be able to safely round the result. As you can see, the numbers are very close to either 0 or 1.

1 Like

@DrChainsaw

The thing is, that it considered 0,99999 equals 1 was confusing.
If somone finds a solution how to stop it, it would be great.

I ran in problems because if this, later in the progamm.
Because i used simple high values like 99999*bin var in some constraints and now when the variable is not 0 but 0.000001, the constraint gives a false true.

So a solution would be good. My workaround was taking the 99999 and reduced it to 99, so the tolerance fits, but its shady.

1 Like

Are the constraints violated even when you round the values to integers?

If not, I’m 78.9999992% certain that the result is good (I’m not very experienced with mathematical programming hence the low confidence).

This issue might also give further insight: Wrong result with small values in objective · Issue #141 · jump-dev/Cbc.jl · GitHub

Edit: Link from issue which seems extra relevant: Gurobi tolerances and the limitations of double-precision arithmetic

1 Like

Hi there! Since this is your first post, welcome.

Why are there values not equal to 1 or 0?!

Solvers find solutions to a certain tolerance. They don’t compute using exact arithmetic. Your solution looks a little bad, typically you would expect `1e-8` instead of `1e-6`, but we’d need the full model to explain why. Do you have the output of the Gurobi log?

Since it seems you might be new to numerical optimization, Gurobi has a good documentation section on this and many related topics. I highly recommend the reading:

3 Likes

Can i simply take a integer and limit it to =>0 and <=1

Could be that Gurobi didn’t branch (it creates subproblems in which a binary variable is set to 0 and 1, respectively) but applied numerical techniques (such as cutting planes) that are subject to numerical errors.

No. That will have the same issue.

Can you provide the log or a minimal working example?

thats the problem mainly

Slackhighnumber = 9999

``````    Slacklownumber = 0.000001

Ordernumber = size(Ordersubset,1)

MaxAGV = AVGnumber

Transporttime = 0

AGVEndtoStart = 0 #Time it takes the AGV to get from the last Station to the first Station

m = nothing

m = Model(optimizer_with_attributes(Solver))

set_optimizer_attribute(m, "TimeLimit", Timelimitins)

#Variable

@variable(m, Endtime >= 0, Int);

@variable(m, Taskstart[1:Ordernumber, 1:Tasknumbertotal] >= 0, Int); #Divided everywhere by /100 as a Precisionlimit

@variable(m, OrderstartedbeforeOrder[1:Ordernumber,1:Ordernumber], Bin);

@variable(m, OrdernotfinshedbeforerOrder[1:Ordernumber,1:Ordernumber], Bin);

@variable(m, ActiveOrder[1:Ordernumber,1:Ordernumber], Bin);

#Fix

end

end

#complete all Orders ASAP

@objective(m, Min, Endtime + sum(Taskstart[O, End] for O = 1:Ordernumber)*Slacklownumber);

#Objective sub Constraint to find Maximum Endtime

#Constraint Start and End

#Constraint Precedence

#Constraint every Starttask has 1 Station

#Constraint maximum avgs

@constraint(m, OrderstartedbeforeOrder1[O1=1:Ordernumber,O2 in 1:Ordernumber; O2!=O1],0.01 * Taskstart[O1,Start]-0.01 * Taskstart[O2,Start] + Slacklownumber <= OrderstartedbeforeOrder[O1,O2]*Slackhighnumber);

@constraint(m, ActiveOrder1[O1=1:Ordernumber,O2=1:Ordernumber; O2!=O1],ActiveOrder[O1,O2] >= OrdernotfinshedbeforerOrder[O1,O2] + OrderstartedbeforeOrder[O1,O2] - 1);

@constraint(m, MaxAVGs1[O1=1:Ordernumber],sum(ActiveOrder[O1,O2] for O2 in 1:Ordernumber if O2!=O1)<=MaxAGV-1);

#constraint path

@constraint(m, OldOrders[O=(Oldordersnumber+1):Ordernumber], 0.01 * Taskstart[O, Start] >= FinisholdOrders);

optimize!(m);

println("Termination status: ", JuMP.termination_status(m));

println("Primal status: ", JuMP.primal_status(m));

println("Objective value: ", JuMP.objective_value(m));
``````

the binary variable are to determine if a process is for or after another process