Class MutableDoubleValueGraphAdapter<V>

java.lang.Object
org.jgrapht.graph.AbstractGraph<V,com.google.common.graph.EndpointPair<V>>
org.jgrapht.graph.guava.BaseValueGraphAdapter<V,Double,com.google.common.graph.MutableValueGraph<V,Double>>
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's MutableValueGraph 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 resulting Graph. Thus, the graph is weighted and calling methods Graph.getEdgeWeight(Object) and setEdgeWeight(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:
  • Constructor Details

    • MutableDoubleValueGraphAdapter

      public MutableDoubleValueGraphAdapter(com.google.common.graph.MutableValueGraph<V,Double> valueGraph)
      Create a new adapter.
      Parameters:
      valueGraph - the value graph
      Throws:
      NullPointerException - if valueGraph is null
    • 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 graph
      vertexSupplier - the vertex supplier
      edgeSupplier - the edge supplier
      Throws:
      NullPointerException - if valueGraph is null
  • Method Details