Setting start values for only some indicies of a BilevelJuMP variable

For the following BilevelJumP model, I want to set the start value for variable x 's even indices:

using JuMP, BilevelJuMP, Gurobi

a = [1.0, 0.0, 1.0, 1.0, 0.0, 0.0]

model = BilevelModel(Gurobi.Optimizer, mode = BilevelJuMP.SOS1Mode())
@variable(Lower(model), x[i=1:6], start = (mod(i,2) == 0) ? a[i] : nothing)

I get the following error:

ERROR: MethodError: no method matching Float64(::Nothing)
Closest candidates are:
  (::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50
  (::Type{T})(::Base.TwicePrecision) where T<:Number at twiceprecision.jl:243
  (::Type{T})(::Complex) where T<:Real at complex.jl:37

One way to make it work is I guess as follows:

using JuMP, BilevelJuMP, Gurobi

a = [1.0, 0.0, 1.0, 1.0, 0.0, 0.0]

model = BilevelModel(Gurobi.Optimizer, mode = BilevelJuMP.SOS1Mode())
@variable(Lower(model), x1[i=2:2:6], start = a[i])
@variable(Lower(model), x2[i=1:2:5])

However, why did the first approach not work? It looks more cleaner to me. Thanks!

Perhaps you want

@variable(Lower(model), x[i=1:6])
for i in 1:6
    if !iszero(a[i])
        set_start_value(x[i], a[i])
    end
end
2 Likes

p.s., this will be fixed in the next release of JuMP: Fix passing nothing to start kwarg by odow · Pull Request #2985 · jump-dev/JuMP.jl · GitHub

2 Likes

Thanks!

1 Like