MibS: Example 2 (Experimental feature)

Model of the problem First level

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

Second level

\[\min_{y} y,\\ \notag s.t.\\ 2x - y + 3z<= 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)
@variable(Upper(model), z, Bin)

#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, 2x - 4y + 10z)

\[ 2 x - 4 y + 10 z \]

Upper constraints

@constraints(Upper(model), begin
    u1, -3x + 2y + 5z <= 12
    u2, x + 2y <= 20
    u3, x <= 10
end)
(u1 : -3 x + 5 z + 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 + 3z <= 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 = -8.0, nonzero_upper = Dict(0 => 6.0), nonzero_lower = Dict(0 => 5.0), all_upper = Dict{Any, Any}("x" => 6.0, "z" => 0), all_lower = Dict{Any, Any}("y" => 5.0), all_var = Dict{Any, Any}(MOI.VariableIndex(2) => 0, MOI.VariableIndex(3) => 5.0, MOI.VariableIndex(1) => 6.0))

Auto testing

@test solution.status == true
@test solution.objective ≈ -8.0
@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_upper["z"] == 0
@test solution.all_lower["y"] == 5.0
Test Passed

This page was generated using Literate.jl.