修复find_new_center_pipe中心点代码错误的bug
This commit is contained in:
@@ -25,8 +25,8 @@ 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
|
||||
y_vals = (node_y[end_nodes].to_numpy() + node_y[end_nodes].to_numpy()) / 2.0
|
||||
x_vals = (node_x[start_nodes].to_numpy() + node_x[end_nodes].to_numpy()) / 2.0
|
||||
y_vals = (node_y[start_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))
|
||||
distance = np.abs(x_vals - mean_x) + np.abs(y_vals - mean_y)
|
||||
@@ -122,8 +122,14 @@ def metis_grouping_pipe_weight(
|
||||
w_f = w_f + w_new[i]
|
||||
|
||||
# (edgecuts, parts) = pymetis.part_graph(nparts=group_num, adjacency=adjacency_list_new)
|
||||
# metis_options = pymetis.Options()
|
||||
# metis_options.seed = 42
|
||||
(edgecuts, parts) = pymetis.part_graph(
|
||||
nparts=group_num, adjncy=final_adjacency_list, xadj=xadj, eweights=w_f
|
||||
nparts=group_num,
|
||||
adjncy=final_adjacency_list,
|
||||
xadj=xadj,
|
||||
eweights=w_f,
|
||||
# options=metis_options,
|
||||
)
|
||||
# (edgecuts, parts) = pymetis.part_graph(nparts=group_num, adjacency=adjacency_list_new)
|
||||
candidate_group_list = [[] * 1 for i in range(group_num)]
|
||||
@@ -249,6 +255,9 @@ def visualize_metis_partition(
|
||||
"""
|
||||
fig = plt.figure("metis_partition_convergence", figsize=(22.51, 12.48))
|
||||
fig.clf()
|
||||
ax = fig.add_subplot(111)
|
||||
if not block:
|
||||
plt.ion()
|
||||
|
||||
# 生成颜色映射(自动扩展颜色数量)
|
||||
colors = plt.cm.tab20(np.linspace(0, 1, len(pipe_groups)))
|
||||
@@ -256,7 +265,7 @@ def visualize_metis_partition(
|
||||
# --- 绘制背景管网(灰色半透明) ---
|
||||
for edge in G.edges():
|
||||
start_node, end_node = edge
|
||||
plt.plot(
|
||||
ax.plot(
|
||||
[node_x[start_node], node_x[end_node]],
|
||||
[node_y[start_node], node_y[end_node]],
|
||||
color="lightgray",
|
||||
@@ -274,7 +283,7 @@ def visualize_metis_partition(
|
||||
for pipe in group:
|
||||
start = pipe_start_node_all[pipe]
|
||||
end = pipe_end_node_all[pipe]
|
||||
line = plt.plot(
|
||||
line = ax.plot(
|
||||
[node_x[start], node_x[end]],
|
||||
[node_y[start], node_y[end]],
|
||||
color=color,
|
||||
@@ -290,7 +299,7 @@ def visualize_metis_partition(
|
||||
if center in pipe_start_node_all and center in pipe_end_node_all:
|
||||
start = pipe_start_node_all[center]
|
||||
end = pipe_end_node_all[center]
|
||||
plt.plot(
|
||||
ax.plot(
|
||||
[node_x[start], node_x[end]],
|
||||
[node_y[start], node_y[end]],
|
||||
color="red",
|
||||
@@ -304,7 +313,7 @@ def visualize_metis_partition(
|
||||
# 分组图例
|
||||
if legend_handles:
|
||||
group_labels = [f"Group {i + 1}" for i in range(len(pipe_groups))]
|
||||
plt.legend(
|
||||
ax.legend(
|
||||
legend_handles,
|
||||
group_labels,
|
||||
loc="upper right",
|
||||
@@ -322,7 +331,7 @@ def visualize_metis_partition(
|
||||
y = (
|
||||
node_y[pipe_start_node_all[center]] + node_y[pipe_end_node_all[center]]
|
||||
) / 2
|
||||
plt.text(
|
||||
ax.text(
|
||||
x,
|
||||
y,
|
||||
f"C{i + 1}",
|
||||
@@ -334,15 +343,20 @@ def visualize_metis_partition(
|
||||
)
|
||||
|
||||
# --- 图形美化 ---
|
||||
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()
|
||||
ax.set_title(title or "Water Network Partitioning Overview", fontsize=14, pad=20)
|
||||
ax.set_xlabel("X Coordinate", fontsize=10)
|
||||
ax.set_ylabel("Y Coordinate", fontsize=10)
|
||||
ax.grid(True, alpha=0.2, linestyle=":")
|
||||
fig.tight_layout()
|
||||
|
||||
# 显示图形
|
||||
# 显示图形并强制刷新,避免迭代显示滞后一轮。
|
||||
plt.show(block=block)
|
||||
if pause_seconds is not None:
|
||||
if not block:
|
||||
fig.canvas.draw_idle()
|
||||
fig.canvas.flush_events()
|
||||
pause_value = 0.001 if pause_seconds is None else max(0.0, float(pause_seconds))
|
||||
plt.pause(max(0.001, pause_value))
|
||||
elif pause_seconds is not None:
|
||||
plt.pause(max(0.0, float(pause_seconds)))
|
||||
return fig
|
||||
|
||||
|
||||
Reference in New Issue
Block a user