From 870c9433d637ec5bc2e1bf958a901b418003574e Mon Sep 17 00:00:00 2001 From: Jiang Date: Tue, 3 Feb 2026 11:53:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=85=B3=E9=98=80=E5=88=86?= =?UTF-8?q?=E6=9E=90=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/algorithms/valve_isolation.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/algorithms/valve_isolation.py b/app/algorithms/valve_isolation.py index 98f22ce..092f4f8 100644 --- a/app/algorithms/valve_isolation.py +++ b/app/algorithms/valve_isolation.py @@ -1,7 +1,12 @@ from collections import defaultdict, deque from typing import Any -from app.services.tjnetwork import get_network_link_nodes +from app.services.tjnetwork import ( + get_network_link_nodes, + is_node, + is_link, + get_link_properties, +) VALVE_LINK_TYPE = "valve" @@ -30,6 +35,21 @@ def valve_isolation_analysis( start_nodes = set() + for element in target_elements: + if is_node(network, element): + start_nodes.add(element) + elif is_link(network, element): + link_props = get_link_properties(network, element) + node1 = link_props.get("node1") + node2 = link_props.get("node2") + if not node1 or not node2: + # 如果是批量处理,可以选择跳过错误或记录错误,这里暂时保持严谨抛出异常 + raise ValueError(f"Accident link {element} missing node endpoints") + start_nodes.add(node1) + start_nodes.add(node2) + else: + raise ValueError(f"Accident element {element} not found") + adjacency: dict[str, set[str]] = defaultdict(set) valve_links: dict[str, tuple[str, str]] = {} for link_entry in get_network_link_nodes(network):