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

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.206493189864757

optionally, 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+01

moreover, obtain the business plan as DataFrame

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.010.01666.3752369.52337.410.03036.930.0
32-5.02822e50.05568.010.01666.3752369.52337.410.03036.930.0
43-5.53678e50.05568.010.01666.3752369.52337.410.03036.930.0
54-6.03053e50.05568.010.01666.3752369.52337.410.03036.930.0
65-6.50989e50.05568.010.01666.3752369.52337.410.03036.930.0
76-6.9753e50.05568.010.01666.3752369.52337.410.03036.930.0
87-7.42714e50.05568.010.01666.3752369.52337.410.03036.930.0
98-7.86583e50.05568.010.01666.3752369.52337.410.03036.930.0
109-8.29174e50.05568.010.01666.3752369.52337.410.03036.930.0
1110-8.7178e50.05568.010.01666.3752369.52337.411686.683036.930.0
1211-9.11926e50.05568.010.01666.3752369.52337.410.03036.930.0
1312-9.50903e50.05568.010.01666.3752369.52337.410.03036.930.0
1413-9.88744e50.05568.010.01666.3752369.52337.410.03036.930.0
1514-1.02548e60.05568.010.01666.3752369.52337.410.03036.930.0
1615-1.06332e60.05568.010.01666.3752369.52337.413373.363036.930.0
1716-1.09795e60.05568.010.01666.3752369.52337.410.03036.930.0
1817-1.13157e60.05568.010.01666.3752369.52337.410.03036.930.0
1918-1.16421e60.05568.010.01666.3752369.52337.410.03036.930.0
2019-1.1959e60.05568.010.01666.3752369.52337.410.03036.930.0
2120-1.20649e60.05568.010.01666.3752369.52337.410.03036.9336447.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.2227418941433679

Aggregated 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.2142113113248871

Comparison 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.2142113113248871

As 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,
)
Example block output

This page was generated using Literate.jl.