feat: 增加平台高度参数,优化电缆长度计算

This commit is contained in:
dmy
2026-01-01 12:23:00 +08:00
parent e7e12745d1
commit e6d98297b1
2 changed files with 52 additions and 12 deletions

View File

@@ -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)

58
main.py
View File

@@ -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")