# Setting start values for only some indicies of a BilevelJuMP variable

**URL:** <https://discourse.julialang.org/t/setting-start-values-for-only-some-indicies-of-a-bileveljump-variable/81160>\
**Category:** Optimization (Mathematical)\
**Tags:** question, package, jump\
**Created:** [May 16, 2022, 5:48pm UTC](https://discourse.julialang.org/t/setting-start-values-for-only-some-indicies-of-a-bileveljump-variable/81160 "2022-05-16T17:48:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![math\_opt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/math_opt/32/25317_2.png) [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Post date:** [May 16, 2022, 5:48pm UTC](https://discourse.julialang.org/t/setting-start-values-for-only-some-indicies-of-a-bileveljump-variable/81160/1 "2022-05-16T17:48:11Z")

</div>

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

```julia
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:

```julia
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:

```julia
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!

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 16, 2022, 6:15pm UTC](https://discourse.julialang.org/t/setting-start-values-for-only-some-indicies-of-a-bileveljump-variable/81160/2 "2022-05-16T18:15:26Z")

</div>

Perhaps you want

```nohighlight
@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

```

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 16, 2022, 10:59pm UTC](https://discourse.julialang.org/t/setting-start-values-for-only-some-indicies-of-a-bileveljump-variable/81160/3 "2022-05-16T22:59:05Z")

</div>

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](https://github.com/jump-dev/JuMP.jl/pull/2985)

---

<div class="post-metadata">

**Author:** ![math\_opt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/math_opt/32/25317_2.png) [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Post date:** [May 17, 2022, 2:17am UTC](https://discourse.julialang.org/t/setting-start-values-for-only-some-indicies-of-a-bileveljump-variable/81160/4 "2022-05-17T02:17:00Z")

</div>

Thanks!
