feat: 优化K-means簇数计算逻辑,基于风机数量与电缆型号数量
This commit is contained in:
19
main.py
19
main.py
@@ -803,19 +803,32 @@ def compare_design_methods(excel_path=None, n_clusters_override=None):
|
|||||||
total_power = turbines['power'].sum()
|
total_power = turbines['power'].sum()
|
||||||
max_cable_mw = get_max_cable_capacity_mw(cable_specs=cable_specs)
|
max_cable_mw = get_max_cable_capacity_mw(cable_specs=cable_specs)
|
||||||
|
|
||||||
|
# 获取电缆型号数量
|
||||||
|
if cable_specs is not None:
|
||||||
|
n_cable_types = len(cable_specs)
|
||||||
|
else:
|
||||||
|
# 对应 evaluate_design 中的默认电缆规格库数量
|
||||||
|
n_cable_types = 9
|
||||||
|
|
||||||
# 允许指定簇的数量,如果设置为 None 则自动计算
|
# 允许指定簇的数量,如果设置为 None 则自动计算
|
||||||
if n_clusters_override is not None:
|
if n_clusters_override is not None:
|
||||||
n_clusters = n_clusters_override
|
n_clusters = n_clusters_override
|
||||||
min_clusters_needed = int(np.ceil(total_power / max_cable_mw))
|
min_clusters_needed = int(np.ceil(total_power / max_cable_mw))
|
||||||
print(f"使用手动指定的回路数(簇数): {n_clusters} (理论最小需求 {min_clusters_needed})")
|
print(f"使用手动指定的回路数(簇数): {n_clusters} (理论最小需求 {min_clusters_needed})")
|
||||||
else:
|
else:
|
||||||
|
# 新逻辑:风机数量 / 电缆型号数量,向上取整
|
||||||
|
n_clusters = int(np.ceil(len(turbines) / n_cable_types))
|
||||||
min_clusters_needed = int(np.ceil(total_power / max_cable_mw))
|
min_clusters_needed = int(np.ceil(total_power / max_cable_mw))
|
||||||
# 增加一定的安全裕度 (1.2倍) 并确保至少有一定数量的簇
|
# 确保回路数不低于容量需求的理论最小值
|
||||||
n_clusters = max(int(min_clusters_needed * 1.2), 4)
|
if n_clusters < min_clusters_needed:
|
||||||
|
print(f"WARNING: 根据风机/型号计算的簇数({n_clusters})低于理论最小需求({min_clusters_needed}),已调整为理论最小值。")
|
||||||
|
n_clusters = min_clusters_needed
|
||||||
|
|
||||||
if len(turbines) < n_clusters: # 避免簇数多于风机数
|
if len(turbines) < n_clusters: # 避免簇数多于风机数
|
||||||
n_clusters = len(turbines)
|
n_clusters = len(turbines)
|
||||||
|
|
||||||
print(f"系统设计参数: 总功率 {total_power:.1f} MW, 单回路最大容量 {max_cable_mw:.1f} MW")
|
print(f"系统设计参数: 总功率 {total_power:.1f} MW, 单回路最大容量 {max_cable_mw:.1f} MW, 型号数量 {n_cable_types}")
|
||||||
|
print(f"K-means 簇数设定为: {n_clusters}")
|
||||||
|
|
||||||
# 替换为带容量约束的扫描算法
|
# 替换为带容量约束的扫描算法
|
||||||
kmeans_connections, clustered_turbines = design_with_capacitated_sweep(turbines.copy(), substation, cable_specs=cable_specs)
|
kmeans_connections, clustered_turbines = design_with_capacitated_sweep(turbines.copy(), substation, cable_specs=cable_specs)
|
||||||
|
|||||||
Reference in New Issue
Block a user