For context, the model linked above is a heat pump h which consumes a certain electrical power P_t^{(h)} at each timestep t.
Now I also have an electricity grid model defined in JuMP, which consists of buses and lines. I want to add a heat pump to each bus, electrically this is simple but I am not sure how to do it in JuMP.
I guess this comment JuMP Multiple Models Design Question - #2 by odow would be the right way to include the submodels in the larger model? It’s an older comment so I am not sure it still applies.
I read that, but I cannot make the connection from the knapsack example to my problem. There is a lot happening in that tutorial I can’t figure out which part of it I need.
Okay that’s disappointing, I thought I could just add one model to the other. That would save me a lot of time and rewriting there should be a level of modularity possible here I think.
Seems like the main task now is to rewrite the heat pump model into functions that add the constraints, variables and objectives separately to the ‘main’ electrical model?
Don’t build subcomponents as JuMP models. Build them as function which add components to an existing JuMP model, and use either a naming convention, or an external data structure to manage the relevant variables and connections between components.
If you’re building an energy system model, take a look at the design of PowerSimulations.jl, and read through (and watch the videos) of Open Energy Modeling at JuMP-dev | JuMP
Note that its a different design choice. But Pyomos approach is not obviously better. There are a number of trade offs to consider. JuMPs approach is different but people have demonstrated you can easily build large and highly flexible models with it.