de.aitools.aq.structure.graph
Interface UndirectedIntGraph

All Superinterfaces:
java.lang.Cloneable, java.io.Serializable
All Known Implementing Classes:
UndirectedIntHashGraph

public interface UndirectedIntGraph
extends java.io.Serializable, java.lang.Cloneable

An undirected weighted graph.

Version:
$Id: UndirectedIntGraph.java,v 1.1 2011/09/29 12:43:04 dogu3912 Exp $
Author:
johannes.kiesel(/\t)uni-weimar.de

Nested Class Summary
static interface UndirectedIntGraph.Edge
           A possible edge connecting two vertices of an underlying UndirectedIntGraph.
 
Field Summary
static double DEFAULT_UNCONNECTED_WEIGHT
          The default weight for two not connected vertices.
 
Method Summary
 boolean addVertex(int vertex)
          Adds a vertex to the graph.
 UndirectedIntGraph clone()
           
 boolean containsEdge(int vertexA, int vertexB)
          Checks if there exists an edge in the graph connecting the two vertices given as parameters.
 boolean containsVertex(int vertex)
          Checks if given vertex is contained in the graph.
 UndirectedIntGraph.Edge getEdge(int vertexA, int vertexB)
          Returns the Edge connecting the two vertices.
 java.util.Iterator<? extends UndirectedIntGraph.Edge> getEdges()
          Returns an iterator over all edges of the graph.
 java.util.Iterator<? extends UndirectedIntGraph.Edge> getEdgesConnectedTo(int vertex)
          Returns an iterator over all edges in the graph to which given vertex is connected to.
 double getEdgeWeight(int vertexA, int vertexB)
          Returns the weight of the edge connecting the two vertices.
 double getMass(int vertex)
          Returns the sum of the weights of all edges connected to given vertex.
 int getNumberOfEdges()
          Returns the number of edges.
 int getNumberOfEdgesConnectedTo(int vertex)
          Returns the number of edges connected to given vertex.
 int getNumberOfVertices()
          Returns the number of vertices.
 double getUnconnectedWeight()
           Returns the default weight for unconnected vertices.
 int[] getVertices()
          Returns an array containing all current vertices of this graph.
 int[] getVerticesConnectedTo(int vertex)
          Returns an array containing all vertices that are connected with given vertex at the moment of this call.
 double removeEdge(int vertexA, int vertexB)
          Removes an edge determined by two vertices.
 boolean removeVertex(int vertex)
          Removes a vertex from the graph.
 double setEdgeWeight(int vertexA, int 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(int, int) if the two vertices are not connected.
 

Field Detail

DEFAULT_UNCONNECTED_WEIGHT

static final double DEFAULT_UNCONNECTED_WEIGHT
The default weight for two not connected vertices. If an edge was removed or simply not set yet, this should by default be it's weight.

See Also:
Constant Field Values
Method Detail

setUnconnectedWeight

void setUnconnectedWeight(double unconnectedWeight)
Change the weight that is returned by getEdgeWeight(int, int) if the two vertices are not connected. This will remove all edges that currently have unconnectedWeight as their weight.

Parameters:
unconnectedWeight - the new weight for unconnected vertices.
See Also:
getEdgeWeight(int, int), getUnconnectedWeight()

getUnconnectedWeight

double getUnconnectedWeight()

Returns the default weight for unconnected vertices.

The method getEdgeWeight(int, int) 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.

Returns:
a weight for not existing edges.
See Also:
getEdgeWeight(int, int), setUnconnectedWeight(double)

getNumberOfVertices

int getNumberOfVertices()
Returns the number of vertices.

Returns:
the number of vertices in the graph.

getNumberOfEdges

int getNumberOfEdges()
Returns the number of edges.

Returns:
the number of edges in the graph.

getNumberOfEdgesConnectedTo

int getNumberOfEdgesConnectedTo(int vertex)
                                throws java.util.NoSuchElementException
Returns the number of edges connected to given vertex.

Parameters:
vertex - which vertex to count edges of.
Returns:
the number of edges this vertex is connected with.
Throws:
java.util.NoSuchElementException - if the vertex is not part of the graph.

addVertex

boolean addVertex(int vertex)
Adds a vertex to the graph.

Parameters:
vertex - the vertex to be added.
Returns:
true if the graph changed during this call. false if the graph already contained that vertex.

removeVertex

boolean removeVertex(int vertex)
Removes a vertex from the graph.

Parameters:
vertex - the vertex to be removed.
Returns:
true if the graph changed during this call. false if the graph has not contained that vertex.

getVertices

int[] getVertices()
Returns an array containing all current vertices of this graph.

Returns:
the array.
See Also:
getNumberOfVertices()

getVerticesConnectedTo

int[] getVerticesConnectedTo(int vertex)
                             throws java.util.NoSuchElementException
Returns an array containing all vertices that are connected with given vertex at the moment of this call.

Parameters:
vertex - the vertex.
Returns:
the array.
Throws:
java.util.NoSuchElementException - If the vertex is not part of the graph.
See Also:
#getNumberOfEdges(int)

getMass

double getMass(int vertex)
               throws java.util.NoSuchElementException
Returns the sum of the weights of all edges connected to given vertex.

Parameters:
vertex - the vertex.
Returns:
the mass.
Throws:
java.util.NoSuchElementException - if the vertex is not part of the graph.

setEdgeWeight

double setEdgeWeight(int vertexA,
                     int vertexB,
                     double weight)
                     throws java.util.NoSuchElementException
Sets the weight of a edge determined by two vertices. If the new weight is getUnconnectedWeight(), this should be the same as calling removeEdge(int, int). The old weight of the edge is returned, which may be getUnconnectedWeight() if the edge had not existed.

Parameters:
vertexA - one vertex of the edge.
vertexB - the other vertex of the edge.
weight - the new weight of the edge.
Returns:
the value that would have been returned by a call to getEdgeWeight(int, int) directly before this call.
Throws:
java.util.NoSuchElementException - if at least one of the two vertices is not a part of the graph (see containsVertex(int)).
See Also:
getUnconnectedWeight(), getEdgeWeight(int, int), removeEdge(int, int)

removeEdge

double removeEdge(int vertexA,
                  int vertexB)
                  throws java.util.NoSuchElementException
Removes an edge determined by two vertices. The old weight of the edge is returned, which may be getUnconnectedWeight() if the edge had not existed (in which case nothing has happened).

Parameters:
vertexA - one vertex of the edge.
vertexB - the other vertex of the edge.
Returns:
the value that would have been returned by a call to getEdgeWeight(int, int) directly before this call.
Throws:
java.util.NoSuchElementException - if at least one of the two vertices is not a part of the graph.
See Also:
getUnconnectedWeight(), getEdgeWeight(int, int), setEdgeWeight(int, int, double)

getEdges

java.util.Iterator<? extends UndirectedIntGraph.Edge> getEdges()
Returns an iterator over all edges of the graph. Each edge is only visited once.

Returns:
the iterator.
See Also:
getNumberOfEdges()

getEdgesConnectedTo

java.util.Iterator<? extends UndirectedIntGraph.Edge> getEdgesConnectedTo(int vertex)
                                                                          throws java.util.NoSuchElementException
Returns an iterator over all edges in the graph to which given vertex is connected to.

Parameters:
vertex - the vertex.
Returns:
the iterator.
Throws:
java.util.NoSuchElementException - if the vertex is not part of the graph.
See Also:
#getNumberOfEdges(int)

containsVertex

boolean containsVertex(int vertex)
Checks if given vertex is contained in the graph.

Parameters:
vertex - the vertex to look for.
Returns:
true if the vertex is contained.

containsEdge

boolean containsEdge(int vertexA,
                     int vertexB)
                     throws java.util.NoSuchElementException
Checks if there exists an edge in the graph connecting the two vertices given as parameters.

Parameters:
vertexA - one vertex.
vertexB - the other vertex.
Returns:
true if both vertices are connected.
Throws:
java.util.NoSuchElementException - if at least one of the vertices is not part of the graph.

getEdgeWeight

double getEdgeWeight(int vertexA,
                     int vertexB)
                     throws java.util.NoSuchElementException
Returns the weight of the edge connecting the two vertices. This will return the same as getUnconnectedWeight() if the two vertices are not connected.

Parameters:
vertexA - one vertex.
vertexB - the other vertex.
Returns:
the weight of the edge or getUnconnectedWeight().
Throws:
java.util.NoSuchElementException - if at least one of the vertices is not part of the graph.
See Also:
containsEdge(int, int), getEdge(int, int), getUnconnectedWeight()

getEdge

UndirectedIntGraph.Edge getEdge(int vertexA,
                                int vertexB)
                                throws java.util.NoSuchElementException
Returns the Edge connecting the two vertices. The object will also be returned if there does not exists such an edge in the graph. Use edge.exists() to check.

Parameters:
vertexA - one vertex.
vertexB - the other vertex.
Returns:
the edge.
Throws:
java.util.NoSuchElementException - if at least one of the vertices is not part of the graph.
See Also:
UndirectedIntGraph.Edge, containsEdge(int, int), getEdgeWeight(int, int), UndirectedIntGraph.Edge.exists()

clone

UndirectedIntGraph clone()