Class Graphs
- Since:
- 20.0
- Author:
- James Sexton, Joshua O'Madadhain
-
Method Summary
Modifier and TypeMethodDescriptionstatic <N> MutableGraph<N> Creates a mutable copy ofgraphwith the same nodes and edges.static <N,E> MutableNetwork <N, E> Creates a mutable copy ofnetworkwith the same nodes and edges.static <N,V> MutableValueGraph <N, V> copyOf(ValueGraph<N, V> graph) Creates a mutable copy ofgraphwith the same nodes, edges, and edge values.static <N> booleanReturns true ifgraphhas at least one cycle.static booleanReturns true ifnetworkhas at least one cycle.static <N> MutableGraph<N> inducedSubgraph(Graph<N> graph, Iterable<? extends N> nodes) Returns the subgraph ofgraphinduced bynodes.static <N,E> MutableNetwork <N, E> inducedSubgraph(Network<N, E> network, Iterable<? extends N> nodes) Returns the subgraph ofnetworkinduced bynodes.static <N,V> MutableValueGraph <N, V> inducedSubgraph(ValueGraph<N, V> graph, Iterable<? extends N> nodes) Returns the subgraph ofgraphinduced bynodes.static <N> ImmutableSet<N> reachableNodes(Graph<N> graph, N node) Returns the set of nodes that are reachable fromnode.static <N> ImmutableGraph<N> transitiveClosure(Graph<N> graph) Returns the transitive closure ofgraph.static <N> Graph<N> Returns a view ofgraphwith the direction (if any) of every edge reversed.static <N,E> Network <N, E> Returns a view ofnetworkwith the direction (if any) of every edge reversed.static <N,V> ValueGraph <N, V> transpose(ValueGraph<N, V> graph) Returns a view ofgraphwith the direction (if any) of every edge reversed.
-
Method Details
-
hasCycle
Returns true ifgraphhas at least one cycle. A cycle is defined as a non-empty subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges) starting and ending with the same node.This method will detect any non-empty cycle, including self-loops (a cycle of length 1).
-
hasCycle
Returns true ifnetworkhas at least one cycle. A cycle is defined as a non-empty subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges) starting and ending with the same node.This method will detect any non-empty cycle, including self-loops (a cycle of length 1).
-
transitiveClosure
Returns the transitive closure ofgraph. The transitive closure of a graph is another graph with an edge connecting node A to node B if node B isreachablefrom node A.This is a "snapshot" based on the current topology of
graph, rather than a live view of the transitive closure ofgraph. In other words, the returnedGraphwill not be updated after modifications tograph.- Since:
- 33.1.0 (present with return type
Graphsince 20.0)
-
reachableNodes
Returns the set of nodes that are reachable fromnode. Specifically, it returns all nodesvsuch that there exists a path (a sequence of adjacent outgoing edges) starting atnodeand ending atv. This implementation includesnodeas the first element in the result.If needed, the
Traverserclass provides more flexible and lighter-weight ways to list the nodes reachable from a given node or nodes. See the "Graph traversal" section of the Guava User's Guide for more information.The
Setreturned is a "snapshot" based on the current topology ofgraph, rather than a live view. In other words, modifications tographmade after this method returns will not be reflected in the set.- Throws:
IllegalArgumentException- ifnodeis not present ingraph- Since:
- 33.1.0 (present with return type
Setsince 20.0)
-
transpose
-
transpose
Returns a view ofgraphwith the direction (if any) of every edge reversed. All other properties remain intact, and further updates tographwill be reflected in the view. -
transpose
-
inducedSubgraph
Returns the subgraph ofgraphinduced bynodes. This subgraph is a new graph that contains all of the nodes innodes, and all of theedgesfromgraphfor which both nodes are contained bynodes.- Throws:
IllegalArgumentException- if any element innodesis not a node in the graph
-
inducedSubgraph
public static <N,V> MutableValueGraph<N,V> inducedSubgraph(ValueGraph<N, V> graph, Iterable<? extends N> nodes) Returns the subgraph ofgraphinduced bynodes. This subgraph is a new graph that contains all of the nodes innodes, and all of theedges(and associated edge values) fromgraphfor which both nodes are contained bynodes.- Throws:
IllegalArgumentException- if any element innodesis not a node in the graph
-
inducedSubgraph
public static <N,E> MutableNetwork<N,E> inducedSubgraph(Network<N, E> network, Iterable<? extends N> nodes) Returns the subgraph ofnetworkinduced bynodes. This subgraph is a new graph that contains all of the nodes innodes, and all of theedgesfromnetworkfor which theincident nodesare both contained bynodes.- Throws:
IllegalArgumentException- if any element innodesis not a node in the graph
-
copyOf
Creates a mutable copy ofgraphwith the same nodes and edges. -
copyOf
Creates a mutable copy ofgraphwith the same nodes, edges, and edge values. -
copyOf
Creates a mutable copy ofnetworkwith the same nodes and edges.
-