Optimizing different configurations
This example aims to shocase the use of EnergyCommunity.jl to optimize the different configurations of energy communities supported by the tool, namely:
- Non Cooperative (NC)
- Aggregated Non Cooperative (ANC)
- Cooperative (CO)
The energy community considered in this example consists of 3 users, where:
- all users can install PV system
- only the first user cannot install batteries, whereas the others can
- the third user can install also wind turbines
The example is based on a subset of users taken from the following article, yet for a subset of users.
D. Fioriti, A. Frangioni, D. Poli, "Optimal sizing of energy communities with fair revenue sharing and exit clauses: Value, role and business model of aggregators and users," in Applied Energy, vol. 299, 2021, 117328,doi: 10.1016/j.apenergy.2021.117328
Cooperative (CO)
Initialization
Import the needed packages
using EnergyCommunity, JuMP
using HiGHS, PlotsCreate a base Energy Community example in the data folder; use the default configuration.
folder = joinpath(@__DIR__, "data")
create_example_data(folder, config_name="default")Input file to load the structure of the energy community based on a yaml file.
input_file = joinpath(@__DIR__, "data/energy_community_model.yml");define optimizer and options
optimizer = optimizer_with_attributes(HiGHS.Optimizer, "ipm_optimality_tolerance"=>1e-6)MathOptInterface.OptimizerWithAttributes(HiGHS.Optimizer, Pair{MathOptInterface.AbstractOptimizerAttribute, Any}[MathOptInterface.RawOptimizerAttribute("ipm_optimality_tolerance") => 1.0e-6])Create, build and optimize the model
Define the Cooperative model
CO_Model = ModelEC(input_file, EnergyCommunity.GroupCO(), optimizer)An Energy Community Model
Energy Community problem for a Cooperative Model
User set: ["user1", "user2", "user3"]
Build the mathematical model
build_model!(CO_Model)An Energy Community Model
Energy Community problem for a Cooperative Model
User set: ["user1", "user2", "user3"]
Optimize the model
optimize!(CO_Model)An Energy Community Model
Energy Community problem for a Cooperative Model
User set: ["user1", "user2", "user3"]
Results
get objective value in M€
obj_CO = objective_value(CO_Model)/1e6
obj_CO-1.206493189864757optionally, print summary of the results
print_summary(CO_Model)[ Info: List of users not specified: all users selected
WARNING: Optimizer of the EnergyCommunity model not specified
RESULTS - AGGREGATOR
NPV Agg [k€] : 0.00e+00
SWtot [k€] : -1.21e+03
SWus [k€] : -1.21e+03
ESha [MWh] : 3.70e+00
RESULTS - USER
USER : user1, user2, user3
PV : 4.08e+01, 4.67e+01, 2.27e+01
batt : 0.00e+00, 3.33e+00, 5.10e+00
conv : 0.00e+00, 3.33e+00, 5.10e+00
wind : 0.00e+00, 0.00e+00, 7.35e+01
NPV [k€] : -5.71e+02, -2.30e+02, -4.51e+02
CAPEX [k€] : 6.94e+01, 6.73e+01, 2.60e+02
OPEX [k€] : 1.22e+00, 1.42e+00, 2.92e+00
YBill [k€] : -3.30e+01, -1.07e+01, -1.26e+01
Cboiler [k€] : 0.00e+00, 0.00e+00, 0.00e+00
Cpumps [k€] : 0.00e+00, 0.00e+00, 0.00e+00
Energy flows
USER : user1, user2, user3
PtotPusP [MWh] : 3.31e-01, 5.05e+00, 2.45e+00
PtotPusN [MWh] : 2.24e+01, 7.70e+00, 5.63e+00
PconvP [MWh] : 0.00e+00, 2.76e-01, 3.68e-01
PconvN [MWh] : 0.00e+00, 3.00e-01, 4.00e-01
Pren [MWh] : 8.46e+00, 9.54e+00, 2.13e+01
Pgen [MWh] : 0.00e+00, 0.00e+00, 0.00e+00
Load [MWh] : 3.05e+01, 1.22e+01, 2.45e+01moreover, obtain the business plan as DataFrame
business_plan(CO_Model)| Row | Year | CUM_DCF | CAPEX | OEM | FUEL | EN_SELL | EN_CONS | PEAK | REP | REWARD | RV |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Int64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
| 1 | 0 | -3.96488e5 | 3.96488e5 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| 2 | 1 | -4.50441e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 3 | 2 | -5.02822e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 4 | 3 | -5.53678e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 5 | 4 | -6.03053e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 6 | 5 | -6.50989e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 7 | 6 | -6.9753e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 8 | 7 | -7.42714e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 9 | 8 | -7.86583e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 10 | 9 | -8.29174e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 11 | 10 | -8.7178e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 1686.68 | 3036.93 | 0.0 |
| 12 | 11 | -9.11926e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 13 | 12 | -9.50903e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 14 | 13 | -9.88744e5 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 15 | 14 | -1.02548e6 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 16 | 15 | -1.06332e6 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 3373.36 | 3036.93 | 0.0 |
| 17 | 16 | -1.09795e6 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 18 | 17 | -1.13157e6 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 19 | 18 | -1.16421e6 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 20 | 19 | -1.1959e6 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 0.0 |
| 21 | 20 | -1.20649e6 | 0.0 | 5568.01 | 0.0 | 1666.37 | 52369.5 | 2337.41 | 0.0 | 3036.93 | 36447.2 |
Non Cooperative (NC)
Initialization
Given that the initialization is the same as for the CO model, we can reuse the input file and the optimizer defined above. So we can directly move to the model creation.
Create, build and optimize the model
Define the Non Cooperative model
NC_Model = ModelEC(input_file, EnergyCommunity.GroupNC(), optimizer)An Energy Community Model
Energy Community problem for a Non-Cooperative Model
User set: ["user1", "user2", "user3"]
Build the mathematical model
build_model!(NC_Model)An Energy Community Model
Energy Community problem for a Non-Cooperative Model
User set: ["user1", "user2", "user3"]
Optimize the model
optimize!(NC_Model)An Energy Community Model
Energy Community problem for a Non-Cooperative Model
User set: ["user1", "user2", "user3"]
Results
get objective value in M€
obj_NC = objective_value(NC_Model)/1e6
obj_NC-1.2227418941433679Aggregated Non Cooperative (ANC)
Initialization
Given that the initialization is the same as for the CO model, we can reuse the input file and the optimizer defined above. So we can directly move to the model creation. In this case, we showcase a different approach to define the ANC model by passing directly the configuration name to the ModelEC constructor.
Create, build and optimize the model
Define the Aggregated Non Cooperative model
ANC_Model = ModelEC(CO_Model, GroupANC())An Energy Community Model
Energy Community problem for a Aggregating-Non-Cooperative Model
User set: ["user1", "user2", "user3"]
Build the mathematical model
build_model!(ANC_Model)An Energy Community Model
Energy Community problem for a Aggregating-Non-Cooperative Model
User set: ["user1", "user2", "user3"]
Optimize the model
optimize!(ANC_Model)An Energy Community Model
Energy Community problem for a Aggregating-Non-Cooperative Model
User set: ["user1", "user2", "user3"]
Results
get objective value in M€
obj_ANC = objective_value(ANC_Model)/1e6
obj_ANC-1.2142113113248871Comparison of the results
Finally, we can compare the results obtained from the three different configurations of energy communities.
println("Objective value CO Model [M€]: ", obj_CO)
println("Objective value NC Model [M€]: ", obj_NC)
println("Objective value ANC Model [M€]: ", obj_ANC)Objective value CO Model [M€]: -1.206493189864757
Objective value NC Model [M€]: -1.2227418941433679
Objective value ANC Model [M€]: -1.2142113113248871As expected, the Cooperative model provides the best objective value, followed by the Aggregated Non Cooperative model, and finally the Non Cooperative model. This showcases the benefits of cooperation within energy communities. We can do that also with a plot:
bar(
["CO Model", "ANC Model", "NC Model"],
[obj_CO, obj_ANC, obj_NC],
title="Comparison of Objective Values",
ylabel="Objective Value [M€]",
ylims=[-1.3, -1.1],
legend=false,
)This page was generated using Literate.jl.