# Bilevel model with multiple lower levels

**URL:** <https://discourse.julialang.org/t/bilevel-model-with-multiple-lower-levels/100113>\
**Category:** Optimization (Mathematical)\
**Tags:** bilevel\
**Created:** [June 9, 2023, 3:18pm UTC](https://discourse.julialang.org/t/bilevel-model-with-multiple-lower-levels/100113 "2023-06-09T15:18:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![martina.gherardi](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@martina.gherardi](https://discourse.julialang.org/u/martina.gherardi)\
**Post date:** [June 9, 2023, 3:18pm UTC](https://discourse.julialang.org/t/bilevel-model-with-multiple-lower-levels/100113/1 "2023-06-09T15:18:24Z")

</div>

Hi,

I’m currently working on a bilevel problem that has:

- one lower level problem for each period
- a single upper level problem that considers all the periods

How to code this kind of bilevel problem with “mode=BilevelJuMP.StrongDualityMode()” ?

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:** [June 9, 2023, 11:00pm UTC](https://discourse.julialang.org/t/bilevel-model-with-multiple-lower-levels/100113/2 "2023-06-09T23:00:52Z")

</div>

Hi @martina.gherardi, welcome to the forum.

I don’t think BilevelJuMP explicitly supports multiple lower levels yet. But @joaquimg can confirm.

There’s an open issue since 2019 about this: [Multiple second level problems · Issue #1 · joaquimg/BilevelJuMP.jl · GitHub](https://github.com/joaquimg/BilevelJuMP.jl/issues/1)

If the lower levels are independent, then you could just write a single lower-level problem which contained all of the subproblems?

---

<div class="post-metadata">

**Author:** ![martina.gherardi](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@martina.gherardi](https://discourse.julialang.org/u/martina.gherardi)\
**Post date:** [June 10, 2023, 10:06am UTC](https://discourse.julialang.org/t/bilevel-model-with-multiple-lower-levels/100113/3 "2023-06-10T10:06:04Z")

</div>

Hi Oscar,

Thanks for your reply.

The characteristics of my problem would require to write 24 lower levels (market-clearing problems), one for each hour.  
Each clearing problem has

- its own generation-demand balance constraint,
- its own constraints on the minimum and maximum quantity offered by each generating unit.  
and determines the hourly clearing price as the dual variable of the balance constraint.  
The solution with the lowest cost must be chosen among all the solutions that meet these constraints.

I have not been able to code in Julia this problem because it appears that Julia admits a single lower level problem, as you suggested.

In your opinion,

1. Are these kinds of lower levels (with the same structure replicating for each hour) an example of independent lower levels or not?
2. If they are independent, how to code in Julia this particular case of multiple but independent lower levels?

Many thanks,  
Martina

---

<div class="post-metadata">

**Author:** ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)\
**Post date:** [June 21, 2023, 4:40am UTC](https://discourse.julialang.org/t/bilevel-model-with-multiple-lower-levels/100113/4 "2023-06-21T04:40:09Z")

</div>

Independent lower level models mean:  
each lower level model can only contain its own variables and upper level variables, no lower level variable can be shared between 2 lower level models.

no special structures is required, you problem seem to fit this case in a first sight.

this Gist has an example: [Multiple lower level example · GitHub](https://gist.github.com/joaquimg/0fdb18fccd8401952f41b35aaf3cf212)

this might become a tutorial at some point. I have been avoiding that hoping I can make that explicit in BilevelJuMP.
