Overview | Package | Class | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jgrapht.graph
Class AsWeightedGraph<V,E>

    java.lang.Object
      org.jgrapht.graph.AbstractGraph<V,E>
          org.jgrapht.graph.GraphDelegator<V,E>
              org.jgrapht.graph.AsWeightedGraph<V,E>

All Implemented Interfaces:
  java.io.Serializable, Graph<V,E>, WeightedGraph<V,E>

    public class AsWeightedGraph<V,E>

extends GraphDelegator<V,E>
implements java.io.Serializable, WeightedGraph<V,E>

A weighted view of the backing graph specified in the constructor. This graph allows modules to apply algorithms designed for weighted graphs to an unweighted graph by providing an explicit edge weight mapping. The implementation also allows for "masking" weights for a subset of the edges in an existing weighted graph.

Query operations on this graph "read through" to the backing graph. Vertex addition/removal and edge addition/removal are all supported (and immediately reflected in the backing graph). Setting an edge weight will pass the operation to the backing graph as well if the backing graph implements the WeightedGraph interface. Setting an edge weight will modify the weight map in order to maintain a consistent graph.

Note that edges returned by this graph's accessors are really just the edges of the underlying directed graph.

This graph does not pass the hashCode and equals operations through to the backing graph, but relies on `Object`'s `equals` and `hashCode` methods. This graph will be serializable if the backing graph is serializable.

Since:
  Sep 10, 2007
Author:
  Lucas J. Scharenbroich
See Also:
  Serialized Form

Field Summary
`protected java.util.Map<E,java.lang.Double>` | `weightMap`

Fields inherited from interface org.jgrapht.WeightedGraph
`DEFAULT_EDGE_WEIGHT`

Constructor Summary
`AsWeightedGraph(Graph<V,E> g, java.util.Map<E,java.lang.Double> weightMap)` Constructor for AsWeightedGraph.

Method Summary
`double` | `getEdgeWeight(E e)` Returns the weight assigned to a given edge.
`void` | `setEdgeWeight(E e, double weight)` Assigns a weight to an edge.

Methods inherited from class org.jgrapht.graph.GraphDelegator
`addEdge, addEdge, addVertex, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, toString, vertexSet`

Methods inherited from class org.jgrapht.graph.AbstractGraph
`assertVertexExist, containsEdge, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.jgrapht.Graph
`addEdge, addEdge, addVertex, containsEdge, containsEdge, containsVertex, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeFactory, getEdgeSource, getEdgeTarget, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, vertexSet`

Field Detail

### weightMap

    protected final java.util.Map<E,java.lang.Double> weightMap

Constructor Detail

### AsWeightedGraph

    public AsWeightedGraph(Graph<V,E> g,
                           java.util.Map<E,java.lang.Double> weightMap)

  Constructor for AsWeightedGraph.

  Parameters:
    `g` - the backing graph over which a weighted view is to be created.
    `weightMap` - A mapping of edges to weights. If an edge is not present in the weight map, the edge weight for the underlying graph is returned. Note that a live reference to this map is retained, so if the caller changes the map after construction, the changes will affect the AsWeightedGraph instance as well.

Method Detail

### setEdgeWeight

    public void setEdgeWeight(E e,
                              double weight)

  Description copied from interface: `WeightedGraph`
  Assigns a weight to an edge.

  Specified by:
    `setEdgeWeight` in interface `WeightedGraph<V,E>`
  Overrides:
    `setEdgeWeight` in class `GraphDelegator<V,E>`
  Parameters:
    `e` - edge on which to set weight
    `weight` - new weight for edge
  See Also:
    `WeightedGraph.setEdgeWeight(E, double)`

### getEdgeWeight

    public double getEdgeWeight(E e)

  Description copied from interface: `Graph`
  Returns the weight assigned to a given edge. Unweighted graphs return 1.0 (as defined by `WeightedGraph.DEFAULT_EDGE_WEIGHT`), allowing weighted-graph algorithms to apply to them where meaningful.

  Specified by:
    `getEdgeWeight` in interface `Graph<V,E>`
  Overrides:
    `getEdgeWeight` in class `GraphDelegator<V,E>`
  Parameters:
    `e` - edge of interest
  Returns:
    edge weight
  See Also:
    `Graph.getEdgeWeight(E)`

Overview | Package | Class | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD