From 2d50ab0df0b9e86b34b7ec300ec0193e4a1c33fe Mon Sep 17 00:00:00 2001 From: dmy Date: Thu, 1 Jan 2026 13:56:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96K-means=E7=B0=87?= =?UTF-8?q?=E6=95=B0=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91=EF=BC=8C=E5=9F=BA?= =?UTF-8?q?=E4=BA=8E=E9=A3=8E=E6=9C=BA=E6=95=B0=E9=87=8F=E4=B8=8E=E7=94=B5?= =?UTF-8?q?=E7=BC=86=E5=9E=8B=E5=8F=B7=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 51d1110..b31186d 100644 --- a/main.py +++ b/main.py @@ -803,19 +803,32 @@ def compare_design_methods(excel_path=None, n_clusters_override=None): total_power = turbines['power'].sum() 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 则自动计算 if n_clusters_override is not None: n_clusters = n_clusters_override min_clusters_needed = int(np.ceil(total_power / max_cable_mw)) print(f"使用手动指定的回路数(簇数): {n_clusters} (理论最小需求 {min_clusters_needed})") else: + # 新逻辑:风机数量 / 电缆型号数量,向上取整 + n_clusters = int(np.ceil(len(turbines) / n_cable_types)) 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: # 避免簇数多于风机数 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)