Class GuavaMutableGraphAdapter<V,E>
- Type Parameters:
V
- the vertices typeE
- the edges type
- All Implemented Interfaces:
Graph<V>
,MutableGraph<V>
,PredecessorsFunction<V>
,SuccessorsFunction<V>
The adapter is constructed with a JGAlgo graph and implements the mutable Guava graph interface, and can be used with any Guava algorithm. The adapter is a live view, so any change in the JGAlgo graph is reflected in the Guava graph and vice versa, but the underlying JGAlgo graph should not be modified directly.
The mutable Guava graph is a mutable variant of the basic Guava graph. If mutability is not required, consider using the immutable adapter instead.
Parallel edges are not supported by Guava basic graph, therefore the adapter will throw an UnsupportedOperationException if the underlying JGAlgo graph allows parallel edges. Whether this graph is directed or not, and whether it support self edges or not, is determined by the underlying JGAlgo graph.
Guava support different element orders for the nodes and the incident edges. This adapter uses the default element order, which is unordered, and cannot be changed as the underlying JGAlgo graph does not support any other order.
The basic Guava graph only represent connections between nodes, without
addressing the edges themselves. The edge generic type E
is not reflected in the Guava graph, and is only
internally for safe access to the underlying JGAlgo graph. To create new connections (edges) in the graph, the
adapter must be able to create a new identifier for the created edge in the JGAlgo graph. This is done via the
edge builder, which is a requirement for creating a mutable
adapter.
Among Guava Graph
, ValueGraph
and
Network
, the network is the most similar to JGAlgo graphs, as vertices and edges have
unique identifiers, and queries of edges are answered with the edges identifiers. On the other had, the Graph and
ValueGraph do not support unique identifiers for the edges, and operations on edges are addressed by a pair of nodes.
The ValueGraph does associate a value with each edge, be it does not have to be unique, and it is more similar to
weights in JGAlgo graphs.
For adapting the other way around, from Guava to JGAlgo, only from Guava
Network is supported, see GuavaNetworkWrapper
.
- Author:
- Barak Ugav
- See Also:
-
Constructor Summary
ConstructorDescriptionGuavaMutableGraphAdapter
(Graph<V, E> graph) Constructs a new mutable adapter from the given JGAlgo graph. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
putEdge
(EndpointPair<V> endpoints) boolean
boolean
removeEdge
(EndpointPair<V> endpoints) boolean
removeEdge
(V nodeU, V nodeV) boolean
removeNode
(V node) Methods inherited from class com.jgalgo.adapt.guava.GuavaGraphAdapter
adjacentNodes, allowsSelfLoops, degree, edges, hasEdgeConnecting, hasEdgeConnecting, incidentEdgeOrder, incidentEdges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
Methods inherited from class com.google.common.graph.AbstractGraph
equals, hashCode, toString
Methods inherited from interface com.google.common.graph.Graph
adjacentNodes, allowsSelfLoops, degree, edges, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, incidentEdgeOrder, incidentEdges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
-
Constructor Details
-
GuavaMutableGraphAdapter
Constructs a new mutable adapter from the given JGAlgo graph.An edge builder is required, as the adapter will need to create edge identifiers in the JGAlgo graph to add new connections in the Guava graph.
- Parameters:
graph
- the JGAlgo graph- Throws:
UnsupportedOperationException
- if the graph allows parallel edgesIllegalArgumentException
- if the graph does not have edge builder
-
-
Method Details
-
addNode
- Specified by:
addNode
in interfaceMutableGraph<V>
-
putEdge
- Specified by:
putEdge
in interfaceMutableGraph<V>
-
putEdge
- Specified by:
putEdge
in interfaceMutableGraph<V>
-
removeNode
- Specified by:
removeNode
in interfaceMutableGraph<V>
-
removeEdge
- Specified by:
removeEdge
in interfaceMutableGraph<V>
-
removeEdge
- Specified by:
removeEdge
in interfaceMutableGraph<V>
-