重构管道中心选择逻辑,优化数据处理方式
This commit is contained in:
@@ -37,6 +37,8 @@ def _ensure_signatures_for_centers(
|
||||
其中 subset 只包含 center_list 的行(顺序与 center_list 保持一致)。
|
||||
"""
|
||||
|
||||
center_list = _dedupe_preserve_order(center_list)
|
||||
|
||||
# 1) 推断传感器列名(与现有数据保持一致)
|
||||
sensor_name_all = list(pressure_monitor.columns)
|
||||
sensor_f_name_all = (
|
||||
@@ -193,6 +195,17 @@ def find_list_repeat(candidate_center, target):
|
||||
return repeated_list
|
||||
|
||||
|
||||
def _dedupe_preserve_order(items):
|
||||
seen = set()
|
||||
output = []
|
||||
for item in items:
|
||||
if item in seen:
|
||||
continue
|
||||
seen.add(item)
|
||||
output.append(item)
|
||||
return output
|
||||
|
||||
|
||||
def cal_DtoTop1(
|
||||
G0, pipe_leak, located_pipe, pipe_start_node_all, pipe_end_node_all, pipe_length
|
||||
):
|
||||
@@ -324,6 +337,7 @@ def DN_search_multi_simple_add_flow_count_new(
|
||||
dis_f_h = 0
|
||||
if_compalsive = 0
|
||||
record_center_dataset = []
|
||||
record_center_set = set()
|
||||
# iter
|
||||
while 1:
|
||||
final_area = []
|
||||
@@ -374,18 +388,21 @@ def DN_search_multi_simple_add_flow_count_new(
|
||||
leak_center_dict = dict()
|
||||
for i in range(len(candidate_center_list)):
|
||||
houxuan_center = []
|
||||
candidate_group_set = set(candidate_group_list[i])
|
||||
for each_center in record_center_dataset:
|
||||
if (
|
||||
each_center in candidate_group_list[i]
|
||||
each_center in candidate_group_set
|
||||
and each_center != candidate_center_list[i]
|
||||
):
|
||||
houxuan_center.append(each_center)
|
||||
add_center = add_center + houxuan_center
|
||||
houxuan_center.append(candidate_center_list[i])
|
||||
leak_center_dict[candidate_center_list[i]] = houxuan_center
|
||||
add_center = _dedupe_preserve_order(add_center)
|
||||
for each_center in candidate_center_list:
|
||||
if each_center not in record_center_dataset:
|
||||
if each_center not in record_center_set:
|
||||
record_center_dataset.append(each_center)
|
||||
record_center_set.add(each_center)
|
||||
|
||||
# --------------------------------------------------------
|
||||
# --------------------------------------------------------
|
||||
@@ -417,7 +434,9 @@ def DN_search_multi_simple_add_flow_count_new(
|
||||
if len(candidate_pipe_input) < 1.2 * top_pipe_num_max / top_group_ratio:
|
||||
if_compalsive = 1
|
||||
cos_h, dis_h, dis_f_h = adjust_ratio(similarity_mode, cos_h, dis_h, dis_f_h)
|
||||
candidate_center_list_sup = candidate_center_list + add_center
|
||||
candidate_center_list_sup = _dedupe_preserve_order(
|
||||
candidate_center_list + add_center
|
||||
)
|
||||
similarity, cos_h, dis_h, dis_f_h, break_flag = (
|
||||
cal_similarity_all_multi_new_sq_improve_double_lzr(
|
||||
candidate_center_list_sup,
|
||||
|
||||
@@ -21,25 +21,19 @@ def _to_metis_edge_weight(edge_weight):
|
||||
|
||||
|
||||
def pick_center_pipe(node_x, node_y, candidate_pipe, pipe_start_node, pipe_end_node):
|
||||
data_set_t = pd.DataFrame(dtype=object)
|
||||
data_set_t["x"] = (
|
||||
node_x[pipe_start_node[candidate_pipe]].values
|
||||
+ node_x[pipe_start_node[candidate_pipe]].values
|
||||
) / 2
|
||||
data_set_t["y"] = (
|
||||
node_y[pipe_end_node[candidate_pipe]].values
|
||||
+ node_y[pipe_end_node[candidate_pipe]].values
|
||||
) / 2
|
||||
data_set_t.index = list(candidate_pipe)
|
||||
mean_x = data_set_t["x"].mean()
|
||||
mean_y = data_set_t["y"].mean()
|
||||
data_set_t["d"] = abs(data_set_t["x"] - mean_x) + abs(data_set_t["y"] - mean_y)
|
||||
distance_t = data_set_t["d"].sort_values(ascending=True, inplace=False)
|
||||
"""if distance_t.index==[]:
|
||||
print(candidate_pipe)
|
||||
else:"""
|
||||
center_t = distance_t.index[0]
|
||||
return center_t
|
||||
candidate_pipe_list = list(candidate_pipe)
|
||||
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
|
||||
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)
|
||||
center_idx = int(np.argmin(distance))
|
||||
return candidate_pipe_list[center_idx]
|
||||
|
||||
|
||||
def find_new_center_pipe(
|
||||
@@ -56,11 +50,8 @@ def find_new_center_pipe(
|
||||
|
||||
def cal_area_node_linked_pipe(nodeset, node_pipe_dic):
|
||||
pipeset = []
|
||||
nodeset = list(nodeset)
|
||||
for i in range(len(nodeset)):
|
||||
temp_node = nodeset[i]
|
||||
pipe = node_pipe_dic[temp_node]
|
||||
pipeset = pipeset + pipe
|
||||
for temp_node in nodeset:
|
||||
pipeset.extend(node_pipe_dic[temp_node])
|
||||
return pipeset
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user