Package jline.util.graph
Class DirectedGraph
java.lang.Object
jline.util.graph.DirectedGraph
A 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
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Constructor Summary
ConstructorsConstructorDescriptionDirectedGraph(Matrix param) Constructs a directed graph with the given adjacency matrix (no column filtering).DirectedGraph(Matrix param, Set<Integer> colsToIgnore) Constructs a directed graph with the given adjacency matrix and column filter. -
Method Summary
-
Constructor Details
-
DirectedGraph
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
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 Details
-
isDAG
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
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
public void addEdge(int s, int d, double weight) -
stronglyconncomp
-
toMatrix
-