Cooperative Energy Community

This example is taken from the article Optimal sizing of energy communities with fair revenue sharing and exit clauses: Value, role and business model of aggregators and users by Davide Fioriti et al, url but for a subset of users

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

Import the needed packages

using EnergyCommunity, JuMP
using HiGHS, Plots

Create 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");

Output path of the summary and of the plots

output_file_isolated = joinpath(@__DIR__, "./results/output_file_CO.xlsx");
output_plot_isolated = joinpath(@__DIR__, "./results/Img/plot_user_{:s}_CO.png");

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])

Define the Non 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"]

get objective value

objective_value(CO_Model)
-1.2064931898647554e6

Create plots of the results

plot(CO_Model, output_plot_isolated)

Print summaries 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
generator         :  0.00e+00,  0.00e+00,  0.00e+00
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
Cthermal [k€]     :  2.41e-17,  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.78e-01,  3.65e-01
PconvN [MWh]      :  0.00e+00,  3.03e-01,  3.97e-01
Pren [MWh]        :  8.46e+00,  9.54e+00,  2.13e+01
Pgen [MWh]        :  4.29e-18,  0.00e+00,  0.00e+00
Load [MWh]        :  3.05e+01,  1.22e+01,  2.45e+01

Save summaries

save_summary(CO_Model, output_file_isolated)

Plot the sankey plot of resources

plot_sankey(CO_Model)
Example block output

DataFrame of the business plan

business_plan(CO_Model)
21×11 DataFrame
RowYearCUM_DCFCAPEXOEMFUELEN_SELLEN_CONSPEAKREPREWARDRV
Int64Float64Float64Float64Float64Float64Float64Float64Float64Float64Float64
10-3.96488e53.96488e50.00.00.00.00.00.00.00.0
21-4.50441e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
32-5.02822e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
43-5.53678e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
54-6.03053e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
65-6.50989e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
76-6.9753e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
87-7.42714e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
98-7.86583e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
109-8.29174e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
1110-8.7178e50.05568.012.41303e-141660.8252363.92337.411686.683036.930.0
1211-9.11926e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
1312-9.50903e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
1413-9.88744e50.05568.012.41303e-141660.8252363.92337.410.03036.930.0
1514-1.02548e60.05568.012.41303e-141660.8252363.92337.410.03036.930.0
1615-1.06332e60.05568.012.41303e-141660.8252363.92337.413373.363036.930.0
1716-1.09795e60.05568.012.41303e-141660.8252363.92337.410.03036.930.0
1817-1.13157e60.05568.012.41303e-141660.8252363.92337.410.03036.930.0
1918-1.16421e60.05568.012.41303e-141660.8252363.92337.410.03036.930.0
2019-1.1959e60.05568.012.41303e-141660.8252363.92337.410.03036.930.0
2120-1.20649e60.05568.012.41303e-141660.8252363.92337.410.03036.9336447.2

plot business plan

business_plan_plot(CO_Model)
Example block output

This page was generated using Literate.jl.