public final class GraphUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <V> List<Edge<V>> |
acyclicTransitiveReduction(DirectedGraph<V> acyclicGraph)
For a given acyclic graph this method returns a list of edges that can be
removed to obtain a transitive reduction of the given graph.
|
static <V> DirectedGraph<V> |
completeGraph(Set<V> vertices)
Returns complete graph over given set of vertices.
|
static <V> List<List<V>> |
computeSCC(DirectedGraph<V> graph)
Computes strongly-connected components.
|
static <V> List<V> |
getCycle(DirectedGraph<V> graph)
Returns a list of vertices forming a cycle or
null if the
graph is acyclic. |
static <V> Set<V> |
getVerticesInCycles(DirectedGraph<V> graph)
Returns a set of all vertices that take part in a cycle.
|
static <V> List<V> |
internalTopSort(DirectedGraph<V> graph)
Returns topological sort of given directed graph or
null if the graph is
not acyclic. |
static boolean |
isAcyclic(DirectedGraph<?> graph)
Returns true if given graph is acyclic.
|
static <V> DirectedGraph<V> |
reverse(DirectedGraph<V> graph)
Returns reverse of given graph (all edges are reversed).
|
static <V> DirectedGraph<V> |
subgraph(DirectedGraph<V> graph,
Set<V> vertices)
Returns new instance of
DirectedGraph induced by given set of
vertices on given graph. |
static <V> List<V> |
topologicalSort(DirectedGraph<V> graph)
Returns topological sort of given acyclic directed graph.
|
static void |
transitiveClosure(DirectedGraph<?> graph)
Adds edges to a given graph to create a transitive closure.
|
static <V> Set<V> |
transitiveClosure(DirectedGraph<V> graph,
Set<? extends V> vertices)
Returns transitive closure of given vertices on given graph.
|
public static <V> DirectedGraph<V> subgraph(DirectedGraph<V> graph, Set<V> vertices)
DirectedGraph
induced by given set of
vertices on given graph. Given vertices must form a subset of the graph
vertices.V
- type of graph vertexvertices
- set of verticesgraph
- directed graphNullPointerException
- if any argument is nullIllegalArgumentException
- if given vertices are not a subset of this graph verticespublic static <V> DirectedGraph<V> completeGraph(Set<V> vertices)
V
- type of vertexvertices
- set of verticesNullPointerException
- if argument vertices is nullpublic static <V> Set<V> transitiveClosure(DirectedGraph<V> graph, Set<? extends V> vertices)
V
- type of vertexgraph
- directed graphvertices
- set of verticesNullPointerException
- if any argument is nullIllegalArgumentException
- if given vertices are not a subset of this graph verticespublic static void transitiveClosure(DirectedGraph<?> graph)
graph
- public static <V> DirectedGraph<V> reverse(DirectedGraph<V> graph)
V
- type of vertexgraph
- directed graphpublic static <V> List<V> topologicalSort(DirectedGraph<V> graph)
V
- type of vertexgraph
- acyclic directed graphIllegalArgumentException
- if given graph is not acyclicpublic static <V> List<V> internalTopSort(DirectedGraph<V> graph)
null
if the graph is
not acyclic.
IMPORTANT: the method modifies the given graph.
V
- type of vertexgraph
- directed graph (will be modified by the method)public static boolean isAcyclic(DirectedGraph<?> graph)
graph
- directed graphpublic static <V> List<V> getCycle(DirectedGraph<V> graph)
null
if the
graph is acyclic. The algorithm finds only one cycle, not all cycles.V
- graph
- null
if the
graph is acyclicpublic static <V> List<List<V>> computeSCC(DirectedGraph<V> graph)
V
- graph
- public static <V> Set<V> getVerticesInCycles(DirectedGraph<V> graph)
V
- graph
- public static <V> List<Edge<V>> acyclicTransitiveReduction(DirectedGraph<V> acyclicGraph)
V
- acyclicGraph
- Copyright © 2007-2020 Whitestein Technologies. All Rights Reserved.