V
- the vertex type; often Coord
public abstract class Graph<V>
extends java.lang.Object
DirectedGraph
and UndirectedGraph
.Modifier and Type | Field and Description |
---|---|
protected OrderedMap<Connection<V>,Connection<V>> |
edgeMap |
protected OrderedMap<V,Node<V>> |
vertexMap |
Modifier | Constructor and Description |
---|---|
protected |
Graph() |
protected |
Graph(java.util.Collection<V> vertices) |
Modifier and Type | Method and Description |
---|---|
protected Connection<V> |
addConnection(Node<V> a,
Node<V> b) |
protected Connection<V> |
addConnection(Node<V> a,
Node<V> b,
float weight) |
Connection<V> |
addEdge(V v,
V w)
Add an edge to the graph, from v to w.
|
Connection<V> |
addEdge(V v,
V w,
float weight)
Add an edge to the graph, from v to w and with the specified weight.
|
boolean |
addVertex(V v)
Adds a vertex to the graph.
|
void |
addVertices(java.util.Collection<V> vertices)
Adds all the vertices in the collection to the graph.
|
abstract Algorithms<V> |
algorithms() |
protected boolean |
connectionExists(Node<V> u,
Node<V> v) |
boolean |
contains(V v)
Check if the graph contains a vertex.
|
protected abstract Graph<V> |
createNew() |
boolean |
edgeExists(V v,
V w)
Check if the graph contains an edge from v to w.
|
protected Connection<V> |
getEdge(Node<V> a,
Node<V> b) |
Edge<V> |
getEdge(V v,
V w)
Retrieve the edge which is from v to w.
|
int |
getEdgeCount()
Get the number of edges in the graph.
|
java.util.SortedSet<? extends Edge<V>> |
getEdges()
Get a collection containing all the edges in the graph.
|
java.util.List<? extends Edge<V>> |
getEdges(V v)
Get a collection containing all the edges which have v as a source.
|
protected Node<V> |
getNode(V v) |
protected java.util.Collection<Node<V>> |
getNodes() |
java.util.SortedSet<V> |
getVertices()
Get a collection containing all the vertices in the graph.
|
boolean |
isDirected()
Check if the graph is directed, that is whether the edges form an ordered pair or a set.
|
protected abstract Connection<V> |
obtainEdge() |
void |
removeAllEdges()
Removes all edges from the graph.
|
void |
removeAllVertices()
Removes all vertices and edges from the graph.
|
protected boolean |
removeConnection(Node<V> a,
Node<V> b) |
boolean |
removeEdge(Edge<V> edge) |
boolean |
removeEdge(V v,
V w)
Removes the edge from v to w from the graph.
|
protected void |
removeNode(Node<V> node) |
boolean |
removeVertex(V v)
Removes a vertex from the graph, and any adjacent edges.
|
void |
removeVertices(java.util.Collection<V> vertices)
Removes all the vertices in the collection from the graph, and any adjacent edges.
|
int |
size()
Get the number of vertices in the graph.
|
void |
sortEdges(java.util.Comparator<Connection<V>> comparator)
Sort the edges using the provided comparator.
|
void |
sortVertices(java.util.Comparator<V> comparator)
Sort the vertices using the provided comparator.
|
protected final OrderedMap<V,Node<V>> vertexMap
protected final OrderedMap<Connection<V>,Connection<V>> edgeMap
protected Graph()
protected Graph(java.util.Collection<V> vertices)
protected abstract Connection<V> obtainEdge()
public abstract Algorithms<V> algorithms()
public boolean addVertex(V v)
v
- the vertex to be addedpublic void addVertices(java.util.Collection<V> vertices)
vertices
- a collection of vertices to be addedpublic boolean removeVertex(V v)
v
- the vertex to be removedpublic void removeVertices(java.util.Collection<V> vertices)
vertices
- vertices a collection of vertices to be removedpublic Connection<V> addEdge(V v, V w)
v
- the source vertex of the edgew
- the destination vertex of the edgepublic Connection<V> addEdge(V v, V w, float weight)
v
- the source vertex of the edgew
- the destination vertex of the edgeweight
- the weight of the edgepublic boolean removeEdge(V v, V w)
v
- the source vertex of the edgew
- the destination vertex of the edgepublic void removeAllEdges()
public void removeAllVertices()
public void sortVertices(java.util.Comparator<V> comparator)
getVertices()
, as well as algorithms which involve iterating over all vertices.comparator
- a comparator for comparing verticespublic void sortEdges(java.util.Comparator<Connection<V>> comparator)
getEdges()
, as well as algorithms which involve iterating over all edges.comparator
- a comparator for comparing edgespublic boolean contains(V v)
v
- the vertex with which to checkpublic Edge<V> getEdge(V v, V w)
v
- the source vertex of the edgew
- the destination vertex of the edgepublic boolean edgeExists(V v, V w)
v
- the source vertex of the edgew
- the destination vertex of the edgepublic java.util.List<? extends Edge<V>> getEdges(V v)
v
- the source vertex of all the edgespublic java.util.SortedSet<? extends Edge<V>> getEdges()
public java.util.SortedSet<V> getVertices()
public boolean isDirected()
public int size()
public int getEdgeCount()
Copyright © Eben Howard 2012–2022. All rights reserved.