重构爆管定位算法,增加多进程支持与可视化功能
This commit is contained in:
@@ -25,9 +25,7 @@ def pick_center_pipe(node_x, node_y, candidate_pipe, pipe_start_node, pipe_end_n
|
||||
start_nodes = pipe_start_node[candidate_pipe_list]
|
||||
end_nodes = pipe_end_node[candidate_pipe_list]
|
||||
|
||||
x_vals = (
|
||||
node_x[start_nodes].to_numpy() + node_x[start_nodes].to_numpy()
|
||||
) / 2.0
|
||||
x_vals = (node_x[start_nodes].to_numpy() + node_x[start_nodes].to_numpy()) / 2.0
|
||||
y_vals = (node_y[end_nodes].to_numpy() + node_y[end_nodes].to_numpy()) / 2.0
|
||||
mean_x = float(np.mean(x_vals))
|
||||
mean_y = float(np.mean(y_vals))
|
||||
@@ -227,7 +225,16 @@ def metis_grouping_pipe_weight(
|
||||
|
||||
|
||||
def visualize_metis_partition(
|
||||
G, center_pipes, pipe_groups, node_x, node_y, pipe_start_node_all, pipe_end_node_all
|
||||
G,
|
||||
center_pipes,
|
||||
pipe_groups,
|
||||
node_x,
|
||||
node_y,
|
||||
pipe_start_node_all,
|
||||
pipe_end_node_all,
|
||||
title: str | None = None,
|
||||
block: bool = True,
|
||||
pause_seconds: float | None = None,
|
||||
):
|
||||
"""
|
||||
可视化METIS分区结果(单图模式)
|
||||
@@ -240,7 +247,8 @@ def visualize_metis_partition(
|
||||
pipe_start_node_all: 管道起点字典(dict)
|
||||
pipe_end_node_all: 管道终点字典(dict)
|
||||
"""
|
||||
plt.figure(figsize=(9, 10))
|
||||
fig = plt.figure("metis_partition_convergence", figsize=(22.51, 12.48))
|
||||
fig.clf()
|
||||
|
||||
# 生成颜色映射(自动扩展颜色数量)
|
||||
colors = plt.cm.tab20(np.linspace(0, 1, len(pipe_groups)))
|
||||
@@ -294,15 +302,16 @@ def visualize_metis_partition(
|
||||
|
||||
# --- 添加图例和标注 ---
|
||||
# 分组图例
|
||||
group_labels = [f"Group {i + 1}" for i in range(len(pipe_groups))]
|
||||
plt.legend(
|
||||
legend_handles,
|
||||
group_labels,
|
||||
loc="upper right",
|
||||
title="Partitions",
|
||||
fontsize=8,
|
||||
title_fontsize=10,
|
||||
)
|
||||
if legend_handles:
|
||||
group_labels = [f"Group {i + 1}" for i in range(len(pipe_groups))]
|
||||
plt.legend(
|
||||
legend_handles,
|
||||
group_labels,
|
||||
loc="upper right",
|
||||
title="Partitions",
|
||||
fontsize=8,
|
||||
title_fontsize=10,
|
||||
)
|
||||
|
||||
# 中心管道标注(可选)
|
||||
for i, center in enumerate(center_pipes):
|
||||
@@ -325,14 +334,17 @@ def visualize_metis_partition(
|
||||
)
|
||||
|
||||
# --- 图形美化 ---
|
||||
plt.title("Water Network Partitioning Overview", fontsize=14, pad=20)
|
||||
plt.title(title or "Water Network Partitioning Overview", fontsize=14, pad=20)
|
||||
plt.xlabel("X Coordinate", fontsize=10)
|
||||
plt.ylabel("Y Coordinate", fontsize=10)
|
||||
plt.grid(True, alpha=0.2, linestyle=":")
|
||||
plt.tight_layout()
|
||||
|
||||
# 显示图形
|
||||
plt.show()
|
||||
plt.show(block=block)
|
||||
if pause_seconds is not None:
|
||||
plt.pause(max(0.0, float(pause_seconds)))
|
||||
return fig
|
||||
|
||||
|
||||
def generate_adjlist_with_all_edges(G, delimiter):
|
||||
|
||||
Reference in New Issue
Block a user