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

MibS is an external solver rather than a JuMP optimizer, so it is selected with a mode and needs no set_optimizer. MibS_jll is not a dependency of BilevelJuMP, so its executable is passed in explicitly.

model = BilevelModel()
BilevelJuMP.set_mode(model, BilevelJuMP.MibSMode(MibS_jll.mibs))
An Abstract JuMP Model
Feasibility problem with:
Variables: 0
Upper Constraints: 0
Lower Constraints: 0
Bilevel Model
Solution method: BilevelJuMP.MibSMode{Float64}(MibS_jll.mibs, false, "", true)
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 objective 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 \]

Now we can solve the problem and query the solution with the usual JuMP functions:

optimize!(model)

termination_status(model)

objective_value(model)

value(x)

value(y)
5.0

Auto testing

@test termination_status(model) == MOI.OPTIMAL
@test primal_status(model) == MOI.FEASIBLE_POINT
@test objective_value(model) ≈ -53
@test value(x) ≈ 6.0
@test value(y) ≈ 5.0
Test Passed

This page was generated using Literate.jl.