Input/Ouput to/from disk

This example showcase the input/output capabilities of the EnergyCommunity.jl package on writing and reading the model and outputs to/from disk. EnergyCommunity.jl supports:

  • Input from yaml files defining the structure of the energy community
  • Output of summaries and plots to files
  • Saving and loading the model to/from jld2 files, so that any intermediate results can be stored and retrieved later on without the need to re-optimize the model.

In the example below, we consider a Cooperative (CO) energy community optimization problem and showcase the opportunities related to input/output operations; for plotting, see the other example.

Initialization of the model

Import the needed packages

using EnergyCommunity, JuMP
using HiGHS, FileIO

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

output_file_isolated = joinpath(@__DIR__, "./results/output_file_CO.xlsx");

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

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

Save summaries

save_summary(CO_Model, output_file_isolated)

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

Save the model to disk

save the model to a jld2 file, to store the whole object

save("co_model.jld2", CO_Model)

Load the model from disk

read the loaded model from the jld2 file

CO_Model_loaded = load!("co_model.jld2", ModelEC())
An Energy Community Model
Energy Community problem for a Cooperative Model
User set: ["user1", "user2", "user3"]

get the objective value of the loaded model

objective_value(CO_Model_loaded)
-1.206493189864757e6

compare the objective values of the two models

objective_value(CO_Model) == objective_value(CO_Model_loaded)
true

This page was generated using Literate.jl.