|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectMysteryWeightedGraphImplementation
public class MysteryWeightedGraphImplementation
An implementation of the Weighted Graph ADT. This class can represent both directed and undirected graphs, but the choice must be made at construction time, and is final. Another choice that must be made at construction time is that of the "sentinel" value for weights. This is the value that getWeight() returns for edges that are not in the graph. The default is Double.POSITIVE_INFINITY, but other common choices are negative infinity, zero, or NaN. Technically, this implementation supports self-loops; it makes no effort to prevent these. Any method that takes one or more vertex IDs as arguments may throw an IndexOutOfBoundsException if any input ID is out of bounds.
Constructor Summary | |
---|---|
MysteryWeightedGraphImplementation()
Default constructor: an empty directed graph. |
|
MysteryWeightedGraphImplementation(boolean directed)
Constructs an empty graph with the specified directedness, with a sentinel value of Double.POSITIVE_INFINITY. |
|
MysteryWeightedGraphImplementation(boolean directed,
int N)
Constructs a graph with N vertices and the specified directedness, with a sentinel value of Double.POSITIVE_INFINITY. |
|
MysteryWeightedGraphImplementation(boolean directed,
int N,
double sentinel)
Constructs a graph with N vertices and the specified directedness and sentinel value. |
Method Summary | |
---|---|
boolean |
addEdge(int begin,
int end,
double weight)
Adds a weighted edge between two vertices. |
int |
addVertex()
Adds a new vertex. |
void |
clear()
Removes all vertices and edges from the graph. |
int |
getDegree(int v)
Returns the out-degree of the specified vertex. |
int |
getInDegree(int v)
Returns the in-degree of the specified vertex. |
java.lang.Iterable<java.lang.Integer> |
getNeighbors(int v)
Returns an iterator over the neighbors of the specified vertex. |
double |
getWeight(int begin,
int end)
Gets the weight of the edge between two vertices. |
boolean |
hasEdge(int begin,
int end)
Checks whether an edge exists between two vertices. |
boolean |
isDirected()
Returns true if the graph is directed. |
boolean |
isEmpty()
Returns true if there are no vertices in the graph. |
double |
missingEdgeSentinel()
Returns the "sentinel" weight value for edges not in the graph. |
int |
numEdges()
Returns the number of edges in the graph. |
int |
numVerts()
Returns the number of vertices in the graph. |
boolean |
setWeight(int begin,
int end,
double weight)
Sets the weight of an edge already in the graph. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MysteryWeightedGraphImplementation()
public MysteryWeightedGraphImplementation(boolean directed)
public MysteryWeightedGraphImplementation(boolean directed, int N)
public MysteryWeightedGraphImplementation(boolean directed, int N, double sentinel)
Method Detail |
---|
public int addVertex()
addVertex
in interface Graph
public boolean addEdge(int begin, int end, double weight)
addEdge
in interface WeightedGraph
public boolean hasEdge(int begin, int end)
hasEdge
in interface Graph
public boolean setWeight(int begin, int end, double weight)
setWeight
in interface WeightedGraph
public double getWeight(int begin, int end)
getWeight
in interface WeightedGraph
public int getDegree(int v)
getDegree
in interface Graph
public int getInDegree(int v)
getInDegree
in interface Graph
public java.lang.Iterable<java.lang.Integer> getNeighbors(int v)
getNeighbors
in interface Graph
public int numVerts()
numVerts
in interface Graph
public int numEdges()
numEdges
in interface Graph
public boolean isDirected()
isDirected
in interface Graph
public boolean isEmpty()
isEmpty
in interface Graph
public void clear()
clear
in interface Graph
public double missingEdgeSentinel()
missingEdgeSentinel
in interface WeightedGraph
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |