- java.lang.Object
-
- org.jgrapht.graph.AbstractGraph<V,com.google.common.graph.EndpointPair<V>>
-
- org.jgrapht.graph.guava.BaseValueGraphAdapter<V,W,com.google.common.graph.MutableValueGraph<V,W>>
-
- org.jgrapht.graph.guava.MutableValueGraphAdapter<V,Double>
-
- org.jgrapht.graph.guava.MutableDoubleValueGraphAdapter<V>
-
- Type Parameters:
V
- the graph vertex type
- All Implemented Interfaces:
Serializable
,Cloneable
,Graph<V,com.google.common.graph.EndpointPair<V>>
public class MutableDoubleValueGraphAdapter<V> extends MutableValueGraphAdapter<V,Double>
A graph adapter class using Guava'sMutableValueGraph
specialized with double values.The adapter uses class
EndpointPair
to represent edges. Changes in the adapter such as adding or removing vertices and edges are reflected in the underlying value graph.Each edge in
MutableValueGraph
is associated with a double value which is mapped to the edge weight in the resultingGraph
. Thus, the graph is weighted and calling methodsGraph.getEdgeWeight(Object)
andsetEdgeWeight(EndpointPair, double)
will get and set the value of an edge.See the example below on how to create such an adapter:
MutableValueGraph<String, Double> mutableValueGraph = ValueGraphBuilder.directed().allowsSelfLoops(true).build(); mutableValueGraph.addNode("v1"); mutableValueGraph.addNode("v2"); mutableValueGraph.putEdgeValue("v1", "v2", 3.0); Graph<String, EndpointPair<String>> graph = new MutableDoubleValueGraphAdapter<>(mutableValueGraph); System.out.println(graph.getEdgeWeight(EndpointPair.ordered("v1", "v2")); // outputs 3.0 graph.setEdgeWeight(EndpointPair.ordered("v1", "v2"), 7.0); System.out.println(graph.getEdgeWeight(EndpointPair.ordered("v1", "v2")); // outputs 7.0
- Author:
- Dimitrios Michail
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.jgrapht.graph.guava.MutableValueGraphAdapter
defaultValue
-
Fields inherited from class org.jgrapht.graph.guava.BaseValueGraphAdapter
edgeSupplier, LOOPS_NOT_ALLOWED, unmodifiableEdgeSet, unmodifiableVertexSet, valueConverter, valueGraph, vertexOrder, vertexOrderMethod, vertexSupplier
-
Fields inherited from interface org.jgrapht.Graph
DEFAULT_EDGE_WEIGHT
-
-
Constructor Summary
Constructors Constructor Description MutableDoubleValueGraphAdapter(com.google.common.graph.MutableValueGraph<V,Double> valueGraph)
Create a new adapter.MutableDoubleValueGraphAdapter(com.google.common.graph.MutableValueGraph<V,Double> valueGraph, Supplier<V> vertexSupplier, Supplier<com.google.common.graph.EndpointPair<V>> edgeSupplier)
Create a new adapter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
setEdgeWeight(com.google.common.graph.EndpointPair<V> e, double weight)
Assigns a weight to an edge.-
Methods inherited from class org.jgrapht.graph.guava.MutableValueGraphAdapter
addEdge, addEdge, addVertex, addVertex, clone, removeEdge, removeEdge, removeVertex
-
Methods inherited from class org.jgrapht.graph.guava.BaseValueGraphAdapter
containsEdge, containsVertex, createVertexOrder, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeSource, getEdgeSupplier, getEdgeTarget, getEdgeWeight, getType, getVertexSupplier, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, setEdgeSupplier, setVertexSupplier, vertexSet
-
Methods inherited from class org.jgrapht.graph.AbstractGraph
assertVertexExist, containsEdge, equals, hashCode, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jgrapht.Graph
containsEdge, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeSource, getEdgeSupplier, getEdgeTarget, getEdgeWeight, getType, getVertexSupplier, incomingEdgesOf, inDegreeOf, iterables, outDegreeOf, outgoingEdgesOf, removeAllEdges, removeAllEdges, removeAllVertices, setEdgeWeight, vertexSet
-
-
-
-
Constructor Detail
-
MutableDoubleValueGraphAdapter
public MutableDoubleValueGraphAdapter(com.google.common.graph.MutableValueGraph<V,Double> valueGraph)
Create a new adapter.- Parameters:
valueGraph
- the value graph- Throws:
NullPointerException
- ifvalueGraph
isnull
-
MutableDoubleValueGraphAdapter
public MutableDoubleValueGraphAdapter(com.google.common.graph.MutableValueGraph<V,Double> valueGraph, Supplier<V> vertexSupplier, Supplier<com.google.common.graph.EndpointPair<V>> edgeSupplier)
Create a new adapter.- Parameters:
valueGraph
- the value graphvertexSupplier
- the vertex supplieredgeSupplier
- the edge supplier- Throws:
NullPointerException
- ifvalueGraph
isnull
-
-
Method Detail
-
setEdgeWeight
public void setEdgeWeight(com.google.common.graph.EndpointPair<V> e, double weight)
Description copied from class:MutableValueGraphAdapter
Assigns a weight to an edge. This method always throws anUnsupportedOperationException
since the adapter works one-way from values to weights. Adjusting the weights can be done by adjusting the values in the underlyingValueGraph
which will automatically be propagated using the provided converter.- Specified by:
setEdgeWeight
in interfaceGraph<V,com.google.common.graph.EndpointPair<V>>
- Overrides:
setEdgeWeight
in classMutableValueGraphAdapter<V,Double>
- Parameters:
e
- edge on which to set weightweight
- new weight for edge- Throws:
IllegalArgumentException
- ife
is not an edge of this graphNullPointerException
- ife
isnull
-
-