V - the vertex type.E - the edge type.public interface Graph<V extends Vertex,E extends Edge<V>> extends Serializable
V set and a set of edges of type
E. Edges of this graph type have exactly two endpoints; whether these endpoints must be distinct depends
on the implementation. This implementation is shamelessly copied from the Jung graph library which is used as the implementation for all the classes in this package.
| Modifier and Type | Method and Description |
|---|---|
boolean |
addEdge(E e,
V v1,
V v2)
Adds edge
e to this graph such that it connects vertex
v1 to
v2. |
boolean |
addEdge(E e,
V v1,
V v2,
EdgeType edgeType)
Adds edge
e to this graph such that it connects vertex
v1 to
v2. |
void |
addEdgeAttribute(String name,
Class type,
String defaultValue)
Add a new node attribute to the network.
|
boolean |
addVertex(V vertex)
Adds a vertex to the graph.
|
void |
addVertexAttribute(String name,
Class type,
String defaultValue)
Add a new node attribute to the network.
|
V |
getDest(E directedEdge)
If
directed_edge is a directed edge in this graph, returns the destination; otherwise returns
null. |
E |
getEdge(String id)
Returns a view the edges in this graph with the given id.
|
Collection<EdgeAttribute> |
getEdgeAttributes()
Get the attributes for the edges in the graph.
|
Collection<E> |
getEdges()
Returns a view of all edges in this graph.
|
EdgeType |
getEdgeType()
Get the type of edge (directed/undirected employed in the graph.
|
Pair<V,V> |
getEndpoints(E edge)
Returns the endpoints of
edge as a
Pair. |
Collection<E> |
getInEdges(V vertex)
Returns a
Collection view of the incoming edges incident to
vertex in this graph. |
V |
getOpposite(V vertex,
E edge)
Returns the vertex at the other end of
edge from
vertex. |
Collection<E> |
getOutEdges(V vertex)
Returns a
Collection view of the outgoing edges incident to
vertex in this graph. |
int |
getPredecessorCount(V vertex)
Returns the number of predecessors that
vertex has in this graph. |
Collection<V> |
getPredecessors(V vertex)
Returns a
Collection view of the predecessors of
vertex in this graph. |
V |
getSource(E directedEdge)
If
directed_edge is a directed edge in this graph, returns the source; otherwise returns
null. |
int |
getSuccessorCount(V vertex)
Returns the number of successors that
vertex has in this graph. |
Collection<V> |
getSuccessors(V vertex)
Returns a
Collection view of the successors of
vertex in this graph. |
V |
getVertex(String id)
Returns a view the vertex in this graph with a given id.Returns null if the edge does not exist.
|
Collection<VertexAttribute> |
getVertexAttributes()
Get the attributes for the vertics in the graph.
|
int |
getVertexCount()
Returns the number of vertices in this graph.
|
Collection<V> |
getVertices()
Returns a view of all vertices in this graph.
|
int |
inDegree(V vertex)
Returns the number of incoming edges incident to
vertex. |
boolean |
isDest(V vertex,
E edge)
Returns
true if
vertex is the destination of
edge. |
boolean |
isPredecessor(V v1,
V v2)
Returns
true if
v1 is a predecessor of
v2 in this graph. |
boolean |
isSource(V vertex,
E edge)
Returns
true if
vertex is the source of
edge. |
boolean |
isSuccessor(V v1,
V v2)
Returns
true if
v1 is a successor of
v2 in this graph. |
int |
outDegree(V vertex)
Returns the number of outgoing edges incident to
vertex. |
boolean |
removeEdge(E edge)
Removes
edge from this graph. |
boolean |
removeVertex(V vertex)
Remove the passed node, and, in the case of a tree, all nodes that are descendants of the passed node.
|
Collection<E> getInEdges(V vertex)
Collection view of the incoming edges incident to
vertex in this graph.vertex - the vertex whose incoming edges are to be returnedCollection view of the incoming edges incident to vertex in this graphCollection<E> getOutEdges(V vertex)
Collection view of the outgoing edges incident to
vertex in this graph.vertex - the vertex whose outgoing edges are to be returnedCollection view of the outgoing edges incident to vertex in this graphCollection<V> getPredecessors(V vertex)
Collection view of the predecessors of
vertex in this graph. A predecessor of
vertex is defined as a vertex
v which is connected to
vertex by an edge
e, where
e is an outgoing edge of
v and an incoming edge of
vertex.vertex - the vertex whose predecessors are to be returnedCollection view of the predecessors of vertex in this graphCollection<V> getSuccessors(V vertex)
Collection view of the successors of
vertex in this graph. A successor of
vertex is defined as a vertex
v which is connected to
vertex by an edge
e, where
e is an incoming edge of
v and an outgoing edge of
vertex.vertex - the vertex whose predecessors are to be returnedCollection view of the successors of vertex in this graphint inDegree(V vertex)
vertex. Equivalent to
getInEdges(vertex).size().vertex - the vertex whose indegree is to be calculatedvertexint outDegree(V vertex)
vertex. Equivalent to
getOutEdges(vertex).size().vertex - the vertex whose outdegree is to be calculatedvertexboolean isPredecessor(V v1, V v2)
true if
v1 is a predecessor of
v2 in this graph. Equivalent to
v1.getPredecessors().contains(v2).v1 - the first vertex to be queriedv2 - the second vertex to be queriedtrue if v1 is a predecessor of v2, and false otherwise.boolean isSuccessor(V v1, V v2)
true if
v1 is a successor of
v2 in this graph. Equivalent to
v1.getSuccessors().contains(v2).v1 - the first vertex to be queriedv2 - the second vertex to be queriedtrue if v1 is a successor of v2, and false otherwise.int getPredecessorCount(V vertex)
vertex has in this graph. Equivalent to
vertex.getPredecessors().size().vertex - the vertex whose predecessor count is to be returnedvertex has in this graphint getSuccessorCount(V vertex)
vertex has in this graph. Equivalent to
vertex.getSuccessors().size().vertex - the vertex whose successor count is to be returnedvertex has in this graphV getSource(E directedEdge)
directed_edge is a directed edge in this graph, returns the source; otherwise returns
null. The source of a directed edge
d is defined to be the vertex for which
d is an outgoing edge.
directed_edge is guaranteed to be a directed edge if its
EdgeType is
DIRECTED.directedEdge - the edge for which we want the corresponding source.directed_edge if it is a directed edge in this graph, or null
otherwiseV getDest(E directedEdge)
directed_edge is a directed edge in this graph, returns the destination; otherwise returns
null. The destination of a directed edge
d is defined to be the vertex incident to
d for which
d is an incoming edge.
directed_edge is guaranteed to be a directed edge if its
EdgeType is
DIRECTED.directedEdge - the edge for which we want the corresponding destination.directed_edge if it is a directed edge in this graph, * * or null otherwiseboolean isSource(V vertex, E edge)
true if
vertex is the source of
edge. Equivalent to
getSource(edge).equals(vertex).vertex - the vertex to be queriededge - the edge to be queriedtrue iff vertex is the source of edgeboolean isDest(V vertex, E edge)
true if
vertex is the destination of
edge. Equivalent to
getDest(edge).equals(vertex).vertex - the vertex to be queriededge - the edge to be queriedtrue iff vertex is the destination of edgeboolean addVertex(V vertex)
vertex - the vertex to be added to the graphboolean addEdge(E e, V v1, V v2)
e to this graph such that it connects vertex
v1 to
v2. Equivalent to
addEdge(e, new Pair(v1, v2)) . If this graph does not contain
v1,
v2, or both, implementations may choose to either silently add the vertices to the graph or throw an
IllegalArgumentException. If this graph assigns edge types to its edges, the edge type of
e will be the default for this graph. See
Hypergraph.addEdge() for a listing of possible reasons for failure.e - the edge to be addedv1 - the first vertex to be connectedv2 - the second vertex to be connectedtrue if the add is successful, false otherwiseHypergraph#addEdge(Object, Collection),
#addEdge(Object, Object, Object, EdgeType)boolean addEdge(E e, V v1, V v2, EdgeType edgeType)
e to this graph such that it connects vertex
v1 to
v2. Equivalent to
addEdge(e, new Pair(v1, v2)) . If this graph does not contain
v1,
v2, or both, implementations may choose to either silently add the vertices to the graph or throw an
IllegalArgumentException. If
edgeType is not legal for this graph, this method will throw
IllegalArgumentException. See
Hypergraph.addEdge() for a listing of possible reasons for failure.e - the edge to be addedv1 - the first vertex to be connectedv2 - the second vertex to be connectededgeType - the type to be assigned to the edgetrue if the add is successful, false otherwiseHypergraph#addEdge(Object, Collection),
#addEdge(Object, Object, Object)Pair<V,V> getEndpoints(E edge)
edge as a
Pair.edge - the edge whose endpoints are to be returnededgeV getOpposite(V vertex, E edge)
edge from
vertex. (That is, returns the vertex incident to
edge which is not
vertex.)vertex - the vertex to be queriededge - the edge to be queriededge from vertexint getVertexCount()
Collection<V> getVertices()
Collection contract, and therefore makes no guarantees about the ordering of the vertices within the
set.Collection view of all vertices in this graphV getVertex(String id)
id - the id of the vertex to be found.E getEdge(String id)
id - the id of the vertex to be foundCollection<E> getEdges()
Collection contract, and therefore makes no guarantees about the ordering of the edges within the
set.Collection view of all edges in this graphboolean removeVertex(V vertex)
vertex - the vertex to be removed.true iff the graph was modifiedboolean removeEdge(E edge)
edge from this graph.
Fails if edge is null, or is otherwise not an element of this graph.edge - the edge to removetrue if the removal is successful, false otherwiseCollection<VertexAttribute> getVertexAttributes()
Collection<EdgeAttribute> getEdgeAttributes()
void addVertexAttribute(String name, Class type, String defaultValue)
name - the name of the attribute.type - the type of attribute (int string etc).defaultValue - the default value for the attribute.void addEdgeAttribute(String name, Class type, String defaultValue)
name - the name of the attribute.type - the type of attribute (int string etc).defaultValue - the default value for the attribute.EdgeType getEdgeType()
Copyright © 2015 University of Glasgow. All rights reserved.