Class GuavaMutableValueGraphAdapter<V,E,ValueT>
- java.lang.Object
-
- com.google.common.graph.AbstractValueGraph<V,ValueT>
-
- com.jgalgo.adapt.guava.GuavaValueGraphAdapter<V,E,ValueT>
-
- com.jgalgo.adapt.guava.GuavaMutableValueGraphAdapter<V,E,ValueT>
-
- Type Parameters:
V
- the vertices typeE
- the edges typeValueT
- the values type
- All Implemented Interfaces:
MutableValueGraph<V,ValueT>
,PredecessorsFunction<V>
,SuccessorsFunction<V>
,ValueGraph<V,ValueT>
public class GuavaMutableValueGraphAdapter<V,E,ValueT> extends GuavaValueGraphAdapter<V,E,ValueT> implements MutableValueGraph<V,ValueT>
An adapter from a JGAlgo graph to a mutable Guava value graph.The adapter is constructed with a JGAlgo graph and implements the mutable Guava value 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 Guava value graph. If mutability is not required, consider using the immutable adapter instead.
Parallel edges are not supported by Guava value 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.
The Guava value graph represent connections between nodes with value for each connection. Each connection has a non unique value, similar to a map from the endpoints to the value. The values of the edges are represented as weights in the underlying JGAlgo graph, and the weights key is passed in the constructor, see Graph.edgesWeights(String). The type of the value is specified as a generic
ValueT
parameter. The edge generic typeE
is not reflected in the Guava graph, and is only used 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.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.
Among Guava
Graph
,ValueGraph
andNetwork
, 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:
Graph
,MutableValueGraph
,GuavaValueGraphAdapter
-
-
Constructor Summary
Constructors Constructor Description GuavaMutableValueGraphAdapter(Graph<V,E> graph, String edgeWeightKey)
Constructs a new adapter from the given JGAlgo graph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addNode(V node)
ValueT
putEdgeValue(EndpointPair<V> endpoints, ValueT value)
ValueT
putEdgeValue(V nodeU, V nodeV, ValueT value)
ValueT
removeEdge(EndpointPair<V> endpoints)
ValueT
removeEdge(V nodeU, V nodeV)
boolean
removeNode(V node)
-
Methods inherited from class com.jgalgo.adapt.guava.GuavaValueGraphAdapter
adjacentNodes, allowsSelfLoops, asGraph, degree, edges, edgeValueOrDefault, edgeValueOrDefault, hasEdgeConnecting, hasEdgeConnecting, incidentEdgeOrder, incidentEdges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
-
Methods inherited from class com.google.common.graph.AbstractValueGraph
edgeValue, edgeValue, equals, hashCode, toString
-
Methods inherited from interface com.google.common.graph.ValueGraph
adjacentNodes, allowsSelfLoops, asGraph, degree, edges, edgeValue, edgeValue, edgeValueOrDefault, edgeValueOrDefault, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, incidentEdgeOrder, incidentEdges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
-
-
-
-
Constructor Detail
-
GuavaMutableValueGraphAdapter
public GuavaMutableValueGraphAdapter(Graph<V,E> graph, String edgeWeightKey)
Constructs a new 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 graphedgeWeightKey
- the key of the weights of the edges, which are the values of the value graph- Throws:
IllegalArgumentException
- if the graph does not have edge builder or if the graph does not contain edge weights for the given keyUnsupportedOperationException
- if the graph allows parallel edges
-
-
Method Detail
-
addNode
public boolean addNode(V node)
- Specified by:
addNode
in interfaceMutableValueGraph<V,E>
-
putEdgeValue
public ValueT putEdgeValue(V nodeU, V nodeV, ValueT value)
- Specified by:
putEdgeValue
in interfaceMutableValueGraph<V,E>
-
putEdgeValue
public ValueT putEdgeValue(EndpointPair<V> endpoints, ValueT value)
- Specified by:
putEdgeValue
in interfaceMutableValueGraph<V,E>
-
removeNode
public boolean removeNode(V node)
- Specified by:
removeNode
in interfaceMutableValueGraph<V,E>
-
removeEdge
public ValueT removeEdge(V nodeU, V nodeV)
- Specified by:
removeEdge
in interfaceMutableValueGraph<V,E>
-
removeEdge
public ValueT removeEdge(EndpointPair<V> endpoints)
- Specified by:
removeEdge
in interfaceMutableValueGraph<V,E>
-
-