From e7e12745d1e11a8d2d02009735a0c1069f655848 Mon Sep 17 00:00:00 2001 From: dmy Date: Thu, 1 Jan 2026 11:55:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E9=A3=8E=E7=94=B5?= =?UTF-8?q?=E5=9C=BA=E9=9B=86=E7=94=B5=E7=B3=BB=E7=BB=9F=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E7=94=B5=E7=BC=86=E8=A7=84=E6=A0=BC?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 4a49c84..0ac9c25 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,10 @@ import argparse plt.rcParams['font.sans-serif'] = ['Microsoft YaHei', 'SimHei', 'Arial'] plt.rcParams['axes.unicode_minus'] = False +# 常量定义 +VOLTAGE_LEVEL = 66000 # 66kV +POWER_FACTOR = 0.95 + # 1. 生成风电场数据(实际应用中替换为真实坐标) def generate_wind_farm_data(n_turbines=30, seed=42, layout='random', spacing=800): """ @@ -381,10 +385,6 @@ def design_with_capacitated_sweep(turbines, substation, cable_specs=None): return cluster_connections + substation_connections, turbines -# 常量定义 -VOLTAGE_LEVEL = 66000 # 66kV -POWER_FACTOR = 0.95 - def get_max_cable_capacity_mw(cable_specs=None): """ 计算给定电缆规格中能够承载的最大功率 (单位: MW)。 @@ -616,8 +616,8 @@ def export_to_dxf(turbines, substation, connections_details, filename): if layer_name not in doc.layers: doc.layers.add(layer_name) - # 绘制直线 - msp.add_line(p1, p2, dxfattribs={'layer': layer_name}) + # 绘制二维多段线 + msp.add_lwpolyline([p1, p2], dxfattribs={'layer': layer_name}) # 添加电缆型号文字(可选,在线的中点) # mid_x = (p1[0] + p2[0]) / 2 @@ -824,7 +824,7 @@ def compare_design_methods(excel_path=None, n_clusters_override=None): # 这里我们导出Sector Clustering的结果 export_to_dxf(clustered_turbines, substation, kmeans_evaluation['details'], dxf_filename) - plt.show() + # plt.show() # 打印详细结果 print(f"\n===== 海上风电场设计方案比较 ({'导入数据' if excel_path else '自动生成'}) =====") @@ -833,6 +833,36 @@ def compare_design_methods(excel_path=None, n_clusters_override=None): print(f" 总成本: ¥{eval_data['total_cost']:,.2f} ({eval_data['total_cost']/10000:.2f}万元)") print(f" 预估总损耗: {eval_data['total_loss']:.2f} kW") print(f" 连接数量: {eval_data['num_connections']}") + + # Calculate additional metrics for K-means (Capacitated Sweep) + print("\n===== K-Means (Capacitated Sweep) 详细统计 =====") + + # 1. 总回路数 + # The 'cluster' column in clustered_turbines holds the circuit ID. + num_circuits = clustered_turbines['cluster'].nunique() + print(f"总回路数: {num_circuits}") + + # 2. 每种型号电缆长度 + cable_lengths = defaultdict(float) + max_current = 0.0 + + for conn in kmeans_evaluation['details']: + # Length + section = conn['cable']['cross_section'] + length = conn['length'] + cable_lengths[section] += length + + # Max Current + current = conn['cable']['current'] + if current > max_current: + max_current = current + + print("每种型号电缆的长度:") + for section in sorted(cable_lengths.keys()): + print(f" {section}mm²: {cable_lengths[section]:.2f} m") + + # 3. 最大支路电流 + print(f"最大支路电流: {max_current:.2f} A") return results @@ -850,4 +880,4 @@ if __name__ == "__main__": # 3. 运行比较 # 如果本地没有excel文件,将自动回退到生成数据模式 - compare_design_methods(excel_path, n_clusters_override=args.clusters) + compare_design_methods(excel_path, n_clusters_override=args.clusters) \ No newline at end of file