|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.aitools.aq.structure.graph.UndirectedHashGraph<V>
V
- The vertices in this graph.public final class UndirectedHashGraph<V>
A general implementation for all kind of vertices. To provide fast access, each weight is of an edge is hold twice in the graph.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface de.aitools.aq.structure.graph.UndirectedGraph |
---|
UndirectedGraph.Edge<V> |
Field Summary |
---|
Fields inherited from interface de.aitools.aq.structure.graph.UndirectedGraph |
---|
DEFAULT_UNCONNECTED_WEIGHT |
Constructor Summary | |
---|---|
UndirectedHashGraph()
Create a new UndirectedHashGraph with default weight for unconnected vertices and default capacity. |
|
UndirectedHashGraph(double unconnectedWeight,
int initialCapacity)
Create a new UndirectedHashGraph. |
Method Summary | |
---|---|
boolean |
addVertex(V vertex)
Adds a vertex to the graph. |
UndirectedHashGraph<V> |
clone()
|
boolean |
containsEdge(V vertexA,
V vertexB)
Check if there exists an edge in the graph connecting the two vertices given as parameters. |
boolean |
containsVertex(V vertex)
Checks if given vertex is contained in the graph. |
UndirectedGraph.Edge<V> |
getEdge(V vertexA,
V vertexB)
Returns the Edge connecting the two vertices. |
java.util.Iterator<? extends UndirectedGraph.Edge<V>> |
getEdges()
Returns an iterator over all edges of the graph. |
java.util.Iterator<? extends UndirectedGraph.Edge<V>> |
getEdgesConnectedTo(V vertex)
Returns an iterator over all edges in the graph that are connected to given vertex |
double |
getEdgeWeight(V vertexA,
V vertexB)
Returns the weight of the edge connecting the two vertices. |
double |
getMass(V vertex)
Returns the sum of the weights of all edges connected to given vertex. |
int |
getNumberOfEdges()
Returns the number of edges. |
int |
getNumberOfEdgesConnectedTo(V vertex)
Returns the number of edges connected to given vertex. |
int |
getNumberOfVertices()
Returns the number of vertices. |
java.util.Set<UndirectedGraph.Edge<V>> |
getSetOfEdges()
|
java.util.Set<UndirectedGraph.Edge<V>> |
getSetOfEdgesConnectedTo(V vertex)
|
java.util.Set<V> |
getSetOfVertices()
|
java.util.Set<V> |
getSetOfVerticesConnectedTo(V vertex)
|
double |
getUnconnectedWeight()
Returns the default weight for unconnected vertices. |
java.util.Iterator<V> |
getVertices()
Returns an iterator over all current vertices of this graph. |
java.util.Iterator<V> |
getVerticesConnectedTo(V vertex)
Returns an iterator over all vertices that are connected with given vertex at the moment of this call. |
java.util.Iterator<V> |
iterator()
|
double |
removeEdge(V vertexA,
V vertexB)
Removes the edge determined by two vertices. |
boolean |
removeVertex(V vertex)
Remove a vertex from the graph. |
double |
setEdgeWeight(V vertexA,
V vertexB,
double weight)
Sets the weight of a edge determined by two vertices. |
void |
setUnconnectedWeight(double unconnectedWeight)
Change the weight that is returned by getEdgeWeight(Object, Object) if the two vertices are not connected. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UndirectedHashGraph()
UndirectedHashGraph
,
UndirectedGraph
,
setUnconnectedWeight(double)
,
UndirectedHashGraph(double, int)
public UndirectedHashGraph(double unconnectedWeight, int initialCapacity)
unconnectedWeight
- the weight for unconnected vertices.
Default is using UndirectedGraph#DEFAULT_UNCONNECTED_WEIGHT.initialCapacity
- the initial capacity of vertices (grows
automatically), or a negative value to use a default value.UndirectedHashGraph
,
UndirectedGraph
,
UndirectedGraph.DEFAULT_UNCONNECTED_WEIGHT
Method Detail |
---|
public double getUnconnectedWeight()
UndirectedGraph
Returns the default weight for unconnected vertices.
The method getEdgeWeight(Object, Object) returns a double value for any possible edge connecting two vertices in the graph. If an edge does not exist, the method will return this value.
getUnconnectedWeight
in interface UndirectedGraph<V>
UndirectedGraph.getEdgeWeight(Object, Object)
,
UndirectedGraph.setUnconnectedWeight(double)
public void setUnconnectedWeight(double unconnectedWeight)
UndirectedGraph
setUnconnectedWeight
in interface UndirectedGraph<V>
unconnectedWeight
- the new weight for unconnected vertices.UndirectedGraph.getEdgeWeight(Object, Object)
,
UndirectedGraph.getUnconnectedWeight()
public int getNumberOfVertices()
UndirectedGraph
getNumberOfVertices
in interface UndirectedGraph<V>
public int getNumberOfEdges()
UndirectedGraph
getNumberOfEdges
in interface UndirectedGraph<V>
public int getNumberOfEdgesConnectedTo(V vertex) throws java.lang.NullPointerException, java.util.NoSuchElementException
UndirectedGraph
getNumberOfEdgesConnectedTo
in interface UndirectedGraph<V>
vertex
- which vertex to count edges of.
java.lang.NullPointerException
- if vertex is null.
java.util.NoSuchElementException
- if the vertex is not part of the
graph.public java.util.Iterator<V> getVertices()
UndirectedGraph
getVertices
in interface UndirectedGraph<V>
Iterable.iterator()
,
UndirectedGraph.getNumberOfEdges()
public java.util.Set<V> getSetOfVertices()
public java.util.Iterator<V> getVerticesConnectedTo(V vertex) throws java.lang.NullPointerException, java.util.NoSuchElementException
UndirectedGraph
getVerticesConnectedTo
in interface UndirectedGraph<V>
vertex
- the vertex.
java.lang.NullPointerException
- if vertex is null.
java.util.NoSuchElementException
- if the vertex is not part of the
graph.UndirectedGraph.getNumberOfEdges()
public java.util.Set<V> getSetOfVerticesConnectedTo(V vertex) throws java.lang.NullPointerException, java.util.NoSuchElementException
java.lang.NullPointerException
java.util.NoSuchElementException
public java.util.Iterator<? extends UndirectedGraph.Edge<V>> getEdges()
UndirectedGraph
getEdges
in interface UndirectedGraph<V>
UndirectedGraph.getNumberOfEdges()
public java.util.Set<UndirectedGraph.Edge<V>> getSetOfEdges()
public java.util.Iterator<? extends UndirectedGraph.Edge<V>> getEdgesConnectedTo(V vertex) throws java.lang.NullPointerException, java.util.NoSuchElementException
UndirectedGraph
getEdgesConnectedTo
in interface UndirectedGraph<V>
vertex
- the vertex.
java.lang.NullPointerException
- if the vertex is null.
java.util.NoSuchElementException
- if the vertex is not part of the
graph.UndirectedGraph.getNumberOfEdges()
public java.util.Set<UndirectedGraph.Edge<V>> getSetOfEdgesConnectedTo(V vertex) throws java.lang.NullPointerException, java.util.NoSuchElementException
java.lang.NullPointerException
java.util.NoSuchElementException
public boolean containsVertex(V vertex) throws java.lang.NullPointerException
UndirectedGraph
containsVertex
in interface UndirectedGraph<V>
vertex
- the vertex to look for.
java.lang.NullPointerException
- if vertex is null.public boolean containsEdge(V vertexA, V vertexB) throws java.lang.NullPointerException, java.util.NoSuchElementException
UndirectedGraph
containsEdge
in interface UndirectedGraph<V>
vertexA
- one vertex.vertexB
- the other vertex.
java.lang.NullPointerException
- if one of the vertices is null.
java.util.NoSuchElementException
- if at least one of the vertices is not
part of the graph.public double getEdgeWeight(V vertexA, V vertexB) throws java.lang.NullPointerException, java.util.NoSuchElementException
UndirectedGraph
getEdgeWeight
in interface UndirectedGraph<V>
vertexA
- one vertex.vertexB
- the other vertex.
java.lang.NullPointerException
- if one of the vertices is null.
java.util.NoSuchElementException
- if at least one of the vertices is not
part of the graph.UndirectedGraph.containsEdge(Object, Object)
,
UndirectedGraph.getEdge(Object, Object)
,
UndirectedGraph.getUnconnectedWeight()
public UndirectedGraph.Edge<V> getEdge(V vertexA, V vertexB) throws java.lang.NullPointerException, java.util.NoSuchElementException
UndirectedGraph
getEdge
in interface UndirectedGraph<V>
vertexA
- one vertex.vertexB
- the other vertex.
java.lang.NullPointerException
- if one of the vertices is null.
java.util.NoSuchElementException
- if at least one of the vertices is not
part of the graph.UndirectedGraph.Edge
,
UndirectedGraph.containsEdge(Object, Object)
,
UndirectedGraph.getEdgeWeight(Object, Object)
public boolean addVertex(V vertex) throws java.lang.NullPointerException
UndirectedGraph
addVertex
in interface UndirectedGraph<V>
vertex
- the vertex to be added.
java.lang.NullPointerException
- if vertex is null.public boolean removeVertex(V vertex) throws java.lang.NullPointerException
UndirectedGraph
removeVertex
in interface UndirectedGraph<V>
vertex
- the vertex to be removed.
java.lang.NullPointerException
- if vertex is null.public double getMass(V vertex) throws java.lang.NullPointerException, java.util.NoSuchElementException
UndirectedGraph
getMass
in interface UndirectedGraph<V>
vertex
- the vertex.
java.lang.NullPointerException
- if vertex is null.
java.util.NoSuchElementException
- if the vertex is not part of the
graph.public double setEdgeWeight(V vertexA, V vertexB, double weight) throws java.lang.NullPointerException, java.util.NoSuchElementException
UndirectedGraph
Sets the weight of a edge determined by two vertices. If the new weight is the value returned by getUnconnectedWeight(), this is be the same as calling removeEdge(Object, Object).
The old weight of the edge is returned, which may be the same as getUnconnectedWeight(), if the edge had not existed.
setEdgeWeight
in interface UndirectedGraph<V>
vertexA
- one vertex of the edge.vertexB
- the other vertex of the edge.weight
- the new weight of the edge.
java.lang.NullPointerException
- if at least one vertex is null.
java.util.NoSuchElementException
- if at least one of the two vertices is
not a part of the graph.UndirectedGraph.containsVertex(Object)
,
UndirectedGraph.getUnconnectedWeight()
,
UndirectedGraph.getEdgeWeight(Object, Object)
,
UndirectedGraph.removeEdge(Object, Object)
public double removeEdge(V vertexA, V vertexB) throws java.lang.NullPointerException, java.util.NoSuchElementException
UndirectedGraph
removeEdge
in interface UndirectedGraph<V>
vertexA
- one vertex of the edge.vertexB
- the other vertex of the edge.
java.lang.NullPointerException
- if at least one vertex is null.
java.util.NoSuchElementException
- if at least one of the two vertices is
not a part of the graph.UndirectedGraph.containsEdge(Object, Object)
,
UndirectedGraph.containsVertex(Object)
,
UndirectedGraph.getEdgeWeight(Object, Object)
,
UndirectedGraph.getUnconnectedWeight()
,
UndirectedGraph.setEdgeWeight(Object, Object, double)
public java.util.Iterator<V> iterator()
iterator
in interface java.lang.Iterable<V>
public UndirectedHashGraph<V> clone()
clone
in interface UndirectedGraph<V>
clone
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |