GraphLab Project

graphlab.library
Class ListGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>

java.lang.Object
  extended by graphlab.library.BaseGraph<VertexType,EdgeType>
      extended by graphlab.library.ListGraph<VertexType,EdgeType>
Type Parameters:
VertexType - Type of the vertices the graph can work with.
EdgeType - Type of the edges the graph can work with.

toCheck : edgeIterator class, removeEdge, removeAllEdges, copy, setDirected

All Implemented Interfaces:
java.lang.Iterable<VertexType>
Direct Known Subclasses:
GraphModel

public class ListGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
extends BaseGraph<VertexType,EdgeType>

Adjacency List Graph.

Author:
Omid Aladini

Field Summary
 
Fields inherited from class graphlab.library.BaseGraph
isSubgraph, lastSubgraphIndex, subgraphIndex, superGraph
 
Constructor Summary
ListGraph()
          Constructs an undirected graph object that stores graph data using adjacency list data structure.
ListGraph(BaseGraph<ImportVertexType,ImportEdgeType> graph, GraphConverter<ImportVertexType,VertexType,ImportEdgeType,EdgeType,ImportGraphType,ListGraph<VertexType,EdgeType>> converter)
          Constructs a graph object that stores graph data using adjacency list data structure by importing graph data from a pre-existing graph.
ListGraph(boolean directed, int expectedNumberOfVertices)
          Constructs a graph object that stores graph data using adjacency list data structure.
 
Method Summary
 void checkVertex(VertexType v)
          If the supplied vertex is invalid (Not one of graph's vertices), throws InvalidVertexException.
 void clear()
          Clears the graph.
 boolean containsVertex(VertexType v)
          This method returns true if the graph contains the specified vertex, false otherwise.
 BaseGraph<VertexType,EdgeType> copy(EdgeVertexCopier<VertexType,EdgeType> gc)
          Creates a clone of the current graph using the GraphConverter object which is responsible for duplication of the graph elements (edges and vertices).
 ListGraph<VertexType,EdgeType> createEmptyGraph()
          Returns a new instance of an empty graph of the current graph type.
 void dump()
          Prints the Adjacency Matrix to the standard output.
 java.util.Iterator<EdgeType> edgeIterator()
          Constructs and returns an Edge Iterator object which iterates through all the edges in the graph.
 java.util.Iterator<EdgeType> edgeIterator(VertexType v)
          Constructs an Edge Iterator object which iterates through all the edges going to or coming from the specified vertex v.
 Matrix getAdjacencyMatrix()
          Returns a Jama Matrix object that represents adjacency matrix of the graph.
 VertexType getAVertex()
           
 int[][] getEdgeArray()
          Returns array of array of 'int's where represents a simple adjacency list.
 java.util.AbstractList<EdgeType> getEdges(VertexType source, VertexType target)
          Returns a collection of all edges which connects two vertices supplied as first and second arguments of this method.
 int getEdgesCount()
           
 int getInDegree(VertexType v)
          Returns in-degree of vertex vertexId, the number of edges which their target goes to the specified vertex.
 int getOutDegree(VertexType v)
          Returns out-degree of the supplied vertex, the number of edges which their source is attached to the specified vertex.
 BaseVertex[] getVertexArray()
          Returns array of vertices upcasted to BaseVertex.
 int getVerticesCount()
          Returns the number of vertices.
 void insertEdge(EdgeType newEdge)
          Inserts an edge in the graph.
 void insertVertex(VertexType newVertex)
          Inserts a new vertex to the graph.
 boolean isDirected()
          Returns whether the graph is directed.
 boolean isEdge(VertexType source, VertexType target)
          Returns true if there is an edge between specified vertices (direction considered for directed graphs).
 java.util.Iterator<VertexType> iterator()
          Returns iterator object for the vertices.
 java.util.Iterator<EdgeType> lightEdgeIterator()
          Returns a light(weight) Edge Iterator object which iterates through all the edges in the graph.
 java.util.Iterator<EdgeType> lightEdgeIterator(VertexType v)
          Constructs a light(weight) Edge Iterator object which iterates through all the edges going to or coming from the specified vertex v.
 void removeAllEdges(VertexType source, VertexType target)
          Removes all edges between two vertices.
 void removeEdge(EdgeType edge)
          Removes an edge from the graph.
 void removeVertex(VertexType v)
          Removes a vertex and all it's connected edges.
 void setDirected(boolean directed)
           
protected  void setId(VertexType v, int id)
          A wrapper for setting vertex Id's which supports multiple vertex owners.
 
Methods inherited from class graphlab.library.BaseGraph
edges, getDegree, getEdges, getId, getNeighbors, getNewSubgraphIndex, registerSubgraph, setSubGraphIndex, vertices
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListGraph

public ListGraph(boolean directed,
                 int expectedNumberOfVertices)
Constructs a graph object that stores graph data using adjacency list data structure.

Parameters:
directed - Indicated whether the graph is directed.
expectedNumberOfVertices - Approximate number of vertices that will be added to the graph. This paramether is optional and is available for performance reasons.

ListGraph

public ListGraph()
Constructs an undirected graph object that stores graph data using adjacency list data structure.


ListGraph

public ListGraph(BaseGraph<ImportVertexType,ImportEdgeType> graph,
                 GraphConverter<ImportVertexType,VertexType,ImportEdgeType,EdgeType,ImportGraphType,ListGraph<VertexType,EdgeType>> converter)
          throws InvalidGraphException
Constructs a graph object that stores graph data using adjacency list data structure by importing graph data from a pre-existing graph. A GraphConvertor object is passed as a parameter which is reponsible for duplication/type-convertion of graph elements.

Type Parameters:
ImportVertexType - The type of vertex object which the input graph contain.
ImportEdgeType - The type of edge object which the input graph contain.
Parameters:
graph -
converter - A GraphConverter object which is responsible for duplicating/converting graph elements.
Throws:
InvalidGraphException - Throws when the input graph is an invalid graph object.
Method Detail

setId

protected void setId(VertexType v,
                     int id)
A wrapper for setting vertex Id's which supports multiple vertex owners.

Parameters:
v - Vertex which the caller intends to set its Id.

getVerticesCount

public int getVerticesCount()
Description copied from class: BaseGraph
Returns the number of vertices.

Specified by:
getVerticesCount in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
Number of vertices in the graph.

edgeIterator

public java.util.Iterator<EdgeType> edgeIterator()
Description copied from class: BaseGraph
Constructs and returns an Edge Iterator object which iterates through all the edges in the graph. Note that if the graph object is changed during iteration, the iteration may not actually represent current state of the graph. For example, if you deleted an edge after construction of this object, the edge would be included in the iteration.

Specified by:
edgeIterator in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
Iterator object on edges.
See Also:
BaseGraph.lightEdgeIterator()

edgeIterator

public java.util.Iterator<EdgeType> edgeIterator(VertexType v)
                                                                       throws InvalidVertexException
Description copied from class: BaseGraph
Constructs an Edge Iterator object which iterates through all the edges going to or coming from the specified vertex v. Note that if the graph object is changed during iteration, the iteration may not actually represent current state of the graph. For example, if you deleted an edge after construction of this object, the edge would be included in the iteration.

Specified by:
edgeIterator in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Parameters:
v - Source or target of desired edges.
Returns:
Iterator object on edges which their sources or targets are the supplied vertex.
Throws:
InvalidVertexException
See Also:
BaseGraph.lightEdgeIterator(BaseVertex), BaseGraph.getNeighbors(BaseVertex)

lightEdgeIterator

public java.util.Iterator<EdgeType> lightEdgeIterator()
Description copied from class: BaseGraph
Returns a light(weight) Edge Iterator object which iterates through all the edges in the graph. The light(weight) edge iterator presents an iterator with O(1) constructor. Note that you should not change the content of the graph during your iteration. You can still change properties of each edge or vertex.

Specified by:
lightEdgeIterator in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
Returns a light(weight) Edge Iterator object.

lightEdgeIterator

public java.util.Iterator<EdgeType> lightEdgeIterator(VertexType v)
                                                                            throws InvalidVertexException
Description copied from class: BaseGraph
Constructs a light(weight) Edge Iterator object which iterates through all the edges going to or coming from the specified vertex v. The light(weight) edge iterator presents an iterator with O(1) constructor. Note that you should not change the content of the graph during your iteration. You can still change properties of each edge or vertex.

Specified by:
lightEdgeIterator in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Parameters:
v - Source or target of desired edges.
Returns:
A light(weight) Edge Iterator object which iterates through all the edges going to or coming from the specified vertex.
Throws:
InvalidVertexException

insertEdge

public void insertEdge(EdgeType newEdge)
                throws InvalidVertexException
Description copied from class: BaseGraph
Inserts an edge in the graph.

Specified by:
insertEdge in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Parameters:
newEdge - Reference to the new edge object.
Throws:
InvalidVertexException - Thrown when the edge object tries to connect two vertices whom their indexes are invalid.

insertVertex

public void insertVertex(VertexType newVertex)
Description copied from class: BaseGraph
Inserts a new vertex to the graph.

Specified by:
insertVertex in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Parameters:
newVertex - The new vertex to be inserted.

iterator

public java.util.Iterator<VertexType> iterator()
Description copied from class: BaseGraph
Returns iterator object for the vertices.

Specified by:
iterator in interface java.lang.Iterable<VertexType extends BaseVertex>
Specified by:
iterator in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
iterator object for the vertices.

getAdjacencyMatrix

public Matrix getAdjacencyMatrix()
Description copied from class: BaseGraph
Returns a Jama Matrix object that represents adjacency matrix of the graph. the Matrix object have the ability apply simple linear algebra operations on the adjacency matrix.

Specified by:
getAdjacencyMatrix in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
Adjacency Matrix of the graph as a Jama Matrix object.

isDirected

public boolean isDirected()
Description copied from class: BaseGraph
Returns whether the graph is directed.

Specified by:
isDirected in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
True is graph is constructed as a directed graph and false otherwise.

dump

public void dump()
Description copied from class: BaseGraph
Prints the Adjacency Matrix to the standard output.

Specified by:
dump in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>

removeAllEdges

public void removeAllEdges(VertexType source,
                           VertexType target)
                    throws InvalidVertexException
Description copied from class: BaseGraph
Removes all edges between two vertices.

Specified by:
removeAllEdges in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Parameters:
source - Index of the edges' start point.
target - Index of the edges' end point.
Throws:
InvalidVertexException - Thrown when two supplied indexes of vertices are invalid.

removeEdge

public void removeEdge(EdgeType edge)
                throws InvalidEdgeException
Description copied from class: BaseGraph
Removes an edge from the graph.

Specified by:
removeEdge in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Parameters:
edge - Edge to be removed.
Throws:
InvalidEdgeException - If edge is an invalid edge object.

getEdges

public java.util.AbstractList<EdgeType> getEdges(VertexType source,
                                                 VertexType target)
                                                                       throws InvalidVertexException
Description copied from class: BaseGraph
Returns a collection of all edges which connects two vertices supplied as first and second arguments of this method.

Specified by:
getEdges in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
Returns a collection of all edges which connects two vertices supplied as first and second arguments of this method.
Throws:
InvalidVertexException - if supplied source or target are invalid.

removeVertex

public void removeVertex(VertexType v)
                  throws InvalidVertexException
Description copied from class: BaseGraph
Removes a vertex and all it's connected edges.

Specified by:
removeVertex in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Throws:
InvalidVertexException

getInDegree

public int getInDegree(VertexType v)
                throws InvalidVertexException
Description copied from class: BaseGraph
Returns in-degree of vertex vertexId, the number of edges which their target goes to the specified vertex.

Specified by:
getInDegree in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
in-degree of vertex vertexId.
Throws:
InvalidVertexException
See Also:
BaseGraph.getDegree(BaseVertex)

getOutDegree

public int getOutDegree(VertexType v)
                 throws InvalidVertexException
Description copied from class: BaseGraph
Returns out-degree of the supplied vertex, the number of edges which their source is attached to the specified vertex.

Specified by:
getOutDegree in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
out-degree of vertex vertexId.
Throws:
InvalidVertexException
See Also:
BaseGraph.getDegree(BaseVertex)

copy

public BaseGraph<VertexType,EdgeType> copy(EdgeVertexCopier<VertexType,EdgeType> gc)
                                                                                    throws InvalidGraphException
Description copied from class: BaseGraph
Creates a clone of the current graph using the GraphConverter object which is responsible for duplication of the graph elements (edges and vertices).

Specified by:
copy in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Parameters:
gc - Reference to EdgeVertexCopier object.
Returns:
Clone of the current graph which is independent of it's source graph.
Throws:
InvalidGraphException - If the graph is not a valid graph object.

getAVertex

public VertexType getAVertex()

containsVertex

public boolean containsVertex(VertexType v)
Description copied from class: BaseGraph
This method returns true if the graph contains the specified vertex, false otherwise.

Specified by:
containsVertex in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Parameters:
v - Vertex to check existance.
Returns:
True if the graph contains the specified vertex, false otherwise.

checkVertex

public void checkVertex(VertexType v)
                 throws InvalidVertexException
Description copied from class: BaseGraph
If the supplied vertex is invalid (Not one of graph's vertices), throws InvalidVertexException. This method should be called before any operation by algorithms where some vertices are supplied as their arguments.

Specified by:
checkVertex in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Parameters:
v - The vertex to be checked.
Throws:
InvalidVertexException - If the supplied vertex is invalid.

isEdge

public boolean isEdge(VertexType source,
                      VertexType target)
               throws InvalidVertexException
Description copied from class: BaseGraph
Returns true if there is an edge between specified vertices (direction considered for directed graphs).

Specified by:
isEdge in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
true if there is an edge between specified vertices (direction considered for directed graphs).
Throws:
InvalidVertexException - if supplied source or target are invalid.

createEmptyGraph

public ListGraph<VertexType,EdgeType> createEmptyGraph()
Description copied from class: BaseGraph
Returns a new instance of an empty graph of the current graph type.

Specified by:
createEmptyGraph in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
A new instance of an empty graph of the current graph type.

setDirected

public void setDirected(boolean directed)
Specified by:
setDirected in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>

getVertexArray

public BaseVertex[] getVertexArray()
Description copied from class: BaseGraph
Returns array of vertices upcasted to BaseVertex.

Specified by:
getVertexArray in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
Array of vertices upcasted to BaseVertex.

getEdgeArray

public int[][] getEdgeArray()
Description copied from class: BaseGraph
Returns array of array of 'int's where represents a simple adjacency list.

Specified by:
getEdgeArray in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Returns:
Array of array of 'int's where represents a simple adjacency list.

clear

public void clear()
Description copied from class: BaseGraph
Clears the graph.

Specified by:
clear in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>

getEdgesCount

public int getEdgesCount()
Specified by:
getEdgesCount in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>

GraphLab Project