edu.stanford.nlp.graph
Class DirectedMultiGraph<V,E>

java.lang.Object
  extended by edu.stanford.nlp.graph.DirectedMultiGraph<V,E>
Type Parameters:
V - Type of vertices
E - Type of edges.
All Implemented Interfaces:
java.io.Serializable

public class DirectedMultiGraph<V,E>
extends java.lang.Object
implements java.io.Serializable

Simple graph library; this is directed for now. This class focuses on time efficiency rather than memory efficiency.

Author:
sonalg, John Bauer
See Also:
Serialized Form

Constructor Summary
DirectedMultiGraph()
           
 
Method Summary
 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
 boolean containsVertex(V v)
           
 java.util.List<E> convertPath(java.util.List<V> nodes, boolean directionSensitive)
           
 java.lang.Iterable<E> edgeIterable()
           
 java.util.Iterator<E> edgeIterator()
           
 boolean equals(java.lang.Object that)
           
 java.util.Set<V> getAllVertices()
           
 java.util.List<java.util.Set<V>> getConnectedComponents()
           
 java.util.List<E> getEdges(V source, V dest)
           
 int getInDegree(V vertex)
           
 int getNumVertices()
           
 int getOutDegree(V vertex)
           
 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 getTotalNumEdges()
           
 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.
 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)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DirectedMultiGraph

public DirectedMultiGraph()
Method Detail

hashCode

public int hashCode()
Be careful hashing these. They are mutable objects, and changing the object will throw off the hash code, messing up your hash table

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object that)
Overrides:
equals in class java.lang.Object

addVertex

public boolean addVertex(V v)
For adding a zero degree vertex

Parameters:
v -

add

public void add(V source,
                V dest,
                E data)
adds vertices (if not already in the graph) and the edge between them

Parameters:
source -
dest -
data -

removeEdges

public boolean removeEdges(V source,
                           V dest)

removeEdge

public boolean removeEdge(V source,
                          V dest,
                          E data)

removeVertex

public boolean removeVertex(V vertex)
remove a vertex (and its edges) from the graph.

Parameters:
vertex -
Returns:
true if successfully removes the node

removeVertices

public boolean removeVertices(java.util.Collection<V> vertices)

getNumVertices

public int getNumVertices()

getTotalNumEdges

public int getTotalNumEdges()

containsVertex

public boolean containsVertex(V v)

isEdge

public boolean isEdge(V source,
                      V dest)
only checks if there is an edge from source to dest. To check if it is connected in either direction, use isNeighbor

Parameters:
source -
dest -
Returns:

getAllVertices

public java.util.Set<V> getAllVertices()

isEmpty

public boolean isEmpty()
False if there are any vertices in the graph, true otherwise. Does not care about the number of edges.


getEdges

public java.util.List<E> getEdges(V source,
                                  V dest)

getShortestPath

public java.util.List<V> getShortestPath(V node1,
                                         V node2)
direction insensitive (the paths can go "up" or through the parents)


getShortestPathEdges

public java.util.List<E> getShortestPathEdges(V node1,
                                              V node2)

getShortestPath

public java.util.List<V> getShortestPath(V node1,
                                         V node2,
                                         boolean directionSensitive)
can specify the direction sensitivity

Parameters:
node1 -
node2 -
directionSensitive - - whether the path can go through the parents
Returns:
the list of nodes you get through to get there

getShortestPathEdges

public java.util.List<E> getShortestPathEdges(V node1,
                                              V node2,
                                              boolean directionSensitive)

convertPath

public java.util.List<E> convertPath(java.util.List<V> nodes,
                                     boolean directionSensitive)

getInDegree

public int getInDegree(V vertex)

getOutDegree

public int getOutDegree(V vertex)

getConnectedComponents

public java.util.List<java.util.Set<V>> getConnectedComponents()

incomingEdgeIterator

public java.util.Iterator<E> incomingEdgeIterator(V vertex)

incomingEdgeIterable

public java.lang.Iterable<E> incomingEdgeIterable(V vertex)

outgoingEdgeIterator

public java.util.Iterator<E> outgoingEdgeIterator(V vertex)

outgoingEdgeIterable

public java.lang.Iterable<E> outgoingEdgeIterable(V vertex)

edgeIterator

public java.util.Iterator<E> edgeIterator()

edgeIterable

public java.lang.Iterable<E> edgeIterable()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Stanford NLP Group