Round variables in JuMP

Dear all,
I have a model in JuMP with the following range index:
variable(model, x[i in 1:10, t in 1:10, h in H[i], bin)



ie., h depends on i.

Due numerial rounds, in the optimal solution of my model, value.(x) are not binary.
How can I round value.(x) where the index h range depends on i? I have tried round.(value.(x)) but this does not work.

You could use a loop. Something like

xvals = value.(x)

for i in 1:10, t in 1:10, h in H[i]
    xvals[i,t,h] = round(Int, xvals[i,t,h])

This should work for the output. Perhaps even round.(Int, value.(x)).

But you can’t use this as a constraint inside the model. Solvers do not use exact arithmetic. They use a tolerance to check if the variable is “binary” so you can get small values like 1e-8 or nearly one values like 0.99999999 or 1.00000001. This should be considered “0” and “1” for practical purposes.

I use the round after the optimization process.

1 Like