de.aitools.aq.structure.graph
Interface UndirectedLongGraph

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

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

An undirected weighted graph.

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

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

getUnconnectedWeight

double getUnconnectedWeight()

Returns the default weight for unconnected vertices.

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

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

Returns:
the array.
See Also:
getNumberOfVertices()

getVerticesConnectedTo

long[] getVerticesConnectedTo(long 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(long)

getMass

double getMass(long 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(long vertexA,
                     long 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(long, long). 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(long, long) 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(long)).
See Also:
getUnconnectedWeight(), getEdgeWeight(long, long), removeEdge(long, long)

removeEdge

double removeEdge(long vertexA,
                  long 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(long, long) 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(long, long), setEdgeWeight(long, long, double)

getEdges

java.util.Iterator<? extends UndirectedLongGraph.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 UndirectedLongGraph.Edge> getEdgesConnectedTo(long 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(long)

containsVertex

boolean containsVertex(long 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(long vertexA,
                     long 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(long vertexA,
                     long 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(long, long), getEdge(long, long), getUnconnectedWeight()

getEdge

UndirectedLongGraph.Edge getEdge(long vertexA,
                                 long 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:
UndirectedLongGraph.Edge, containsEdge(long, long), getEdgeWeight(long, long), UndirectedLongGraph.Edge.exists()

clone

UndirectedLongGraph clone()