V - The vertex typeE - The edge typepublic class Graph<V extends Vertex,E extends Edge<V>>
extends java.lang.Object
V
and a set of edges of type E.| Constructor and Description |
|---|
Graph()
Creates a graph by creating empty lists of edges, vertices and other properties
By default, the graph is undirected
|
Graph(boolean directed)
Creates a directed or undirected graph, depending on the provided parameter value
|
Graph(java.util.List<V> vertices,
java.util.List<E> edges) |
| Modifier and Type | Method and Description |
|---|---|
void |
addEdge(E... edge) |
void |
addVertex(V... vert) |
void |
addVertex(V v)
Add one vertex to the graph
|
void |
addVertexBeginning(V v)
Adds vertex as to the graph before any other vertex
|
int[][] |
adjacencyMatrix()
Calculates the adjacency matrix of the graph
|
java.util.List<E> |
adjacentEdges(V v) |
java.util.List<V> |
adjacentVertices(V v)
All vertices adjacent to the given one
|
java.util.LinkedList<E> |
allEdges(V v)
All edges leaving or entering the given vertex
|
E |
edgeBetween(V v1,
V v2)
Checks if there is an edge between the two given graph vertices and return is
it if exists
|
java.util.List<E> |
edgeesBetween(V v1,
V v2)
Returns all edges between vertices v1 and v2
|
java.util.List<E> |
edgesBetween(java.util.List<V> vertices)
Finds all edges between certain vertices
|
boolean |
equals(java.lang.Object obj) |
java.util.Map<V,java.util.List<E>> |
getAdjacentLists() |
java.util.List<E> |
getAllSelfLoopEdges()
All edges which connect one vertex to itself - loops
|
java.util.List<V> |
getAllSinks()
Finds all sinks in the graph
|
java.util.List<V> |
getAllSources()
Finds all sources in the graph
|
java.util.List<E> |
getEdges() |
java.util.List<V> |
getTreeLeaves(V root) |
V |
getVertexByContent(java.lang.Object content)
Return a vertex with the provided content
|
java.util.List<V> |
getVertices() |
int |
graphMaxDegree()
Max vertex degree
|
boolean |
hasEdge(V v1,
V v2)
Checks if vertices v1 and v2 are connected i.e.
|
int |
hashCode() |
boolean |
hasSelfLoopEdges()
Checks if graph has loops
|
boolean |
hasVertex(V v)
Checks if the graph contains a certain vertex
|
int |
inDegree(V v)
In degree of the given vertex
|
java.util.List<E> |
inEdges(V v)
All edges entering v
|
boolean |
isBiconnected()
Checks if a graph is biconnected.
|
boolean |
isConnected()
Checks is graph is connected
|
boolean |
isConnected(java.util.List<V> excluding)
Checks is graph is connected presumed that certain vertices are removed
|
boolean |
isCyclic()
Check if the graph is cyclic
|
boolean |
isDirected() |
boolean |
isRing()
Check if the graph is a ring
|
boolean |
isSimple()
Checks if graph is simple
|
boolean |
isSink(V v)
Checks if vertex is a sink (vertex with no outgoing edges)
|
boolean |
isSource(V v)
Checks if vertex is a source (vertex with no incoming edges)
|
boolean |
isTree()
Check if the graph is a tree
|
java.util.List<Graph<V,E>> |
listBiconnectedComponents()
Finds all biconnected components of the graph
|
java.util.List<V> |
listCutVertices()
Finds all cut vertices of a graph
|
java.util.List<java.util.List<E>> |
listMultiEdges()
Finds all multiedges of the graph
|
int |
outDegree(V v)
Out degree of the given node
|
java.util.List<E> |
outEdges(V v)
All edges leaving v
|
void |
printAdjacencyMatrix()
Prints adjacency matrix
|
void |
removeEdge(E e)
Removes an edge from the graph and updates all relevants structures
|
void |
removeVertex(V v)
Removes a vertex from the graph, thus updating all relevant structures
and also removing the edges it was a part of
|
void |
setDirected(boolean directed) |
void |
setEdges(java.util.List<E> edges) |
void |
setVertices(java.util.List<V> vertices) |
Graph<V,E> |
subgraph(java.util.List<V> subgraphVertices)
Creates a subgraph of the graph containing the
given vertices
|
java.lang.String |
toString() |
int |
vertexDegree(V v)
Number of edges entering or leaving v
|
public Graph()
public Graph(boolean directed)
directed - true if the graph should be directed, false otherwisepublic boolean hasVertex(V v)
v - Vertextrue if the graph contains v, false otherwisepublic void addVertex(V... vert)
public void addVertex(V v)
v - Vertex to addpublic void addVertexBeginning(V v)
v - Vertex to addpublic void removeVertex(V v)
v - Vertex to removepublic void addEdge(E... edge)
public boolean hasEdge(V v1, V v2)
v1 - Source vertexv2 - Destination vertextrue if there is and edge between v1 and v2, otherwise falsepublic java.util.List<E> edgeesBetween(V v1, V v2)
v1 - Source vertexv2 - Destination vertexpublic E edgeBetween(V v1, V v2)
v1 - The first vertexv2 - The second vertexv1 and v2 if it exists, @{code null} otherwisepublic void removeEdge(E e)
e - Edge to be removedpublic java.util.List<E> outEdges(V v)
v - Vertexvpublic java.util.List<V> adjacentVertices(V v)
v - Vertexvpublic int outDegree(V v)
v - Vertexvpublic java.util.List<E> inEdges(V v)
v - Vertexvpublic int inDegree(V v)
v - Vertexvpublic boolean isSource(V v)
v - Vertextrue if vertex v is a source, false otherwisepublic boolean isSink(V v)
v - Vertextrue if vertex v is a sink, false otherwisepublic java.util.LinkedList<E> allEdges(V v)
v - Vertexvpublic java.util.List<E> edgesBetween(java.util.List<V> vertices)
vertices - A list of verticesvertices listpublic java.util.List<E> getAllSelfLoopEdges()
public boolean hasSelfLoopEdges()
true if the graph has loops, false otherwisepublic boolean isSimple()
true if the graph is simple, false otherwisepublic int vertexDegree(V v)
v - Vertexvpublic int graphMaxDegree()
public boolean isConnected()
true if the graph is connected, false otherwisepublic boolean isTree()
true if the graph is a tree, false otherwisepublic java.util.List<V> getTreeLeaves(V root)
root - Root of the treepublic boolean isConnected(java.util.List<V> excluding)
excluding - Vertices without whom the graph should still be connectedtrue if the graph without vertices belonging to excluding
is connected, false otherwisepublic boolean isCyclic()
true if the graph is a tree, false otherwisepublic java.util.List<V> getAllSinks()
public java.util.List<V> getAllSources()
public java.util.List<java.util.List<E>> listMultiEdges()
public boolean isRing()
true if the graph is a tree, false otherwisepublic boolean isBiconnected()
true if graph is biconnected, otherwise falsepublic java.util.List<V> listCutVertices()
public java.util.List<Graph<V,E>> listBiconnectedComponents()
public Graph<V,E> subgraph(java.util.List<V> subgraphVertices)
subgraphVertices - Vertices that should be in the subgraphpublic int[][] adjacencyMatrix()
public void printAdjacencyMatrix()
public V getVertexByContent(java.lang.Object content)
content - Searched contentpublic java.util.List<V> getVertices()
public void setVertices(java.util.List<V> vertices)
vertices - Vertices to setpublic java.util.List<E> getEdges()
public void setEdges(java.util.List<E> edges)
edges - Edges to setpublic boolean isDirected()
true if graph is directed, false otherwisepublic void setDirected(boolean directed)
directed - Value of directed property to setpublic java.lang.String toString()
toString in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Object