I am trying to implement a bilevel model to pyomo. Specifically, when I get the results from the upper level, I want the lower level model to inherit values from the solution of the variables of the upper level. And I want to implement a for loop between the models, in order to iterate until their objective functions converge.
The algorithm I want to implement is attached. Both the upper and lower level models are MILP and will be solved with CPLEX.
My question is how can the lower level model inherit the values of the upper level as parameters. This is my implementation but it is not correct. How can I formulate this?
Upper level model
up = AbstractModel()
up.c = Set()
up.h = Set()
up.p = Set()
up.t = RangeSet(130)
up.INH = Var(up.p, up.h, up.t, within=NonNegativeIntegers)
Lower level model
lp = AbstractModel()
lp.c = Set()
lp.h = Set()
lp.p = Set()
lp.t = RangeSet(130)
lp.INH2 = Param(lp.p, lp.h, lp.t, default=instance.INH)