Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Existing JuMP Model Construction Code with BilevelJuMP #217

Open
dsigler1234 opened this issue Jun 17, 2024 · 1 comment
Open

Using Existing JuMP Model Construction Code with BilevelJuMP #217

dsigler1234 opened this issue Jun 17, 2024 · 1 comment

Comments

@dsigler1234
Copy link

Hello,

I was hoping to use BilevelJuMP with PowerSimulations.jl. There is already existing code to construct my lower level JuMP model in PowerSimulations.jl, which I would like to leverage. Is there a way to build a JuMP model using some other existing package, and then set that as the lower level problem in the BilevelModel?

Thanks,

Devon

@dsigler1234 dsigler1234 changed the title Using Existing JuMP Model Construction Code with BiLevelJuMP Using Existing JuMP Model Construction Code with BilevelJuMP Jun 18, 2024
@joaquimg
Copy link
Owner

joaquimg commented Jul 3, 2024

I have a recommended workflow for that.

Suppose you have the following function:

function create_my_model()
    # initialize the JuMP model
    model = Model()
    # append data to model
    @variable(model, ...
    @constraint(model, ...
    @objective(model, ...
    return model
end

You can split this in two function (PowerModels work this way, you just have to find the right functions, HydroPowerModels.jl does it):

function init_model()
    # initialize the JuMP model
    model = Model()
    return model
end

function build_model!(model)
    # append data to model
    @variable(model, ...
    @constraint(model, ...
    @objective(model, ...
    return model
end

function create_my_model()
    # initialize the JuMP model
    model = init_model()
    build_model!(model)
    return model
end

Now you can re-use the build_model!(model) function:

function create_my_bilevel_model()
    model = BilevelModel()
    # now pass just the lower level model as `Lower(model)`
    # this will add all variables and constraints to the lower part of the model
    build_model!(Lower(model))
    # do something else for the upper...
    ...
    return model
end

Again, this is possible in PowerModels and is already done for multi-stages (not bilevel) models in HydroPowerModels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants