naohiro701 commited on
Commit
ebece77
·
verified ·
1 Parent(s): 6191222

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -19
app.py CHANGED
@@ -128,7 +128,8 @@ def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wi
128
  'type': 'min',
129
  'technology': tech,
130
  'solution': {g: renewable_capacity[('region1', g)].varValue for g in technologies},
131
- 'battery_capacity': battery_capacity.varValue
 
132
  })
133
 
134
  # Maximize capacity of each technology
@@ -149,7 +150,8 @@ def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wi
149
  'type': 'max',
150
  'technology': tech,
151
  'solution': {g: renewable_capacity[('region1', g)].varValue for g in technologies},
152
- 'battery_capacity': battery_capacity.varValue
 
153
  })
154
 
155
  return alternative_solutions
@@ -182,28 +184,47 @@ if st.button("Run MGA Optimization"):
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
- # 各しきい値ごとの最小と最大のバッテリー容量を収集
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  epsilon_values = sorted(list(set(sol['threshold'] * 100 for sol in alternative_solutions)))
187
- storage_min = []
188
- storage_max = []
189
-
190
- for epsilon in epsilon_values:
191
- capacities = [sol['battery_capacity'] for sol in alternative_solutions if sol['threshold'] * 100 == epsilon]
192
- storage_min.append(min(capacities))
193
- storage_max.append(max(capacities))
194
-
195
- # 可視化
196
  fig, ax = plt.subplots()
197
- ax.fill_between(epsilon_values, storage_min, storage_max, color='orange', alpha=0.3) # オレンジ色の塗りつぶし
198
- ax.plot(epsilon_values, storage_min, marker='o', color='orange', linestyle='-', linewidth=1.5, label='Min Storage') # 最小値ライン
199
- ax.plot(epsilon_values, storage_max, marker='o', color='orange', linestyle='-', linewidth=1.5, label='Max Storage') # 最大値ライン
200
-
 
 
 
 
 
 
 
 
 
 
201
  # ラベルとタイトル
202
  ax.set_xlabel(r'$\epsilon$ [%]')
203
- ax.set_ylabel('Storage [GW]')
204
- ax.set_title('GHG -100%')
205
  ax.legend()
206
  ax.grid(True, linestyle='--', alpha=0.7)
207
-
208
  # Streamlitにプロットを表示
209
  st.pyplot(fig)
 
128
  'type': 'min',
129
  'technology': tech,
130
  'solution': {g: renewable_capacity[('region1', g)].varValue for g in technologies},
131
+ 'battery_capacity': battery_capacity.varValue,
132
+ 'total_cost': pulp.value(alt_model_min.objective)
133
  })
134
 
135
  # Maximize capacity of each technology
 
150
  'type': 'max',
151
  'technology': tech,
152
  'solution': {g: renewable_capacity[('region1', g)].varValue for g in technologies},
153
+ 'battery_capacity': battery_capacity.varValue,
154
+ 'total_cost': pulp.value(alt_model_max.objective)
155
  })
156
 
157
  return alternative_solutions
 
184
  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)
185
 
186
  if alternative_solutions:
187
+ # コスト積み上げ用データの収集
188
+ cost_data = []
189
+ for sol in alternative_solutions:
190
+ cost_data.append({
191
+ 'threshold': sol['threshold'] * 100,
192
+ 'type': sol['type'],
193
+ 'technology': sol['technology'],
194
+ 'total_cost': sol['total_cost']
195
+ })
196
+
197
+ # コスト積み上げグラフのプロット
198
+ cost_df = pd.DataFrame(cost_data)
199
+ fig_cost = px.bar(cost_df, x='threshold', y='total_cost', color='technology', title="Cost Breakdown by Technology and Threshold")
200
+ fig_cost.update_layout(xaxis_title='Threshold (%)', yaxis_title='Total Cost (¥)')
201
+
202
+ # Streamlitでコスト積み上げグラフを表示
203
+ st.plotly_chart(fig_cost, use_container_width=True)
204
+
205
+ # 各しきい値ごとの技術ごとの容量の範囲を表示
206
  epsilon_values = sorted(list(set(sol['threshold'] * 100 for sol in alternative_solutions)))
 
 
 
 
 
 
 
 
 
207
  fig, ax = plt.subplots()
208
+
209
+ for tech in selected_technologies:
210
+ storage_min = []
211
+ storage_max = []
212
+ for epsilon in epsilon_values:
213
+ capacities = [sol['solution'][tech] for sol in alternative_solutions if sol['technology'] == tech and sol['threshold'] * 100 == epsilon]
214
+ storage_min.append(min(capacities))
215
+ storage_max.append(max(capacities))
216
+
217
+ # 塗りつぶし範囲とラインプロット
218
+ ax.fill_between(epsilon_values, storage_min, storage_max, alpha=0.3, label=f"{tech} range")
219
+ ax.plot(epsilon_values, storage_min, marker='o', linestyle='-', label=f"{tech} Min")
220
+ ax.plot(epsilon_values, storage_max, marker='o', linestyle='-', label=f"{tech} Max")
221
+
222
  # ラベルとタイトル
223
  ax.set_xlabel(r'$\epsilon$ [%]')
224
+ ax.set_ylabel('Capacity [GW]')
225
+ ax.set_title('Capacity Ranges for Each Technology')
226
  ax.legend()
227
  ax.grid(True, linestyle='--', alpha=0.7)
228
+
229
  # Streamlitにプロットを表示
230
  st.pyplot(fig)