"""测试优化函数是否正常工作""" import sys sys.path.append('src') from storage_optimization import optimize_storage_capacity, SystemParameters # 使用简单的24小时示例数据 solar_output = [0.0] * 6 + [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0] + [0.0] * 6 wind_output = [2.0, 3.0, 4.0, 3.0, 2.0, 1.0] * 4 thermal_output = [5.0] * 24 load_demand = [3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 18.0, 16.0, 14.0, 12.0, 10.0, 8.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 2.0] # 系统参数 params = SystemParameters( max_curtailment_wind=0.1, max_curtailment_solar=0.1, max_grid_ratio=0.2, storage_efficiency=0.9, discharge_rate=1.0, charge_rate=1.0, max_storage_capacity=200.0 # 设置储能容量上限 ) print("开始测试优化函数...") print("储能容量上限: 200.0 MWh") # 计算最优储能容量 result = optimize_storage_capacity( solar_output, wind_output, thermal_output, load_demand, params ) print("\n" + "="*50) print("测试结果:") print("="*50) print(f"result 类型: {type(result)}") print(f"result 是否为 None: {result is None}") if result is not None: print(f"所选储能容量: {result.get('required_storage_capacity', 'N/A'):.2f} MWh") print(f"总弃电量: {result.get('total_curtailed_energy', 'N/A'):.2f} MWh") print(f"弃风率: {result.get('total_curtailment_wind_ratio', 'N/A'):.3f}") print(f"弃光率: {result.get('total_curtailment_solar_ratio', 'N/A'):.3f}") print(f"储能容量上限: {result.get('max_storage_limit', 'N/A')}") print(f"优化目标: {result.get('optimization_goal', 'N/A')}") print("\n✓ 测试成功!函数返回了有效结果。") else: print("\n✗ 测试失败!函数返回了 None。")