If you have a JuMP model, you probably had a function (or many) that built that.
For instance:
function model_builder()
model = Model()
# add variables and constraints
return model
end
model = model_builder()
You could change to:
model = Model()
function model_builder(model)
# add variables and constraints
return
end
model_builder(model)
# at this point `model` would be equivalent to the first version
you can re-use the builder for the lower level of a bilvel problem like this:
model = BilevelModel(...)
function model_builder(model)
# add variables and constraints
return
end
model_builder(Lower(model))
# this would load the lower level
In this case you don’t even need to pre-build a model an use a copy. Just re-use a builder function.