From e6d98297b1501e9410b55bee58cafa78e96242fd Mon Sep 17 00:00:00 2001 From: dmy Date: Thu, 1 Jan 2026 12:23:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E9=AB=98=E5=BA=A6=E5=8F=82=E6=95=B0=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=94=B5=E7=BC=86=E9=95=BF=E5=BA=A6=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generate_template.py | 6 +++-- main.py | 58 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/generate_template.py b/generate_template.py index 2d1ea39..7875ff8 100644 --- a/generate_template.py +++ b/generate_template.py @@ -11,7 +11,8 @@ def create_template(): 'ID': 'Sub1', 'X': 4000, 'Y': -800, - 'Power': 0 + 'Power': 0, + 'PlatformHeight': 0 }) # Add Turbines (Grid layout) @@ -29,7 +30,8 @@ def create_template(): 'ID': i, 'X': x, 'Y': y, - 'Power': np.random.uniform(6.0, 10.0) + 'Power': np.random.uniform(6.0, 10.0), + 'PlatformHeight': 0 }) df = pd.DataFrame(data) diff --git a/main.py b/main.py index 0ac9c25..82dcec2 100644 --- a/main.py +++ b/main.py @@ -107,6 +107,15 @@ def load_data_from_excel(file_path): if len(turbines_df) == 0: raise ValueError("未在文件中找到风机(Turbine)数据") + # 尝试获取平台高度列 (兼容不同命名) + platform_height_col = None + for col in turbines_df.columns: + if col.lower().replace(' ', '') == 'platformheight': + platform_height_col = col + break + + platform_heights = turbines_df[platform_height_col].values if platform_height_col else np.zeros(len(turbines_df)) + # 重置索引并整理格式 turbines = pd.DataFrame({ 'id': range(len(turbines_df)), @@ -114,6 +123,7 @@ def load_data_from_excel(file_path): 'x': turbines_df['X'].values, 'y': turbines_df['Y'].values, 'power': turbines_df['Power'].values, + 'platform_height': platform_heights, 'cumulative_power': np.zeros(len(turbines_df)) }) @@ -466,6 +476,22 @@ def evaluate_design(turbines, connections, substation, cable_specs=None, is_offs detailed_connections = [] for source, target, length in connections: + # Determine vertical length (PlatformHeight) + vertical_length = 0 + + if source.startswith('turbine_'): + tid = int(source.split('_')[1]) + vertical_length += turbines.loc[tid, 'platform_height'] + + if target.startswith('turbine_'): + tid = int(target.split('_')[1]) + vertical_length += turbines.loc[tid, 'platform_height'] + + # Calculate effective length with margin + # Total Length = (Horizontal Distance + Vertical Up/Down) * 1.03 + horizontal_length = length + effective_length = (horizontal_length + vertical_length) * 1.03 + # 确定该段线路承载的总功率 if source.startswith('turbine_') and target.startswith('turbine_'): # 风机间连接,取下游节点功率 @@ -516,8 +542,8 @@ def evaluate_design(turbines, connections, substation, cable_specs=None, is_offs selected_spec = cable_specs_to_use[-1] print(f"WARNING [{method_name}]: Current {current:.2f} A (Power: {power:.2f} MW) exceeds max cable capacity {selected_spec[1]} A!") - resistance = selected_spec[2] * length / 1000 # 电阻(Ω) - cost = selected_spec[3] * length * cost_multiplier # 电缆成本(含敷设) + resistance = selected_spec[2] * effective_length / 1000 # 电阻(Ω) + cost = selected_spec[3] * effective_length * cost_multiplier # 电缆成本(含敷设) cable = { 'cross_section': selected_spec[0], @@ -531,7 +557,9 @@ def evaluate_design(turbines, connections, substation, cable_specs=None, is_offs detailed_connections.append({ 'source': source, 'target': target, - 'length': length, + 'horizontal_length': horizontal_length, + 'vertical_length': vertical_length, + 'length': effective_length, # effective length used for stats 'power': power, 'cable': cable }) @@ -843,23 +871,33 @@ def compare_design_methods(excel_path=None, n_clusters_override=None): print(f"总回路数: {num_circuits}") # 2. 每种型号电缆长度 - cable_lengths = defaultdict(float) + raw_horizontal_lengths = defaultdict(float) # 仅风机间 + effective_lengths = defaultdict(float) # 机箱变之间 (含垂直+裕度) max_current = 0.0 + total_vertical_length = 0.0 for conn in kmeans_evaluation['details']: - # Length section = conn['cable']['cross_section'] - length = conn['length'] - cable_lengths[section] += length + + # Accumulate + raw_horizontal_lengths[section] += conn['horizontal_length'] + effective_lengths[section] += conn['length'] + total_vertical_length += conn['vertical_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") + print("每种型号电缆长度 (仅风机间水平距离):") + for section in sorted(raw_horizontal_lengths.keys()): + print(f" {section}mm²: {raw_horizontal_lengths[section]:.2f} m") + + print("机箱变之间电缆长度 (含垂直高度及1.03裕度):") + for section in sorted(effective_lengths.keys()): + print(f" {section}mm²: {effective_lengths[section]:.2f} m") + + print(f"其中电缆上下风机总长度: {total_vertical_length:.2f} m") # 3. 最大支路电流 print(f"最大支路电流: {max_current:.2f} A")