Search code examples
optimizationpyomominimax

Solve maxmin problems using Pyomo Bilevel


I would like to solve the following simple maxmin problem using Pyomo (bilevel module)

enter image description here

I have solved the problem using the KKT's conditions and the result is (as expected) x=y=10

But I would like to solve similar problems using pyomo.bilevel

I know that this module is deprecated, but PAO (the indicated module) is still under development.

I have tried the following code, but no success

from pyomo.environ import *
from pyomo.bilevel import *

M = ConcreteModel()
M.x = Var(bounds=(0,100))
M.s = SubModel(fixed=M.x)
M.s.y = Var(bounds=(0,10))

M.s.o = Objective(expr= M.x, sense=maximize)
M.o = Objective(expr= M.s.o, sense=minimize)
M.s.c1 = Constraint(expr= M.x>=M.s.y)

opt = SolverFactory('gurobi')
opt.solve(M)

M.pprint()

If I try to switch x and y between M and M.s I get an error.

Thank you.


Solution

  • I believe I found the solution

    from pyomo.environ import *
    from pyomo.bilevel import *
    
    M = ConcreteModel()
    M.y = Var(bounds=(0,10))
    M.s = SubModel()
    M.s.x = Var(bounds=(0,100))
    
    M.s.o = Objective(expr= M.s.x, sense=minimize)
    M.o = Objective(expr= M.s.o, sense=maximize)
    M.s.c1 = Constraint(expr= M.s.x>=M.y)
    
    opt = SolverFactory('bilevel_blp_global')
    opt.options['solver'] = 'gurobi'
    result = opt.solve(M)
    
    M.s.x.pprint()
    M.y.pprint()
    

    If you are looking for the KKTs approach, please check the formulation below: enter image description here