Class LoopDetector
java.lang.Object
neqsim.process.equipment.network.LoopDetector
- All Implemented Interfaces:
Serializable
Detects independent loops in a pipeline network using graph theory algorithms.
Uses Depth-First Search (DFS) to build a spanning tree of the network graph. Non-tree edges (chords) each define exactly one independent loop. The number of independent loops equals: E - V + 1 (for a connected graph) where E is the number of edges (pipelines) and V is the number of vertices (nodes).
Algorithm
- Build a graph representation from node/edge data
- Run DFS to create a spanning tree
- Identify chord edges (edges not in the spanning tree)
- For each chord, trace the fundamental cycle (loop)
References
- Cormen, T.H. et al. "Introduction to Algorithms" - Graph algorithms
- Cross, H. (1936). "Analysis of Flow in Networks of Conduits or Conductors."
- Version:
- 1.0
- Author:
- Even Solbraa
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classRepresents an edge in the network graph. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<String, List<LoopDetector.Edge>> Adjacency list representation of the network graph.private final List<LoopDetector.Edge> All edges in the graph (forward direction only).Depth of each node in the spanning tree.private List<NetworkLoop> Detected independent loops.private intCounter for generating loop IDs.Set of node names.Parent pointers from DFS spanning tree.private final Map<String, LoopDetector.Edge> Edge used to reach each node in spanning tree.private static final longSet of pipe names that are in the spanning tree. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an edge (pipe) to the graph.private voidBuild a spanning tree using DFS.voidclear()Clear all data and prepare for new analysis.private voidFind chord edges and construct the fundamental cycle for each.private LoopDetector.EdgefindEdgeBetween(String from, String to) Find an edge between two adjacent nodes.Detect all independent loops in the network.intGet the number of edges in the graph.intGet the number of independent loops.getLoops()Get the detected independent loops.intGet the number of nodes in the graph.booleanhasLoops()Check if the network contains any loops.pathToRoot(String node) Find the path from a node to the root of its spanning tree.private NetworkLoopTrace the fundamental cycle created by a chord edge.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
adjacencyList
Adjacency list representation of the network graph. -
allEdges
All edges in the graph (forward direction only). -
nodes
-
parent
-
parentEdge
Edge used to reach each node in spanning tree. -
depth
-
spanningTreePipes
-
independentLoops
Detected independent loops. -
loopIdCounter
private int loopIdCounterCounter for generating loop IDs.
-
-
Constructor Details
-
LoopDetector
public LoopDetector()Create a new loop detector.
-
-
Method Details
-
addEdge
-
clear
public void clear()Clear all data and prepare for new analysis. -
findLoops
Detect all independent loops in the network.- Returns:
- list of independent loops
-
buildSpanningTree
private void buildSpanningTree()Build a spanning tree using DFS. -
findChordLoops
private void findChordLoops()Find chord edges and construct the fundamental cycle for each. -
traceFundamentalCycle
Trace the fundamental cycle created by a chord edge.The fundamental cycle consists of the chord edge plus the unique path in the spanning tree between the chord's endpoints.
- Parameters:
chord- the chord edge- Returns:
- the network loop, or null if no valid loop
-
pathToRoot
-
findEdgeBetween
Find an edge between two adjacent nodes.- Parameters:
from- source nodeto- target node- Returns:
- the edge, or null if not found
-
getLoopCount
public int getLoopCount()Get the number of independent loops.- Returns:
- number of independent loops
-
getLoops
Get the detected independent loops.- Returns:
- unmodifiable list of loops
-
hasLoops
public boolean hasLoops()Check if the network contains any loops.- Returns:
- true if the network has loops (is not a tree)
-
getNodeCount
public int getNodeCount()Get the number of nodes in the graph.- Returns:
- number of nodes
-
getEdgeCount
public int getEdgeCount()Get the number of edges in the graph.- Returns:
- number of edges
-