Interface WeightedGraph

All Superinterfaces:
Graph
All Known Implementing Classes:
MysteryWeightedGraphImplementation

public interface WeightedGraph
extends Graph

An interface for weighted graphs. For more discussion of the structure and use of this interface, see the Graph interface. The return value of getWeight() may be a "sentinel" value that indicates the requested edge is absent from the graph. Typical sentinels include positive or negative infinity, zero, or NaN. Classes that implement this interface should specify what sentinel value they use, or allow the user to choose their own sentinel. Note that any of these methods may throw an IndexOutOfBoundsException if any of the input vertex IDs are out of bounds.


Method Summary
 boolean addEdge(int begin, int end, double weight)
          Adds a weighted edge between two vertices.
 double getWeight(int begin, int end)
          Gets the weight of the edge between two vertices.
 double missingEdgeSentinel()
          Returns the "sentinel" weight value for edges not in the graph.
 boolean setWeight(int begin, int end, double weight)
          Sets the weight of an edge already in the graph.
 
Methods inherited from interface Graph
addVertex, clear, getDegree, getInDegree, getNeighbors, hasEdge, isDirected, isEmpty, numEdges, numVerts
 

Method Detail

addEdge

boolean addEdge(int begin,
                int end,
                double weight)
Adds a weighted edge between two vertices. In an undirected graph, this has the same effect as addEdge(end, begin, weight).

Returns:
false if the edge was already in the graph.

setWeight

boolean setWeight(int begin,
                  int end,
                  double weight)
Sets the weight of an edge already in the graph.

Returns:
false if the edge is not in the graph.

getWeight

double getWeight(int begin,
                 int end)
Gets the weight of the edge between two vertices. In an undirected graph, this returns the same as getWeight(end, begin).

Returns:
the weight of the edge from begin to end, or the sentinel value if no such edge exists.

missingEdgeSentinel

double missingEdgeSentinel()
Returns the "sentinel" weight value for edges not in the graph.