|
GraphLab Project | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgraphlab.library.BaseGraph<VertexType,EdgeType>
graphlab.library.MatrixGraph<VertexType,EdgeType>
VertexType
- Type of the vertices the graph can work with.EdgeType
- Type of the edges the graph can work with.public class MatrixGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
Adjacency Matrix Graph. For information about Adjacency Matrix refer to http://en.wikipedia.org/wiki/Adjacency_matrix * @author Omid Aladini
Field Summary |
---|
Fields inherited from class graphlab.library.BaseGraph |
---|
isSubgraph, lastSubgraphIndex, subgraphIndex, superGraph |
Constructor Summary | |
---|---|
MatrixGraph()
Constructs an undirected graph object that stores graph data using adjacency list data structure. |
|
MatrixGraph(BaseGraph<ImportVertexType,ImportEdgeType> graph,
GraphConverter<ImportVertexType,VertexType,ImportEdgeType,EdgeType,ImportGraphType,MatrixGraph<VertexType,EdgeType>> gc)
Constructs a graph object that stores graph data using adjacency matrix data structure by importing graph data from a pre-existing graph. |
|
MatrixGraph(boolean directed)
Constructs a MatrixGraph object |
|
MatrixGraph(boolean directed,
int expectedNumberOfVertices)
Constructs a graph object that stores graph data using adjacency matrix data structure. |
Method Summary | |
---|---|
boolean |
breadthFirstSearch(VertexType vertex,
PreWorkHandler<VertexType> handler)
Runs Breadth First Search (BFS) algorithm on the graph starting from vertex vertexId. |
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). |
MatrixGraph<VertexType,EdgeType> |
createEmptyGraph()
Returns a new instance of an empty graph of the current graph type. |
boolean |
depthFirstSearch(VertexType vertex,
PreWorkPostWorkHandler<VertexType> handler)
Runs Depth First Search (DFS) algorithm on the graph starting from vertex vertexId. |
void |
dump()
Prints the Adjacency Matrix to the standard output. |
java.util.Iterator<EdgeType> |
edgeIterator()
Returns iterator object for the edges. |
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 . |
java.lang.Iterable<EdgeType> |
edges()
|
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.ArrayList<EdgeType> |
getEdges(VertexType source,
VertexType target)
Returns all edges between two vertices. |
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). |
boolean |
isGraphAcyclic()
Checks whether the current graph is acyclic. |
boolean |
isGraphConnected()
Checks whether the current graph is a connected graph. |
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 isDirected)
|
Methods inherited from class graphlab.library.BaseGraph |
---|
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 |
---|
public MatrixGraph(boolean directed, int expectedNumberOfVertices)
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.public MatrixGraph(boolean directed)
directed
- Whether the graph is directed or undirected.public MatrixGraph()
public MatrixGraph(BaseGraph<ImportVertexType,ImportEdgeType> graph, GraphConverter<ImportVertexType,VertexType,ImportEdgeType,EdgeType,ImportGraphType,MatrixGraph<VertexType,EdgeType>> gc) throws InvalidGraphException
ImportVertexType
- The type of vertex object which the input graph contain.ImportEdgeType
- The type of edge object which the input graph contain.graph
- converter
- A GraphConverter object which is responsible for duplicating/converting graph
elements.
InvalidGraphException
- Throws when the input graph is an invalid graph object.Method Detail |
---|
public int getVerticesCount()
BaseGraph
getVerticesCount
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
public void insertEdge(EdgeType newEdge) throws InvalidVertexException
BaseGraph
insertEdge
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
newEdge
- Reference to the new edge object.
InvalidVertexException
- Thrown when the edge object tries
to connect two vertices whom their indexes are invalid.public java.util.ArrayList<EdgeType> getEdges(VertexType source, VertexType target) throws InvalidVertexException
getEdges
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
from
- Index of the edges' start point.to
- Index of the edges' end point.
InvalidVertexException
- Thrown when two supplied indexes of vertices are invalid.public void insertVertex(VertexType newVertex)
BaseGraph
insertVertex
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
newVertex
- The new vertex to be inserted.public boolean depthFirstSearch(VertexType vertex, PreWorkPostWorkHandler<VertexType> handler) throws InvalidVertexException
vertex
- Starting vertex of the traversal.handler
- A reference to a PreWorkPostWorkHandler that contains implementation
of pre-work and post-work operations that depends on the application of DFS.
InvalidVertexException
public boolean breadthFirstSearch(VertexType vertex, PreWorkHandler<VertexType> handler) throws InvalidVertexException
vertex
- Starting vertex of the traversal.handler
- A reference to a PreWorkHandler that contains implementation
of pre-work operation that depends on the application of DFS.
InvalidVertexException
public boolean isGraphConnected()
public boolean isGraphAcyclic()
public java.util.Iterator<VertexType> iterator()
BaseGraph
iterator
in interface java.lang.Iterable<VertexType extends BaseVertex>
iterator
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
public boolean isDirected()
BaseGraph
isDirected
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
public java.util.Iterator<EdgeType> edgeIterator()
edgeIterator
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
BaseGraph.lightEdgeIterator()
public java.lang.Iterable<EdgeType> edges()
edges
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
BaseGraph.lightEdgeIterator()
public java.util.Iterator<EdgeType> edgeIterator(VertexType v) throws InvalidVertexException
BaseGraph
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.
edgeIterator
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
v
- Source or target of desired edges.
InvalidVertexException
BaseGraph.lightEdgeIterator(BaseVertex)
,
BaseGraph.getNeighbors(BaseVertex)
public Matrix getAdjacencyMatrix()
BaseGraph
getAdjacencyMatrix
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
public void dump()
BaseGraph
dump
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
public void removeAllEdges(VertexType source, VertexType target) throws InvalidVertexException
BaseGraph
removeAllEdges
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
source
- Index of the edges' start point.target
- Index of the edges' end point.
InvalidVertexException
- Thrown when two supplied indexes of vertices are invalid.public void removeVertex(VertexType v) throws InvalidVertexException
BaseGraph
removeVertex
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
InvalidVertexException
public int getInDegree(VertexType v) throws InvalidVertexException
BaseGraph
getInDegree
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
InvalidVertexException
BaseGraph.getDegree(BaseVertex)
public int getOutDegree(VertexType v) throws InvalidVertexException
BaseGraph
getOutDegree
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
InvalidVertexException
BaseGraph.getDegree(BaseVertex)
public void removeEdge(EdgeType edge) throws InvalidEdgeException
BaseGraph
removeEdge
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
edge
- Edge to be removed.
InvalidEdgeException
- If edge
is an invalid edge object.public VertexType getAVertex()
public BaseGraph<VertexType,EdgeType> copy(EdgeVertexCopier<VertexType,EdgeType> gc) throws InvalidGraphException
BaseGraph
copy
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
gc
- Reference to EdgeVertexCopier object.
InvalidGraphException
- If the graph is not a valid graph object.public boolean containsVertex(VertexType v)
BaseGraph
containsVertex
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
v
- Vertex to check existance.
public void checkVertex(VertexType v) throws InvalidVertexException
BaseGraph
checkVertex
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
v
- The vertex to be checked.
InvalidVertexException
- If the supplied vertex is invalid.public boolean isEdge(VertexType source, VertexType target) throws InvalidVertexException
BaseGraph
isEdge
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
InvalidVertexException
- if supplied source or target are invalid.public MatrixGraph<VertexType,EdgeType> createEmptyGraph()
BaseGraph
createEmptyGraph
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
public void setDirected(boolean isDirected)
setDirected
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
public BaseVertex[] getVertexArray()
BaseGraph
getVertexArray
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
public int[][] getEdgeArray()
BaseGraph
getEdgeArray
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
public java.util.Iterator<EdgeType> lightEdgeIterator()
BaseGraph
lightEdgeIterator
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
public java.util.Iterator<EdgeType> lightEdgeIterator(VertexType v) throws InvalidVertexException
BaseGraph
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.
lightEdgeIterator
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
v
- Source or target of desired edges.
InvalidVertexException
public void clear()
BaseGraph
clear
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
public int getEdgesCount()
getEdgesCount
in class BaseGraph<VertexType extends BaseVertex,EdgeType extends BaseEdge<VertexType>>
|
GraphLab Project | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |