输出存储容量取整。
This commit is contained in:
@@ -620,9 +620,44 @@ def optimize_storage_capacity(
|
|||||||
if iter_num % 10 == 0 and iter_num > 0:
|
if iter_num % 10 == 0 and iter_num > 0:
|
||||||
print(f" 已完成 {iter_num} 次迭代,当前搜索区间: [{a:.2f}, {b:.2f}] MWh")
|
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")
|
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_generation = sum(thermal_output) + sum(wind_output) + sum(solar_output)
|
||||||
total_consumption = sum(load_demand)
|
total_consumption = sum(load_demand)
|
||||||
|
|||||||
Reference in New Issue
Block a user