Class DirectedGraph
-
- All Implemented Interfaces:
public class DirectedGraphA directed graph data structure with weighted edges represented as an adjacency matrix.
This class provides graph algorithms for directed graphs including cycle detection, topological sorting, and connectivity analysis. It's particularly useful for routing matrix analysis, dependency resolution, and network topology validation.
Key graph algorithms supported:
- Directed Acyclic Graph (DAG) detection
- Topological sorting using Kahn's algorithm
- Adjacency matrix-based representation
- Weighted edge support
- Column filtering for selective analysis
- Since:
1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classDirectedGraph.SCCAuxResultpublic classDirectedGraph.SCCResult
-
Constructor Summary
Constructors Constructor Description DirectedGraph(Matrix param, Set<Integer> colsToIgnore)Constructs a directed graph with the given adjacency matrix and column filter. DirectedGraph(Matrix param)Constructs a directed graph with the given adjacency matrix (no column filtering).
-
Method Summary
Modifier and Type Method Description static booleanisDAG(Matrix adj)Tests if the given adjacency matrix represents a Directed Acyclic Graph (DAG). static Matrixkahn(Matrix adj)Performs topological sorting using Kahn's algorithm. voidaddEdge(int s, int d, double weight)DirectedGraph.SCCResultstronglyconncomp()MatrixtoMatrix()-
-
Constructor Detail
-
DirectedGraph
DirectedGraph(Matrix param, Set<Integer> colsToIgnore)
Constructs a directed graph with the given adjacency matrix and column filter.- Parameters:
param- adjacency matrix [V x V] where entry (i,j) represents edge weight from vertex i to jcolsToIgnore- set of column indices to ignore during graph operations, can be null
-
DirectedGraph
DirectedGraph(Matrix param)
Constructs a directed graph with the given adjacency matrix (no column filtering).- Parameters:
param- adjacency matrix [V x V] where entry (i,j) represents edge weight from vertex i to j
-
-
Method Detail
-
isDAG
static boolean isDAG(Matrix adj)
Tests if the given adjacency matrix represents a Directed Acyclic Graph (DAG).
- Parameters:
adj- adjacency matrix [V x V] to test for cycles- Returns:
true if the graph is acyclic, false if cycles are detected
-
kahn
static Matrix kahn(Matrix adj)
Performs topological sorting using Kahn's algorithm.
This method computes a topological ordering of vertices in a directed graph. If the graph contains cycles, the returned ordering will be incomplete.
- Parameters:
adj- adjacency matrix [V x V] representing the directed graph- Returns:
matrix containing topologically sorted vertex indices, incomplete if graph has cycles
-
addEdge
void addEdge(int s, int d, double weight)
-
stronglyconncomp
DirectedGraph.SCCResult stronglyconncomp()
-
-
-
-