Modifier and Type | Method and Description |
---|---|
static <N> MutableGraph<N> |
copyOf(Graph<N> graph)
Creates a mutable copy of
graph with the same nodes and edges. |
static <N,E> MutableNetwork<N,E> |
copyOf(Network<N,E> network)
Creates a mutable copy of
network with the same nodes and edges. |
static <N,V> MutableValueGraph<N,V> |
copyOf(ValueGraph<N,V> graph)
Creates a mutable copy of
graph with the same nodes, edges, and edge values. |
static boolean |
equivalent(Graph<?> graphA,
Graph<?> graphB)
Returns
true if graphA and graphB have the same elements and the same
relationships between elements, as exposed via the Graph interface. |
static boolean |
equivalent(Network<?,?> networkA,
Network<?,?> networkB)
Returns
true if networkA and networkB have the same elements and the
same relationships between elements, as exposed via the Network interface. |
static boolean |
equivalent(ValueGraph<?,?> graphA,
ValueGraph<?,?> graphB)
Returns
true if graphA and graphB have the same elements (including
edge values) and the same relationships between elements, as exposed via the ValueGraph
interface. |
static boolean |
hasCycle(Graph<?> graph)
Returns true if
graph has at least one cycle. |
static boolean |
hasCycle(Network<?,?> network)
Returns true if
network has at least one cycle. |
static <N> MutableGraph<N> |
inducedSubgraph(Graph<N> graph,
Iterable<? extends N> nodes)
Returns the subgraph of
graph induced by nodes . |
static <N,E> MutableNetwork<N,E> |
inducedSubgraph(Network<N,E> network,
Iterable<? extends N> nodes)
Returns the subgraph of
network induced by nodes . |
static <N,V> MutableValueGraph<N,V> |
inducedSubgraph(ValueGraph<N,V> graph,
Iterable<? extends N> nodes)
Returns the subgraph of
graph induced by nodes . |
static <N> Set<N> |
reachableNodes(Graph<N> graph,
Object node)
Returns the set of nodes that are reachable from
node . |
static <N> Graph<N> |
transitiveClosure(Graph<N> graph)
Returns the transitive closure of
graph . |
static <N> Graph<N> |
transpose(Graph<N> graph)
Returns a view of
graph with the direction (if any) of every edge reversed. |
static <N,E> Network<N,E> |
transpose(Network<N,E> network)
Returns a view of
network with the direction (if any) of every edge reversed. |
static <N,V> ValueGraph<N,V> |
transpose(ValueGraph<N,V> graph)
Returns a view of
graph with the direction (if any) of every edge reversed. |
public static boolean hasCycle(Graph<?> graph)
graph
has 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).
public static boolean hasCycle(Network<?,?> network)
network
has 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).
public static <N> Graph<N> transitiveClosure(Graph<N> graph)
graph
. The transitive closure of a graph is another
graph with an edge connecting node A to node B if node B is reachable
from node A.
This is a "snapshot" based on the current topology of graph
, rather than a live view
of the transitive closure of graph
. In other words, the returned Graph
will not
be updated after modifications to graph
.
public static <N> Set<N> reachableNodes(Graph<N> graph, Object node)
node
. Node B is defined as reachable
from node A if there exists a path (a sequence of adjacent outgoing edges) starting at node A
and ending at node B. Note that a node is always reachable from itself via a zero-length path.
This is a "snapshot" based on the current topology of graph
, rather than a live view
of the set of nodes reachable from node
. In other words, the returned Set
will
not be updated after modifications to graph
.
IllegalArgumentException
- if node
is not present in graph
public static boolean equivalent(@Nullable Graph<?> graphA, @Nullable Graph<?> graphB)
true
if graphA
and graphB
have the same elements and the same
relationships between elements, as exposed via the Graph
interface.
Thus, two graphs A and B are equivalent if both are null or all of the following are true:
directedness
.
node sets
.
edge sets
.
Graph properties besides directedness
do not affect
equivalence. For example, two graphs may be considered equivalent even if one allows self-loops
and the other doesn't. Additionally, the order in which nodes or edges are added to the graph,
and the order in which they are iterated over, are irrelevant.
public static boolean equivalent(@Nullable ValueGraph<?,?> graphA, @Nullable ValueGraph<?,?> graphB)
true
if graphA
and graphB
have the same elements (including
edge values) and the same relationships between elements, as exposed via the ValueGraph
interface.
Thus, two value graphs A and B are equivalent if both are null or all of the following are true:
directedness
.
node sets
.
edge sets
.
value
equal to the value
of the corresponding edge in B.
Graph properties besides directedness
do not affect
equivalence. For example, two graphs may be considered equivalent even if one allows self-loops
and the other doesn't. Additionally, the order in which nodes or edges are added to the graph,
and the order in which they are iterated over, are irrelevant.
public static boolean equivalent(@Nullable Network<?,?> networkA, @Nullable Network<?,?> networkB)
true
if networkA
and networkB
have the same elements and the
same relationships between elements, as exposed via the Network
interface.
Thus, two networks A and B are equivalent if both are null or all of the following are true:
directedness
.
node sets
.
edge sets
.
Network properties besides directedness
do not affect
equivalence. For example, two networks may be considered equal even if one allows parallel
edges and the other doesn't. Additionally, the order in which nodes or edges are added to the
network, and the order in which they are iterated over, are irrelevant.
public static <N> Graph<N> transpose(Graph<N> graph)
graph
with the direction (if any) of every edge reversed. All other
properties remain intact, and further updates to graph
will be reflected in the view.public static <N,V> ValueGraph<N,V> transpose(ValueGraph<N,V> graph)
graph
with the direction (if any) of every edge reversed. All other
properties remain intact, and further updates to graph
will be reflected in the view.public static <N,E> Network<N,E> transpose(Network<N,E> network)
network
with the direction (if any) of every edge reversed. All other
properties remain intact, and further updates to network
will be reflected in the view.public static <N> MutableGraph<N> inducedSubgraph(Graph<N> graph, Iterable<? extends N> nodes)
graph
induced by nodes
. This subgraph is a new graph
that contains all of the nodes in nodes
, and all of the edges
from graph
for which both nodes are contained by nodes
.IllegalArgumentException
- if any element in nodes
is not a node in the graphpublic static <N,V> MutableValueGraph<N,V> inducedSubgraph(ValueGraph<N,V> graph, Iterable<? extends N> nodes)
graph
induced by nodes
. This subgraph is a new graph
that contains all of the nodes in nodes
, and all of the edges
(and associated edge values) from graph
for which both nodes are contained by nodes
.IllegalArgumentException
- if any element in nodes
is not a node in the graphpublic static <N,E> MutableNetwork<N,E> inducedSubgraph(Network<N,E> network, Iterable<? extends N> nodes)
network
induced by nodes
. This subgraph is a new graph
that contains all of the nodes in nodes
, and all of the edges
from network
for which the incident nodes
are
both contained by nodes
.IllegalArgumentException
- if any element in nodes
is not a node in the graphpublic static <N> MutableGraph<N> copyOf(Graph<N> graph)
graph
with the same nodes and edges.public static <N,V> MutableValueGraph<N,V> copyOf(ValueGraph<N,V> graph)
graph
with the same nodes, edges, and edge values.public static <N,E> MutableNetwork<N,E> copyOf(Network<N,E> network)
network
with the same nodes and edges.Copyright © 2010-2017. All Rights Reserved.