# Bilevel JuMP

**URL:** <https://discourse.julialang.org/t/bilevel-jump/44068>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [August 1, 2020, 3:40am UTC](https://discourse.julialang.org/t/bilevel-jump/44068 "2020-08-01T03:40:21Z")\
**Posts on this page:** 11\
**Page:** 3

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [August 12, 2020, 12:59pm UTC](https://discourse.julialang.org/t/bilevel-jump/44068/41 "2020-08-12T12:59:56Z")

</div>

> [@dty](#):
>
> `ERROR: LoadError: Gurobi.GurobiError(10020, "Q matrix is not positive semi-definite (PSD). Set NonConvex parameter to 2 to solve model.")`

Product mode gives you a non-convex QCQP problem, which is passed to Gurobi.  
Gurobi tells you that you must set the `NonConvex` parameter to `2`, see the [Gurobi documentation](https://www.gurobi.com/documentation/9.0/refman/nonconvex.html#parameter:NonConvex). If you don’t do that, the solver will abort.

In general, if you encounter an error that is reported by a solver (e.g., a `GurobiError` or a `CPLEXError`, you should first check that solver’s documentation to understand what the error means.

---

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 12, 2020, 2:27pm UTC](https://discourse.julialang.org/t/bilevel-jump/44068/42 "2020-08-12T14:27:12Z")

</div>

ok，thankyou！

---

<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:** [August 12, 2020, 9:42pm UTC](https://discourse.julialang.org/t/bilevel-jump/44068/43 "2020-08-12T21:42:28Z")

</div>

Product mode should be used with NLP solvers such as Ipopt and Knitro

---

<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:** [August 12, 2020, 9:44pm UTC](https://discourse.julialang.org/t/bilevel-jump/44068/44 "2020-08-12T21:44:55Z")

</div>

> [@dty](#):
>
> how to select the bound value of dual variable and original variable

That is exactly the main difficulty of the Fortuny Amat formulation.  
Finding those bounds might be as hard as solving the problem itself, however, sometimes people can find reasonable bounds by carefully analyzing the problem. There is no free lunch…

---

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 13, 2020, 1:34am UTC](https://discourse.julialang.org/t/bilevel-jump/44068/45 "2020-08-13T01:34:06Z")

</div>

😁OK, I’ll try.  
And I tried to run the source code again, ran 125260 seconds, the results are as follows，What does that mean？

```julia
Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x7fff450fb83f -- GRBsetlogfile at D:\gurobi\win64\bin\gurobi90.DLL (unknown line)
in expression starting at E:\Julia绋嬪簭\瀹屾暣鐗?jl:213
GRBsetlogfile at D:\gurobi\win64\bin\gurobi90.DLL (unknown line)
GRBsetlogfile at D:\gurobi\win64\bin\gurobi90.DLL (unknown line)
GRBsetlogfile at D:\gurobi\win64\bin\gurobi90.DLL (unknown line)
GRBsetlogfile at D:\gurobi\win64\bin\gurobi90.DLL (unknown line)
GRBsetlogfile at D:\gurobi\win64\bin\gurobi90.DLL (unknown line)
GRBsetlogfile at D:\gurobi\win64\bin\gurobi90.DLL (unknown line)
macro expansion at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\Gurobi\7YNJV\src\grb_common.jl:60 [inlined]
optimize at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\Gurobi\7YNJV\src\grb_solve.jl:5 [inlined]
optimize! at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\Gurobi\7YNJV\src\MOI_wrapper.jl:1920
optimize! at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\MathOptInterface\bygN7\src\Bridges\bridge_optimizer.jl:239
#optimize!#42 at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\BilevelJuMP\Ll9sk\src\jump.jl:993
optimize! at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\BilevelJuMP\Ll9sk\src\jump.jl:919
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1700 [inlined]
do_call at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:369
eval_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:458
eval_stmt_value at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:409 [inlined]
eval_body at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:799
jl_interpret_toplevel_thunk at /cygdrive/d/buildbot/worker/package_win64/build/src\interpreter.c:911
jl_toplevel_eval_flex at /cygdrive/d/buildbot/worker/package_win64/build/src\toplevel.c:819
jl_parse_eval_all at /cygdrive/d/buildbot/worker/package_win64/build/src\ast.c:872
include_string at .\loading.jl:1080
#220 at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\Atom\9h5Up\src\eval.jl:174
withpath at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\CodeTools\VsjEq\src\utils.jl:30
withpath at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\Atom\9h5Up\src\eval.jl:9
#219 at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\Atom\9h5Up\src\eval.jl:171 [inlined]
with_logstate at .\logging.jl:398
with_logger at .\logging.jl:505 [inlined]
#218 at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\Atom\9h5Up\src\eval.jl:170 [inlined]
hideprompt at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\Atom\9h5Up\src\repl.jl:127
macro expansion at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\Media\ItEPc\src\dynamic.jl:24 [inlined]
evalall at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\Atom\9h5Up\src\eval.jl:160
jl_apply at /cygdrive/d/buildbot/worker/package_win64/build/src\julia.h:1700 [inlined]

```

---

<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:** [August 13, 2020, 4:22am UTC](https://discourse.julialang.org/t/bilevel-jump/44068/46 "2020-08-13T04:22:27Z")

</div>

That is a gurobi issue.  
Might be memory related…  
From the stack it seems related to a log file. Maybe its too large?  
I don’t know…

---

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 13, 2020, 8:01am UTC](https://discourse.julialang.org/t/bilevel-jump/44068/47 "2020-08-13T08:01:08Z")

</div>

Maybe you’re right. Thank you

---

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 13, 2020, 9:28am UTC](https://discourse.julialang.org/t/bilevel-jump/44068/48 "2020-08-13T09:28:16Z")

</div>

```julia
@objective(Lower(model), Min, sum(0.025*PPV+0.029*PWT+0.025*2*PMT))

     @constraint(Lower(model), c1, PGD_EX+PWT+PPV+2*PMT .== PDL)

     
     BilevelJuMP.set_dual_upper_bound(c1, 150)
     BilevelJuMP.set_dual_lower_bound(c1, -150)
     BilevelJuMP.set_primal_upper_bound_hint(PGD_EX, 200)
     BilevelJuMP.set_primal_upper_bound_hint(PGm1, 800)
     BilevelJuMP.set_primal_upper_bound_hint(PGm2, 300)
     BilevelJuMP.set_primal_upper_bound_hint(PMT, 200)
        
        BilevelJuMP.set_primal_lower_bound_hint(PGD_EX, -200)
        BilevelJuMP.set_primal_lower_bound_hint(PGm1, -2)
        BilevelJuMP.set_primal_lower_bound_hint(PGm2, -2)
        BilevelJuMP.set_primal_lower_bound_hint(PMT, -2)

```

I run the basic scalar successfully, but how can I modify the matrix constraints and variables

```julia
LoadError: MethodError: no method matching set_dual_upper_bound(::Array{ConstraintRef{BilevelModel,Int64,ScalarShape},2}, ::Int64)
Closest candidates are:
  set_dual_upper_bound(::ConstraintRef{BilevelModel,Int64,Shape} where Shape<:AbstractShape, ::T) where T<:Number at C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\BilevelJuMP\Ll9sk\src\jump.jl:602
Stacktrace:
 [1] top-level scope at untitled-a0bdb1d4b669a3031f9496759d22bd8f:129
in expression starting at untitled-a0bdb1d4b669a3031f9496759d22bd8f:129

```

---

<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:** [August 13, 2020, 2:16pm UTC](https://discourse.julialang.org/t/bilevel-jump/44068/49 "2020-08-13T14:16:56Z")

</div>

As the error says You are passing an array while you should be passing one element at a time of the array

---

<div class="post-metadata">

**Author:** ![FVSB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fvsb/32/213029_2.png) [@FVSB](https://discourse.julialang.org/u/FVSB)\
**Post date:** [December 13, 2024, 12:29am UTC](https://discourse.julialang.org/t/bilevel-jump/44068/50 "2024-12-13T00:29:35Z")

</div>

Hello, good day. I am trying to use this module with this example problem, and I am encountering issues. Additionally, it also has problems with other non-convex problems. Does anyone have any idea? Thank you in advance

```julia
BilevelJuMP.@variable(Upper(model), x[1:4])
BilevelJuMP.@variable(Upper(model), y[1:4])
part_1_1=200-y[1]-y[3]
part_1_2=y[1]+y[3]
part_1=part_1_1*part_1_2
part_2_1=160-y[2]-y[4]
part_2_2=y[2]+y[4]
part_2=part_2_1*part_2_2
BilevelJuMP.@objective(Upper(model),Min,part_1+part_2)
BilevelJuMP.@constraints(Upper(model),begin
sum(x)-40<=0
x[1]-10<=0
x[2]-5<=0
x[3]-15<=0
x[4]-20<=0
-x<=0
end)
BilevelJuMP.@objective(Lower(model),Min,(y[1]-4)^2+(y[2]-13)^2+(y[3]-35)^2+(y[4]-2)^2)
BilevelJuMP.@constraints(Lower(model),begin
0.4y[1]+0.7y[2]-x[1]<=0
0.6y[1]+0.3y[2]-x[2]<=0
0.4y[3]+0.7y[3]-x[3]<=0
0.6y[3]+0.3y[4]-x[4]<=0
y[1]-20<=0
y[2]-20<=0
y[3]-40<=0
y[4]-40<=0
-y<=0
end)

```

---

<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:** [January 22, 2025, 3:59am UTC](https://discourse.julialang.org/t/bilevel-jump/44068/51 "2025-01-22T03:59:34Z")

</div>

Hi @FVSB ,  
Which solver and solution method are you using?  
Can you post the error that you get?

[Previous page](https://discourse.julialang.org/t/bilevel-jump/44068.md?page=2)
