edu.stanford.math.plex4.graph
public class UndirectedWeightedListGraph extends java.lang.Object implements AbstractWeightedUndirectedGraph
Constructor and Description |
---|
UndirectedWeightedListGraph(int numVertices)
Constructor which initializes the graph to consist of disconnected
vertices.
|
Modifier and Type | Method and Description |
---|---|
void |
addEdge(int i,
int j)
This function adds the edge (i, j) to the graph.
|
void |
addEdge(int i,
int j,
double weight)
This function adds an edge with specified weight.
|
boolean |
containsEdge(int i,
int j)
This function returns true if the edge (i, j) is in the graph,
and false otherwise.
|
int |
getDegree(int v) |
int[] |
getDegreeSequence() |
gnu.trove.TIntHashSet |
getLowerNeighbors(int i)
This function returns the set of neighbors of vertex i in the graph
which have indices less than i.
|
int[] |
getNeighbors(int v) |
int |
getNumEdges()
Gets the number of edges in the graph.
|
int |
getNumVertices()
Gets the number of vertices in the graph.
|
gnu.trove.TIntObjectHashMap<gnu.trove.TIntHashSet> |
getUnweightedAdjacencySets() |
double |
getWeight(int i,
int j)
This function returns the weight of the edge (i, j).
|
java.util.Iterator<edu.stanford.math.primitivelib.autogen.pair.IntIntPair> |
iterator()
This function returns an edge iterator that allows the user to
iterate over the set of edges in the graph.
|
void |
removeEdge(int i,
int j)
This function removes the edge (i, j) from the graph.
|
UndirectedListGraph |
toUnweightedGraph() |
public UndirectedWeightedListGraph(int numVertices)
numVertices
- the number of vertices to initialize the graph withpublic void addEdge(int i, int j, double weight)
AbstractWeightedUndirectedGraph
addEdge
in interface AbstractWeightedUndirectedGraph
i
- the index of the first vertex of the edgej
- the index of the second vertex of the edgeweight
- the weight of the edgepublic double getWeight(int i, int j)
AbstractWeightedUndirectedGraph
getWeight
in interface AbstractWeightedUndirectedGraph
i
- the index of the first vertex of the edgej
- the index of the second vertex of the edgepublic void addEdge(int i, int j)
AbstractUndirectedGraph
addEdge
in interface AbstractUndirectedGraph
i
- the first vertex of the edge to addj
- the second vertex of the edge to addpublic boolean containsEdge(int i, int j)
AbstractUndirectedGraph
containsEdge
in interface AbstractUndirectedGraph
i
- the first vertex of the edgej
- the second vertex of the edgepublic int getNumEdges()
AbstractUndirectedGraph
getNumEdges
in interface AbstractUndirectedGraph
public int getNumVertices()
AbstractUndirectedGraph
getNumVertices
in interface AbstractUndirectedGraph
public void removeEdge(int i, int j)
AbstractUndirectedGraph
removeEdge
in interface AbstractUndirectedGraph
i
- the first vertex of the edge to addj
- the second vertex of the edge to addpublic gnu.trove.TIntHashSet getLowerNeighbors(int i)
getLowerNeighbors
in interface AbstractUndirectedGraph
i
- the vertex to querypublic gnu.trove.TIntObjectHashMap<gnu.trove.TIntHashSet> getUnweightedAdjacencySets()
public UndirectedListGraph toUnweightedGraph()
public java.util.Iterator<edu.stanford.math.primitivelib.autogen.pair.IntIntPair> iterator()
AbstractUndirectedGraph
iterator
in interface AbstractUndirectedGraph
iterator
in interface java.lang.Iterable<edu.stanford.math.primitivelib.autogen.pair.IntIntPair>
public int getDegree(int v)
getDegree
in interface AbstractUndirectedGraph
public int[] getDegreeSequence()
getDegreeSequence
in interface AbstractUndirectedGraph
public int[] getNeighbors(int v)
getNeighbors
in interface AbstractUndirectedGraph