From a80830e75070ae9b3d4c39295feb6eb01c6dbed3 Mon Sep 17 00:00:00 2001 From: dmy Date: Sat, 27 Dec 2025 16:53:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BE=93=E5=87=BA=E5=AD=98=E5=82=A8=E5=AE=B9?= =?UTF-8?q?=E9=87=8F=E5=8F=96=E6=95=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/storage_optimization.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/storage_optimization.py b/src/storage_optimization.py index a52b6c6..515bc05 100644 --- a/src/storage_optimization.py +++ b/src/storage_optimization.py @@ -620,9 +620,44 @@ def optimize_storage_capacity( if iter_num % 10 == 0 and iter_num > 0: print(f" 已完成 {iter_num} 次迭代,当前搜索区间: [{a:.2f}, {b:.2f}] MWh") - print(f"\n最终选择储能容量: {best_capacity:.2f} MWh (容量上限: {upper_bound:.2f} MWh)") + # 将储能容量向上取整为整数 + import math + rounded_capacity = math.ceil(best_capacity) + # 确保不超过容量上限 + if params.max_storage_capacity is not None: + rounded_capacity = min(rounded_capacity, int(params.max_storage_capacity)) + # 确保不为负数 + rounded_capacity = max(0, rounded_capacity) + + print(f"\n优化得到的储能容量: {best_capacity:.2f} MWh") + print(f"调整后储能容量(向上取整): {rounded_capacity:.0f} MWh (容量上限: {upper_bound:.2f} MWh)") print(f"最终弃电量: {best_curtailed:.2f} MWh") + # 如果调整后的容量不同,重新计算以确保结果准确 + if abs(rounded_capacity - best_capacity) > 0.1: + print(f"重新计算调整后的储能容量结果...") + if is_yearly_data: + adjusted_result = find_periodic_steady_state( + solar_output, wind_output, thermal_output, load_demand, + params, rounded_capacity + ) + else: + adjusted_result = calculate_energy_balance( + solar_output, wind_output, thermal_output, load_demand, params, rounded_capacity + ) + + # 检查约束条件 + adjusted_constraint_results = check_constraints(solar_output, wind_output, thermal_output, adjusted_result, params) + + # 更新结果 + best_result = {**adjusted_result, **adjusted_constraint_results} + best_capacity = rounded_capacity + best_curtailed = sum(adjusted_result['curtailed_wind']) + sum(adjusted_result['curtailed_solar']) + + print(f"调整后的弃电量: {best_curtailed:.2f} MWh") + else: + best_capacity = rounded_capacity + # 添加能量平衡校验 total_generation = sum(thermal_output) + sum(wind_output) + sum(solar_output) total_consumption = sum(load_demand)