MibS: Example 1 (Experimental feature)

Model of the problem First level

\[\min_{x} -3x -7y,\\ \notag s.t.\\ -3x + 2y \leq 12,\\ x + 2y \leq 20,\\ x \leq 10,\\ x \in \mathbb{Z},\\\]

Second level

\[\min_{y} y,\\ \notag s.t.\\ 2x - y <= 7,\\ -2x + 4y <= 16,\\ y <= 5\\ y \in \mathbb{Z}\\\]

using BilevelJuMP
using Test
using MibS_jll

model = BilevelModel()
An Abstract JuMP Model
Feasibility problem with:
Variables: 0
Upper Constraints: 0
Lower Constraints: 0
Bilevel Model
Solution method: BilevelJuMP.NoMode{Float64}
No solver attached

First we need to create all of the variables in the upper and lower problems:

Upper level variables

@variable(Upper(model), x, Int)

#Lower level variables
@variable(Lower(model), y, Int)

$ y $

Then we can add the objective and constraints of the upper problem:

Upper level objecive function

@objective(Upper(model), Min, -3x - 7y)

$ -3 x - 7 y $

Upper constraints

@constraints(Upper(model), begin
    u1, -3x + 2y <= 12
    u2, x + 2y <= 20
    u3, x <= 10
end)
(u1 : -3 x + 2 y ≤ 12, u2 : x + 2 y ≤ 20, u3 : x ≤ 10)

Followed by the objective and constraints of the lower problem:

Lower objective function

@objective(Lower(model), Min, y)

$ y $

Lower constraints

@constraint(Lower(model), l1, 2x - y <= 7)
@constraint(Lower(model), l2, -2x + 4y <= 16)
@constraint(Lower(model), l3, y <= 5)

\[ y \leq 5 \]

Using MibS Solver

solution = BilevelJuMP.solve_with_MibS(model, MibS_jll.mibs)
(status = true, objective = -53.0, nonzero_upper = Dict(0 => 6.0), nonzero_lower = Dict(0 => 5.0), all_upper = Dict{Any, Any}("x" => 6.0), all_lower = Dict{Any, Any}("y" => 5.0), all_var = Dict{Any, Any}(MOI.VariableIndex(2) => 5.0, MOI.VariableIndex(1) => 6.0))

Auto testing

@test solution.status == true
@test solution.objective ≈ -53
@test solution.nonzero_upper == Dict(0 => 6.0)
@test solution.nonzero_lower == Dict(0 => 5.0)
@test solution.all_upper["x"] == 6.0
@test solution.all_lower["y"] == 5.0
Test Passed

This page was generated using Literate.jl.