ch.ethz.graphbench.toolbox
Class Graph

java.lang.Object
  |
  +--ch.ethz.graphbench.toolbox.Graph

public class Graph
extends java.lang.Object

Class representing a graph in 2D eucledian space.
Cannot be instantiated directly, use the Graph instance provided by the GraphAlgorithm.


Method Summary
 Edge createEdge(Vertex from, Vertex to)
          Creates a new Edge, adds it to the graph and returns it.
 Vertex createVertex(java.awt.Point p)
          Creates a new vertex and adds it to the graph.
 Edge getEdge(Vertex from, Vertex to)
          Returns the edge connecting the two vertices.
 int getEdgeCount()
          Returns the number of edges of the graph.
 java.util.Iterator getEdgeIterator()
          Returns an iterator over all edges.
 Vertex getVertex(int index)
          Gets the vertex with the given index.
 int getVertexCount()
          Returns the number of vertices of the graph.
 java.util.Iterator getVertexIterator()
          Returns an iterator over all vertices.
 boolean isDirected()
          Returns if the graph has directed edges or not.
 void removeAllEdges()
          Removes all edges from the graph.
 void removeAllVertices()
          Removes all vertices and therefor also all edges.
 void removeEdge(Edge edge)
          Removes an edge from the graph.
 void removeVertex(Vertex vertex)
          Removes a vertex from the graph.
 void resetStates()
          Resets the states of all vertices and edges.
 void setDirected(boolean directed)
          Sets if the graph has directed edges or not.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setDirected

public void setDirected(boolean directed)
Sets if the graph has directed edges or not.
Parameters:
isDirected - Boolean value specifying if graph is direced.

getVertexCount

public int getVertexCount()
Returns the number of vertices of the graph.
Returns:
Number of vertices.

getEdgeCount

public int getEdgeCount()
Returns the number of edges of the graph.
Returns:
Number of edges.

getEdge

public Edge getEdge(Vertex from,
                    Vertex to)
Returns the edge connecting the two vertices.
Parameters:
from - The starting vertex of the edge.
to - The ending vertex of the edge.
Returns:
Edge connecting the two vertices, null if no such edge exists.

getEdgeIterator

public java.util.Iterator getEdgeIterator()
Returns an iterator over all edges.
Returns:
edge iterator

getVertexIterator

public java.util.Iterator getVertexIterator()
Returns an iterator over all vertices.
Returns:
vertex iterator

getVertex

public Vertex getVertex(int index)
Gets the vertex with the given index.
Parameters:
i - Index of the vertex to be returned.
Returns:
Vertex with given index, null if index does not exist.

isDirected

public boolean isDirected()
Returns if the graph has directed edges or not.
Returns:
true if graph has directed edges, false otherwise.

createVertex

public Vertex createVertex(java.awt.Point p)
Creates a new vertex and adds it to the graph.
Parameters:
p - The eucledian position of the vertex to be created.
Returns:
The new vertex.

createEdge

public Edge createEdge(Vertex from,
                       Vertex to)
Creates a new Edge, adds it to the graph and returns it. If the graph already contains an edge as specified by the two vertices, no new edge is created. Instead the existing edge is returned.
Parameters:
from - The starting vertex of the edge.
to - The ending vertex of the edge.
Returns:
The new edge or the already existing edge.

removeEdge

public void removeEdge(Edge edge)
Removes an edge from the graph.
Parameters:
edge - The edge to be removed.

removeAllEdges

public void removeAllEdges()
Removes all edges from the graph.

removeVertex

public void removeVertex(Vertex vertex)
Removes a vertex from the graph. All edges adjacent to the vertex will also be removed.
Parameters:
vertex - The vertex to be removed.

removeAllVertices

public void removeAllVertices()
Removes all vertices and therefor also all edges.

resetStates

public void resetStates()
Resets the states of all vertices and edges.