V
- Type of verticesE
- Type of edges.public class DirectedMultiGraph<V,E> extends java.lang.Object implements Graph<V,E>
Constructor and Description |
---|
DirectedMultiGraph() |
DirectedMultiGraph(DirectedMultiGraph<V,E> graph)
Creates a copy of the given graph.
|
DirectedMultiGraph(MapFactory<V,java.util.Map<V,java.util.List<E>>> outerMapFactory,
MapFactory<V,java.util.List<E>> innerMapFactory) |
Modifier and Type | Method and Description |
---|---|
void |
add(V source,
V dest,
E data)
adds vertices (if not already in the graph) and the edge between them
|
boolean |
addVertex(V v)
For adding a zero degree vertex
|
void |
clear()
clears the graph, removes all edges and nodes
|
boolean |
containsVertex(V v) |
java.util.List<E> |
convertPath(java.util.List<V> nodes,
boolean directionSensitive) |
void |
deleteDuplicateEdges()
Deletes all duplicate edges.
|
java.lang.Iterable<E> |
edgeIterable() |
java.util.Iterator<E> |
edgeIterator() |
boolean |
equals(java.lang.Object that) |
java.util.List<E> |
getAllEdges() |
java.util.Set<V> |
getAllVertices() |
java.util.Set<V> |
getChildren(V vertex)
for undirected graph, it is just the neighbors
|
java.util.List<java.util.Set<V>> |
getConnectedComponents() |
java.util.List<E> |
getEdges(V source,
V dest) |
java.util.List<E> |
getIncomingEdges(V v)
for undirected graph, it is just the edges from the node
|
int |
getInDegree(V vertex)
for undirected graph, it should just be the degree
|
java.util.Set<V> |
getNeighbors(V v)
Gets both parents and children nodes
|
int |
getNumEdges() |
int |
getNumVertices() |
int |
getOutDegree(V vertex) |
java.util.List<E> |
getOutgoingEdges(V v)
for undirected graph, it is just the edges from the node
|
java.util.Set<V> |
getParents(V vertex)
for undirected graph, it is just the neighbors
|
java.util.List<V> |
getShortestPath(V node1,
V node2)
direction insensitive (the paths can go "up" or through the parents)
|
java.util.List<V> |
getShortestPath(V node1,
V node2,
boolean directionSensitive)
can specify the direction sensitivity
|
java.util.List<E> |
getShortestPathEdges(V node1,
V node2) |
java.util.List<E> |
getShortestPathEdges(V node1,
V node2,
boolean directionSensitive) |
int |
hashCode()
Be careful hashing these.
|
java.lang.Iterable<E> |
incomingEdgeIterable(V vertex) |
java.util.Iterator<E> |
incomingEdgeIterator(V vertex) |
boolean |
isEdge(V source,
V dest)
only checks if there is an edge from source to dest.
|
boolean |
isEmpty()
False if there are any vertices in the graph, true otherwise.
|
boolean |
isNeighbor(V source,
V dest) |
java.lang.Iterable<E> |
outgoingEdgeIterable(V vertex) |
java.util.Iterator<E> |
outgoingEdgeIterator(V vertex) |
boolean |
removeEdge(V source,
V dest,
E data) |
boolean |
removeEdges(V source,
V dest) |
boolean |
removeVertex(V vertex)
remove a vertex (and its edges) from the graph.
|
boolean |
removeVertices(java.util.Collection<V> vertices) |
void |
removeZeroDegreeNodes()
Deletes nodes with zero incoming and zero outgoing edges
|
java.util.Map<V,java.util.List<E>> |
toMap()
Cast this multi-graph as a map from vertices, to the outgoing data along edges out of those vertices.
|
java.util.List<V> |
topologicalSort()
Topological sort of the graph.
|
java.lang.String |
toString() |
public DirectedMultiGraph()
public DirectedMultiGraph(MapFactory<V,java.util.Map<V,java.util.List<E>>> outerMapFactory, MapFactory<V,java.util.List<E>> innerMapFactory)
public DirectedMultiGraph(DirectedMultiGraph<V,E> graph)
graph
- The graph to copy into this object.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object that)
equals
in class java.lang.Object
public boolean addVertex(V v)
public void add(V source, V dest, E data)
public boolean removeEdges(V source, V dest)
removeEdges
in interface Graph<V,E>
public boolean removeEdge(V source, V dest, E data)
removeEdge
in interface Graph<V,E>
public boolean removeVertex(V vertex)
removeVertex
in interface Graph<V,E>
vertex
- public boolean removeVertices(java.util.Collection<V> vertices)
removeVertices
in interface Graph<V,E>
public int getNumVertices()
getNumVertices
in interface Graph<V,E>
public java.util.List<E> getOutgoingEdges(V v)
Graph
getOutgoingEdges
in interface Graph<V,E>
public java.util.List<E> getIncomingEdges(V v)
Graph
getIncomingEdges
in interface Graph<V,E>
public int getNumEdges()
getNumEdges
in interface Graph<V,E>
public java.util.Set<V> getParents(V vertex)
Graph
getParents
in interface Graph<V,E>
public java.util.Set<V> getChildren(V vertex)
Graph
getChildren
in interface Graph<V,E>
public java.util.Set<V> getNeighbors(V v)
getNeighbors
in interface Graph<V,E>
v
- public void clear()
public boolean containsVertex(V v)
containsVertex
in interface Graph<V,E>
public boolean isEdge(V source, V dest)
public boolean isNeighbor(V source, V dest)
isNeighbor
in interface Graph<V,E>
public java.util.Set<V> getAllVertices()
getAllVertices
in interface Graph<V,E>
public java.util.List<E> getAllEdges()
getAllEdges
in interface Graph<V,E>
public boolean isEmpty()
public void removeZeroDegreeNodes()
removeZeroDegreeNodes
in interface Graph<V,E>
public java.util.List<V> getShortestPath(V node1, V node2)
public java.util.List<V> getShortestPath(V node1, V node2, boolean directionSensitive)
node1
- node2
- directionSensitive
- - whether the path can go through the parentspublic java.util.List<E> getShortestPathEdges(V node1, V node2, boolean directionSensitive)
public java.util.List<E> convertPath(java.util.List<V> nodes, boolean directionSensitive)
public int getInDegree(V vertex)
Graph
getInDegree
in interface Graph<V,E>
public int getOutDegree(V vertex)
getOutDegree
in interface Graph<V,E>
public java.util.List<java.util.Set<V>> getConnectedComponents()
getConnectedComponents
in interface Graph<V,E>
public void deleteDuplicateEdges()
public java.util.Iterator<E> edgeIterator()
public java.lang.Iterable<E> edgeIterable()
public java.util.List<V> topologicalSort()
CyclicGraphException
- (a subtype of IllegalStateException) if this graph is not a DAGpublic java.util.Map<V,java.util.List<E>> toMap()
public java.lang.String toString()
toString
in class java.lang.Object