Skip to content

Commit 383f16b

Browse files
committed
mga added
1 parent 14d3bcb commit 383f16b

File tree

11 files changed

+570
-39
lines changed

11 files changed

+570
-39
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1515
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
1616
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
1717
PrettyPrinting = "54e16d92-306c-5ea0-a30b-337be88ac337"
18+
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
1819
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
1920
SankeyMakie = "1323c716-dab9-4207-0457-9cc5295a221b"
2021
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
@@ -33,6 +34,7 @@ JSON = "0.21.4"
3334
JuMP = "1.24.0"
3435
LoggingExtras = "1.2.0"
3536
PrettyPrinting = "0.4.2"
37+
PrettyTables = "3.1.2"
3638
Revise = "3.8.0"
3739
SankeyMakie = "0.1.1"
3840
StatsPlots = "0.15.7"

examples/House/config.json

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
{
2+
"_comment1": "House Model",
3+
"_comment2": "The parser will ignore any key that starts with '_comment', such as this one.",
4+
"_comment3": "",
5+
"units": {
6+
"_comment": "Each entity must have 'input', 'output' and 'scale' keys.",
7+
"power":{"input": "kW", "scale": 1, "output": "kW"},
8+
"energy": {"input": "kWh", "scale": 1, "output": "kWh"},
9+
"co2_emissions": {"input": "kg", "scale": 1, "output": "kg"},
10+
"cost_energy": {"input": "EUR/kWh", "scale": 1, "output": "EUR/kWh"},
11+
"cost_power": {"input": "EUR/kW", "scale": 1, "output": "EUR/kW"},
12+
"co2_spec": {"input": "kg/kWh", "scale": 1, "output": "kg/kWh"},
13+
"money": {"input": "EUR", "scale": 1, "output": "EUR"}
14+
},
15+
"parameters": {
16+
"_comment1": "This dictionary contains the definition of parameters. The 'type' and 'sets' keys are mandatory in all parameter definitions.",
17+
"_comment2": "The value of the 'type' key must be an integer, float, boolean or string.",
18+
"_comment3": "A parameter can have either a 'value' or a 'default' key, but not both at the same time.",
19+
"_comment4": "The value of the 'sets' key could be [],['Y'],['C'],['P'],['P','Y'],['P','T']. Replace the surrounding quotes with double quotes.",
20+
"_comment5": "If 'sets' is equal to [] or ['Y'] then the 'value' must be defined here in the definition of the parameter.",
21+
"discount_rate": {
22+
"type": "Float",
23+
"sets": [],
24+
"value": 0.05
25+
},
26+
"dt": {
27+
"type": "Integer",
28+
"sets": [],
29+
"value": 1
30+
},
31+
"annual_co2_limit": {
32+
"type": "Float",
33+
"sets": ["Y"],
34+
"unit": "co2_emissions",
35+
"value": 0
36+
},
37+
"co2_price": {
38+
"type": "Float",
39+
"sets": ["Y"],
40+
"unit": "money",
41+
"value": 0
42+
},
43+
"is_storage": {
44+
"type": "Boolean",
45+
"sets": ["P"],
46+
"default": false
47+
},
48+
"charge_efficiency": {
49+
"type": "Float",
50+
"sets": ["P"],
51+
"default": 1
52+
},
53+
"c_rate": {
54+
"type": "Float",
55+
"sets": ["P"]
56+
},
57+
"max_legacy_capacity": {
58+
"type": "Float",
59+
"sets": ["P","Y"],
60+
"unit": "power",
61+
"default": 0
62+
},
63+
"min_legacy_capacity": {
64+
"type": "Float",
65+
"sets": ["P","Y"],
66+
"unit": "power"
67+
},
68+
"max_capacity": {
69+
"type": "Float",
70+
"sets": ["P","Y"],
71+
"unit": "power"
72+
},
73+
"min_capacity": {
74+
"type": "Float",
75+
"sets": ["P","Y"],
76+
"unit": "power"
77+
},
78+
"operational_cost_energy": {
79+
"type": "Float",
80+
"sets": ["P","Y"],
81+
"unit": "cost_energy",
82+
"default": 0
83+
},
84+
"operational_cost_power": {
85+
"type": "Float",
86+
"sets": ["P","Y"],
87+
"unit": "cost_power",
88+
"default": 0
89+
},
90+
"capital_cost_power": {
91+
"type": "Float",
92+
"sets": ["P","Y"],
93+
"unit": "cost_power",
94+
"default": 0
95+
},
96+
"min_fraction_in": {
97+
"type": "Float",
98+
"sets": ["P","Y"]
99+
},
100+
"min_fraction_out": {
101+
"type": "Float",
102+
"sets": ["P","Y"]
103+
},
104+
"max_fraction_in": {
105+
"type": "Float",
106+
"sets": ["P","Y"]
107+
},
108+
"max_fraction_out": {
109+
"type": "Float",
110+
"sets": ["P","Y"]
111+
},
112+
"max_energy_out": {
113+
"type": "Float",
114+
"sets": ["P","Y"],
115+
"unit": "energy"
116+
},
117+
"min_energy_out": {
118+
"type": "Float",
119+
"sets": ["P","Y"],
120+
"unit": "energy"
121+
},
122+
"availability_profile": {
123+
"type": "Float",
124+
"sets": ["P","T"],
125+
"normalized": false
126+
},
127+
"output_profile": {
128+
"type": "Float",
129+
"sets": ["P","T"],
130+
"normalized": true
131+
},
132+
"lifetime": {
133+
"type": "Integer",
134+
"sets": ["P"],
135+
"default": 100
136+
},
137+
"technical_availability": {
138+
"type": "Float",
139+
"sets": ["P"],
140+
"default": 1
141+
},
142+
"specific_co2": {
143+
"type": "Float",
144+
"sets": ["P"],
145+
"default": 0,
146+
"unit": "co2_spec"
147+
},
148+
"efficiency": {
149+
"type": "Float",
150+
"sets": ["P"],
151+
"default": 1
152+
},
153+
"carrier_color": {
154+
"_comment": "https://juliagraphics.github.io/Colors.jl/dev/namedcolors/",
155+
"type": "String",
156+
"sets": ["C"]
157+
},
158+
"carrier_order": {
159+
"_comment": "Order of plotting: The lowest order appears in the lowest position.",
160+
"type": "Integer",
161+
"sets": ["C"]
162+
},
163+
"process_color": {
164+
"_comment": "https://juliagraphics.github.io/Colors.jl/dev/namedcolors/",
165+
"type": "String",
166+
"sets": ["P"]
167+
},
168+
"process_order": {
169+
"_comment": "Order of plotting: The lowest order appears in the lowest position.",
170+
"type": "Integer",
171+
"sets": ["P"]
172+
},
173+
"tags": {
174+
"type": "StringArray",
175+
"sets": ["P"],
176+
"default": []
177+
}
178+
},
179+
"timesteps" : "./time_series/8_weeks_Manual.txt",
180+
"years" : [2015, 2020, 2025, 2030, 2035, 2040, 2045, 2050, 2055, 2060],
181+
"carriers": {
182+
"Dummy": {},
183+
"Vehicles_Propulsion": {
184+
"carrier_color": "tomato1"
185+
},
186+
"Electricity": {
187+
"carrier_color": "orange"
188+
}
189+
},
190+
"processes": {
191+
"Import_Electricity": {
192+
"carrier_in": "Dummy",
193+
"carrier_out": "Electricity",
194+
"operational_cost_energy": 0.50,
195+
"process_color": "lightcyan",
196+
"process_order": 1,
197+
"tags": ["import", "grid"]
198+
},
199+
"Demand_Electricity": {
200+
"carrier_in": "Electricity",
201+
"carrier_out": "Dummy",
202+
"min_energy_out": 2500,
203+
"output_profile": "./time_series/Electricity_Demand_Corrected.txt",
204+
"process_color": "magenta1",
205+
"process_order": 301,
206+
"tags": ["demand", "fixed"]
207+
},
208+
"PP_PV": {
209+
"carrier_in": "Dummy",
210+
"carrier_out": "Electricity",
211+
"lifetime": 20,
212+
"operational_cost_power": 15,
213+
"capital_cost_power": 1200,
214+
"availability_profile": "./time_series/PV_availability_rescaled.txt",
215+
"process_color": "darkgoldenrod1",
216+
"process_order": 406,
217+
"tags": ["renewable", "solar", "variable"]
218+
},
219+
"PP_Wind": {
220+
"carrier_in": "Dummy",
221+
"carrier_out": "Electricity",
222+
"lifetime": 25,
223+
"operational_cost_power": 20,
224+
"capital_cost_power": 3500,
225+
"availability_profile": "./time_series/Onshore_Wind_Availability_rescaled.txt",
226+
"process_color": "royalblue1",
227+
"process_order": 409,
228+
"tags": ["renewable", "wind", "variable"]
229+
},
230+
"Battery": {
231+
"_comment": "energy storage capacity of the battery is equal to the capacity of the conversion process(max power in and out) divided by c_rate",
232+
"carrier_in": "Electricity",
233+
"carrier_out": "Electricity",
234+
"lifetime": 15,
235+
"capital_cost_power": 2000,
236+
"is_storage": true,
237+
"c_rate": 0.3,
238+
"process_color": "green2",
239+
"process_order": 1001,
240+
"tags": ["storage", "electrical"]
241+
}
242+
}
243+
}

main.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ using JuMP
3838

3939
include("./src/core/CESM.jl")
4040
using .CESM
41-
input = CESM.Parser.parse_input("./examples/House/House_PV_Wind_1_week.json");
41+
input = CESM.Parser.parse_input("./examples/House/config.json");
42+
for p in input.processes
43+
tags = CESM.Model.get_parameter(input, "tags", (p,))
44+
println("Process: $(p.name), Tags: $tags")
45+
end
4246
# input = CESM.Parser.parse_input("./examples/House/House.json");
4347
# input = CESM.Parser.parse_input("./examples/House_PV_Battery/config.json");
4448
# input = CESM.Parser.parse_input("./examples/Germany/GETM.json");

mga_house.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# 1. Include the necessary modules
2+
include("./src/core/CESM.jl")
3+
include("./src/mga/MGA.jl")
4+
using PrettyTables
5+
6+
# 2. Exploration Parameters
7+
config_path = "./examples/House/config.json"
8+
output_dir = "results/mga_house"
9+
epsilon = 0.05
10+
11+
println("--- Starting MGA Min/Max Exploration ---")
12+
println("Model: House")
13+
println("Slack (epsilon): $(epsilon * 100)%")
14+
println("Output Directory: $output_dir")
15+
16+
# 3. Parse the House input
17+
input = CESM.Parser.parse_input(config_path)
18+
19+
# 4. Run the Min/Max method
20+
# This function handles: solve optimal -> add slack constraint -> min/max all objectives
21+
MGA.run_min_max_mga(input; epsilon=epsilon, output_dir=output_dir)
22+
23+
println("--- MGA Exploration Complete ---")
24+
25+
println("\n--- Analyzing Results ---")
26+
results_summary = MGA.analyze_mga_results(input, output_dir)
27+
28+
# 6. Print a summary table using PrettyTables
29+
case_names = sort(collect(keys(results_summary)))
30+
metric_names = sort(collect(keys(MGA.MGA_OBJECTIVE_DEFS)))
31+
32+
# Construct data matrix: rows are cases, columns are metrics
33+
data = [round(results_summary[c][m], digits=2) for c in case_names, m in metric_names]
34+
35+
# Print the table
36+
# We use column_labels as seen in your documentation example
37+
pretty_table(
38+
data;
39+
column_labels = metric_names,
40+
row_labels = case_names,
41+
alignment = :c,
42+
hlines = :all,
43+
crop = :none
44+
)
45+
46+
println("\nYou can find the .jls results in the '$output_dir' folder.")

src/core/parser.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type_dict = Dict(
1818
"Integer" => Int,
1919
"Boolean" => Bool,
2020
"String" => String,
21+
"StringArray" => Vector{String}
2122
)
2223

2324

src/mga/MGA.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module MGA
2+
3+
include("core.jl")
4+
include("functions.jl")
5+
include("min_max.jl")
6+
include("analysis.jl")
7+
8+
using .MGACore
9+
using .MGAFunctions
10+
using .MinMaxMGA
11+
using .MGAAnalysis
12+
13+
export solve_optimal, add_slack_constraint
14+
export MGA_OBJECTIVE_DEFS
15+
export run_min_max_mga, analyze_mga_results
16+
17+
end

0 commit comments

Comments
 (0)