考虑了储能上限。
This commit is contained in:
@@ -22,6 +22,7 @@ class SystemParameters:
|
||||
storage_efficiency: float = 0.9 # 储能充放电效率 (0.0-1.0)
|
||||
discharge_rate: float = 1.0 # 储能放电倍率 (C-rate)
|
||||
charge_rate: float = 1.0 # 储能充电倍率 (C-rate)
|
||||
max_storage_capacity: Optional[float] = None # 储能容量上限 (MWh),None表示无限制
|
||||
|
||||
|
||||
def validate_inputs(
|
||||
@@ -75,6 +76,8 @@ def validate_inputs(
|
||||
raise ValueError("储能效率必须在0.0-1.0之间")
|
||||
if params.discharge_rate <= 0 or params.charge_rate <= 0:
|
||||
raise ValueError("充放电倍率必须大于0")
|
||||
if params.max_storage_capacity is not None and params.max_storage_capacity <= 0:
|
||||
raise ValueError("储能容量上限必须大于0")
|
||||
|
||||
|
||||
def calculate_energy_balance(
|
||||
@@ -293,11 +296,18 @@ def optimize_storage_capacity(
|
||||
|
||||
# 初始化搜索范围
|
||||
lower_bound = 0.0
|
||||
upper_bound = max(sum(solar_output) + sum(wind_output) + sum(thermal_output), sum(load_demand))
|
||||
theoretical_max = max(sum(solar_output) + sum(wind_output) + sum(thermal_output), sum(load_demand))
|
||||
|
||||
# 应用储能容量上限限制
|
||||
if params.max_storage_capacity is not None:
|
||||
upper_bound = min(theoretical_max, params.max_storage_capacity)
|
||||
else:
|
||||
upper_bound = theoretical_max
|
||||
|
||||
# 二分搜索寻找最小储能容量
|
||||
best_capacity = upper_bound
|
||||
best_result = None
|
||||
solution_found = False # 标记是否找到可行解
|
||||
|
||||
for iteration in range(max_iterations):
|
||||
mid_capacity = (lower_bound + upper_bound) / 2
|
||||
@@ -326,6 +336,7 @@ def optimize_storage_capacity(
|
||||
# 满足条件,尝试减小容量
|
||||
best_capacity = mid_capacity
|
||||
best_result = {**balance_result, **constraint_results}
|
||||
solution_found = True
|
||||
upper_bound = mid_capacity
|
||||
else:
|
||||
# 不满足条件,增大容量
|
||||
@@ -335,8 +346,20 @@ def optimize_storage_capacity(
|
||||
if upper_bound - lower_bound < tolerance:
|
||||
break
|
||||
|
||||
# 如果没有找到可行解,使用最大容量
|
||||
if best_result is None:
|
||||
# 处理储能容量上限限制的情况
|
||||
if not solution_found and params.max_storage_capacity is not None:
|
||||
print(f"警告:在储能容量上限 {params.max_storage_capacity:.2f} MWh 内无法找到满足所有约束的解")
|
||||
print("使用最大允许容量进行计算,但某些约束条件可能无法满足")
|
||||
|
||||
# 使用最大允许容量计算结果
|
||||
balance_result = calculate_energy_balance(
|
||||
solar_output, wind_output, thermal_output, load_demand, params, params.max_storage_capacity
|
||||
)
|
||||
constraint_results = check_constraints(solar_output, wind_output, thermal_output, balance_result, params)
|
||||
best_result = {**balance_result, **constraint_results}
|
||||
best_capacity = params.max_storage_capacity
|
||||
elif best_result is None:
|
||||
# 如果没有找到可行解(且没有容量上限限制),使用最大容量
|
||||
balance_result = calculate_energy_balance(
|
||||
solar_output, wind_output, thermal_output, load_demand, params, upper_bound
|
||||
)
|
||||
@@ -380,7 +403,10 @@ def optimize_storage_capacity(
|
||||
'total_curtailment_wind_ratio': best_result['total_curtailment_wind_ratio'],
|
||||
'total_curtailment_solar_ratio': best_result['total_curtailment_solar_ratio'],
|
||||
'total_grid_feed_in_ratio': best_result['total_grid_feed_in_ratio'],
|
||||
'energy_balance_check': energy_balance_check
|
||||
'energy_balance_check': energy_balance_check,
|
||||
'capacity_limit_reached': params.max_storage_capacity is not None and best_capacity >= params.max_storage_capacity,
|
||||
'theoretical_optimal_capacity': best_capacity if solution_found else None,
|
||||
'max_storage_limit': params.max_storage_capacity
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user