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