Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import pulp
|
|
| 5 |
import plotly.graph_objs as go
|
| 6 |
import plotly.express as px
|
| 7 |
import numpy as np
|
| 8 |
-
import matplotlib.pyplot as plt
|
| 9 |
|
| 10 |
# Renewable energy data fetch function
|
| 11 |
def get_renewable_energy_data(city_code):
|
|
@@ -29,7 +29,7 @@ def get_renewable_energy_data(city_code):
|
|
| 29 |
return result_df, None
|
| 30 |
|
| 31 |
# Optimize energy system and use MGA
|
| 32 |
-
def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand, solar_range, wind_range, river_range, offshore_wind_range, thresholds):
|
| 33 |
data, error = get_renewable_energy_data(city_code)
|
| 34 |
if error:
|
| 35 |
st.error(error)
|
|
@@ -104,12 +104,12 @@ def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wi
|
|
| 104 |
model.solve()
|
| 105 |
optimal_cost = pulp.value(model.objective)
|
| 106 |
|
| 107 |
-
# MGA: Generate alternative solutions
|
| 108 |
mga_models = []
|
| 109 |
alternative_solutions = []
|
| 110 |
for threshold in thresholds:
|
| 111 |
relaxed_cost = optimal_cost * (1 + threshold)
|
| 112 |
-
for tech in
|
| 113 |
# Minimize capacity of each technology
|
| 114 |
alt_model_min = pulp.LpProblem(f"AlternativeModel_Min_{tech}_{threshold}", pulp.LpMinimize)
|
| 115 |
alt_model_min += pulp.lpSum([renewable_capacity[(r, g)] * renewable_capacity_cost[g]
|
|
@@ -174,9 +174,12 @@ with st.sidebar:
|
|
| 174 |
river_range = st.slider("River Capacity Range (MW)", 0, 10000, (0, 10000))
|
| 175 |
thresholds = st.multiselect("Select MGA Cost Deviation Thresholds (%)", [0.5, 1, 2, 3, 5, 7.5, 10], default=[0.5, 1, 5])
|
| 176 |
|
|
|
|
|
|
|
|
|
|
| 177 |
if st.button("Run MGA Optimization"):
|
| 178 |
# 実行して alternative_solutions を取得
|
| 179 |
-
alternative_solutions = optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand, solar_range, wind_range, river_range, offshore_wind_range, [t / 100 for t in thresholds])
|
| 180 |
|
| 181 |
if alternative_solutions:
|
| 182 |
# 各しきい値ごとの最小と最大のバッテリー容量を収集
|
|
|
|
| 5 |
import plotly.graph_objs as go
|
| 6 |
import plotly.express as px
|
| 7 |
import numpy as np
|
| 8 |
+
import matplotlib.pyplot as plt
|
| 9 |
|
| 10 |
# Renewable energy data fetch function
|
| 11 |
def get_renewable_energy_data(city_code):
|
|
|
|
| 29 |
return result_df, None
|
| 30 |
|
| 31 |
# Optimize energy system and use MGA
|
| 32 |
+
def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand, solar_range, wind_range, river_range, offshore_wind_range, thresholds, selected_tech):
|
| 33 |
data, error = get_renewable_energy_data(city_code)
|
| 34 |
if error:
|
| 35 |
st.error(error)
|
|
|
|
| 104 |
model.solve()
|
| 105 |
optimal_cost = pulp.value(model.objective)
|
| 106 |
|
| 107 |
+
# MGA: Generate alternative solutions for selected technologies only
|
| 108 |
mga_models = []
|
| 109 |
alternative_solutions = []
|
| 110 |
for threshold in thresholds:
|
| 111 |
relaxed_cost = optimal_cost * (1 + threshold)
|
| 112 |
+
for tech in selected_tech: # 選択された技術のみ実行
|
| 113 |
# Minimize capacity of each technology
|
| 114 |
alt_model_min = pulp.LpProblem(f"AlternativeModel_Min_{tech}_{threshold}", pulp.LpMinimize)
|
| 115 |
alt_model_min += pulp.lpSum([renewable_capacity[(r, g)] * renewable_capacity_cost[g]
|
|
|
|
| 174 |
river_range = st.slider("River Capacity Range (MW)", 0, 10000, (0, 10000))
|
| 175 |
thresholds = st.multiselect("Select MGA Cost Deviation Thresholds (%)", [0.5, 1, 2, 3, 5, 7.5, 10], default=[0.5, 1, 5])
|
| 176 |
|
| 177 |
+
# 技術の選択オプション
|
| 178 |
+
selected_technologies = st.multiselect("Select Technologies to Optimize", ['solar', 'onshore_wind', 'offshore_wind', 'river'], default=['solar', 'onshore_wind', 'offshore_wind', 'river'])
|
| 179 |
+
|
| 180 |
if st.button("Run MGA Optimization"):
|
| 181 |
# 実行して alternative_solutions を取得
|
| 182 |
+
alternative_solutions = optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand, solar_range, wind_range, river_range, offshore_wind_range, [t / 100 for t in thresholds], selected_technologies)
|
| 183 |
|
| 184 |
if alternative_solutions:
|
| 185 |
# 各しきい値ごとの最小と最大のバッテリー容量を収集
|