# Issues solving a bilevel optimization with binary variables

**URL:** <https://discourse.julialang.org/t/issues-solving-a-bilevel-optimization-with-binary-variables/105460>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, bilevel\
**Created:** [October 27, 2023, 2:54am UTC](https://discourse.julialang.org/t/issues-solving-a-bilevel-optimization-with-binary-variables/105460 "2023-10-27T02:54:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kiki/32/202756_2.png) [@kiki](https://discourse.julialang.org/u/kiki)\
**Post date:** [October 27, 2023, 2:54am UTC](https://discourse.julialang.org/t/issues-solving-a-bilevel-optimization-with-binary-variables/105460/1 "2023-10-27T02:54:12Z")

</div>

I’m new using Julia to solve my nonlinear mixed integer bilevel model, so I have a model in JuMP using BilevelJuMP with binary and continuous variables at the lower and upper level and with non-linear [non quadratic] constraints and objectives in the two levels.

a. Is there a way for BilevelJuMP to accept nonlinear objectives and constraints not only in the upper level, but also in the lower? I’ve been using the Ipopt solver, but it doesn’t support discrete variables.

b. For the above case, trying another way to solve, I have linearized my objective and constraints in both levels, making it a linear mixed integer bilevel model. I’m using the CPLEX 20.1 solver in Julia 1.9.3.

> model = BilevelModel(CPLEX.Optimizer, mode = BilevelJuMP.SOS1Mode())

I have installed and set the CPLEX\_STUDIO\_BINARIES environment variable and run Pkg.add(“CPLEX”) without any issue, but when I try to optimize the model, it doesn’t work, I get the following error message: Would you have any suggestions on how to solve the issue?

Constraints of function MathOptInterface.SingleVariable in the Set MathOptInterface.ZeroOne are not implemented

Stacktrace:  
[1] error(::String, ::Type, ::String, ::Type, ::String)  
@ Base .\error.jl:44  
[2] supported\_constraints(con\_types::Vector{Tuple{DataType, DataType}})  
@ Dualization C:\Users\kchuq.julia\packages\Dualization\wDRnB\src\supported.jl:9  
[3] dualize(primal\_model::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}}, dual\_problem::Dualization.DualProblem{Float64, MathOptInterface.Utilities.GenericModel{Float64, Dualization.DualizableModelFunctionConstraints{Float64}}}, dual\_names::Dualization.DualNames, variable\_parameters::Vector{MathOptInterface.VariableIndex}, ignore\_objective::Bool)  
@ Dualization C:\Users\kchuq.julia\packages\Dualization\wDRnB\src\dualize.jl:50  
[4] #dualize#9  
@ C:\Users\kchuq.julia\packages\Dualization\wDRnB\src\dualize.jl:12 [inlined]  
[5] dualize  
@ C:\Users\kchuq.julia\packages\Dualization\wDRnB\src\dualize.jl:4 [inlined]  
[6] build\_bilevel(upper::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}}, lower::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}}, link::Dict{MathOptInterface.VariableIndex, MathOptInterface.VariableIndex}, upper\_variables::Vector{MathOptInterface.VariableIndex}, mode::BilevelJuMP.SOS1Mode{Float64}, upper\_var\_lower\_ctr::Dict{MathOptInterface.VariableIndex, MathOptInterface.ConstraintIndex}; copy\_names::Bool, pass\_start::Bool)  
@ BilevelJuMP C:\Users\kchuq.julia\packages\BilevelJuMP\YP5EH\src\moi.jl:287  
[7] optimize!(model::BilevelModel; lower\_prob::String, upper\_prob::String, bilevel\_prob::String, solver\_prob::String, file\_format::MathOptInterface.FileFormats.FileFormat)  
@ BilevelJuMP C:\Users\kchuq.julia\packages\BilevelJuMP\YP5EH\src\jump.jl:387  
[8] optimize!(model::BilevelModel)  
@ BilevelJuMP C:\Users\kchuq.julia\packages\BilevelJuMP\YP5EH\src\jump.jl:351  
[9] top-level scope  
@ In[70]:1

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:** [October 27, 2023, 3:32am UTC](https://discourse.julialang.org/t/issues-solving-a-bilevel-optimization-with-binary-variables/105460/2 "2023-10-27T03:32:29Z")

</div>

Hi @kiki, welcome to the forum!

Unfortunately, BilevelJuMP doesn’t support binary variables in the lower-level problem. It should probably throw a nicer error explaining this. (I’ve opened an issue: [Issues · joaquimg/BilevelJuMP.jl · GitHub](https://github.com/joaquimg/BilevelJuMP.jl/issues/211.))

Even if you fix that, you won’t be able to use CPLEX because it doesn’t support nonlinear programs.

If you can post a minimal example of your problem @joaquimg (the author of BilevelJuMP) might be able to point you in a better direction.

Oscar

---

<div class="post-metadata">

**Author:** ![kiki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kiki/32/202756_2.png) [@kiki](https://discourse.julialang.org/u/kiki)\
**Post date:** [November 16, 2023, 12:48am UTC](https://discourse.julialang.org/t/issues-solving-a-bilevel-optimization-with-binary-variables/105460/3 "2023-11-16T00:48:43Z")

</div>

Hi, I have a problem with the code belay, initially it was a bilevel mixed integer nonlinear problem, but it has been linearized, the variable a[i,j] has been used to linearize X[j]\*y[i, j] in this model, but after trying to optimize I get the error: Constraints of function MathOptInterface.SingleVariable in the Set MathOptInterface.ZeroOne are not implemented. Any idea how can i fixed it? Thanks

[code](https://1drv.ms/w/s!AtFiQe1m6Flxgek6GQrqbbRMgJbdkg?e=NfpwSp)

---

<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:** [November 29, 2023, 5:44pm UTC](https://discourse.julialang.org/t/issues-solving-a-bilevel-optimization-with-binary-variables/105460/4 "2023-11-29T17:44:23Z")

</div>

Requiring Binaries in the lower level is problematic because solution methods scale very very poorly.

BilevelJuMP can handle binaries in the lower level as an experimental feature:  
[MibS: Example 1 (Experimental feature) · BilevelJuMP.jl](https://joaquimg.github.io/BilevelJuMP.jl/stable/examples/MibS_example1/) (this will not scale to large scale problems even when the feature is no experimental anymore).
