feat: 增加平台高度参数,优化电缆长度计算
This commit is contained in:
@@ -11,7 +11,8 @@ def create_template():
|
|||||||
'ID': 'Sub1',
|
'ID': 'Sub1',
|
||||||
'X': 4000,
|
'X': 4000,
|
||||||
'Y': -800,
|
'Y': -800,
|
||||||
'Power': 0
|
'Power': 0,
|
||||||
|
'PlatformHeight': 0
|
||||||
})
|
})
|
||||||
|
|
||||||
# Add Turbines (Grid layout)
|
# Add Turbines (Grid layout)
|
||||||
@@ -29,7 +30,8 @@ def create_template():
|
|||||||
'ID': i,
|
'ID': i,
|
||||||
'X': x,
|
'X': x,
|
||||||
'Y': y,
|
'Y': y,
|
||||||
'Power': np.random.uniform(6.0, 10.0)
|
'Power': np.random.uniform(6.0, 10.0),
|
||||||
|
'PlatformHeight': 0
|
||||||
})
|
})
|
||||||
|
|
||||||
df = pd.DataFrame(data)
|
df = pd.DataFrame(data)
|
||||||
|
|||||||
58
main.py
58
main.py
@@ -107,6 +107,15 @@ def load_data_from_excel(file_path):
|
|||||||
if len(turbines_df) == 0:
|
if len(turbines_df) == 0:
|
||||||
raise ValueError("未在文件中找到风机(Turbine)数据")
|
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({
|
turbines = pd.DataFrame({
|
||||||
'id': range(len(turbines_df)),
|
'id': range(len(turbines_df)),
|
||||||
@@ -114,6 +123,7 @@ def load_data_from_excel(file_path):
|
|||||||
'x': turbines_df['X'].values,
|
'x': turbines_df['X'].values,
|
||||||
'y': turbines_df['Y'].values,
|
'y': turbines_df['Y'].values,
|
||||||
'power': turbines_df['Power'].values,
|
'power': turbines_df['Power'].values,
|
||||||
|
'platform_height': platform_heights,
|
||||||
'cumulative_power': np.zeros(len(turbines_df))
|
'cumulative_power': np.zeros(len(turbines_df))
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -466,6 +476,22 @@ def evaluate_design(turbines, connections, substation, cable_specs=None, is_offs
|
|||||||
detailed_connections = []
|
detailed_connections = []
|
||||||
|
|
||||||
for source, target, length in 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_'):
|
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]
|
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!")
|
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 # 电阻(Ω)
|
resistance = selected_spec[2] * effective_length / 1000 # 电阻(Ω)
|
||||||
cost = selected_spec[3] * length * cost_multiplier # 电缆成本(含敷设)
|
cost = selected_spec[3] * effective_length * cost_multiplier # 电缆成本(含敷设)
|
||||||
|
|
||||||
cable = {
|
cable = {
|
||||||
'cross_section': selected_spec[0],
|
'cross_section': selected_spec[0],
|
||||||
@@ -531,7 +557,9 @@ def evaluate_design(turbines, connections, substation, cable_specs=None, is_offs
|
|||||||
detailed_connections.append({
|
detailed_connections.append({
|
||||||
'source': source,
|
'source': source,
|
||||||
'target': target,
|
'target': target,
|
||||||
'length': length,
|
'horizontal_length': horizontal_length,
|
||||||
|
'vertical_length': vertical_length,
|
||||||
|
'length': effective_length, # effective length used for stats
|
||||||
'power': power,
|
'power': power,
|
||||||
'cable': cable
|
'cable': cable
|
||||||
})
|
})
|
||||||
@@ -843,23 +871,33 @@ def compare_design_methods(excel_path=None, n_clusters_override=None):
|
|||||||
print(f"总回路数: {num_circuits}")
|
print(f"总回路数: {num_circuits}")
|
||||||
|
|
||||||
# 2. 每种型号电缆长度
|
# 2. 每种型号电缆长度
|
||||||
cable_lengths = defaultdict(float)
|
raw_horizontal_lengths = defaultdict(float) # 仅风机间
|
||||||
|
effective_lengths = defaultdict(float) # 机箱变之间 (含垂直+裕度)
|
||||||
max_current = 0.0
|
max_current = 0.0
|
||||||
|
total_vertical_length = 0.0
|
||||||
|
|
||||||
for conn in kmeans_evaluation['details']:
|
for conn in kmeans_evaluation['details']:
|
||||||
# Length
|
|
||||||
section = conn['cable']['cross_section']
|
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
|
# Max Current
|
||||||
current = conn['cable']['current']
|
current = conn['cable']['current']
|
||||||
if current > max_current:
|
if current > max_current:
|
||||||
max_current = current
|
max_current = current
|
||||||
|
|
||||||
print("每种型号电缆的长度:")
|
print("每种型号电缆长度 (仅风机间水平距离):")
|
||||||
for section in sorted(cable_lengths.keys()):
|
for section in sorted(raw_horizontal_lengths.keys()):
|
||||||
print(f" {section}mm²: {cable_lengths[section]:.2f} m")
|
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. 最大支路电流
|
# 3. 最大支路电流
|
||||||
print(f"最大支路电流: {max_current:.2f} A")
|
print(f"最大支路电流: {max_current:.2f} A")
|
||||||
|
|||||||
Reference in New Issue
Block a user