new Graph()
Generic graph class. Supports vertices and edge insertion, deletion. Multiple edge connections between vertices,
directed edges, self connected vertices.
Methods

addEdge(source, target, properties) → {algo.core.GraphEdge}

add a new edge to the graph
Parameters:
Name Type Description source
target
properties
Returns:
 Type
 algo.core.GraphEdge

addRandomEdge()

a useful helper function for testing and simple visualization, adds a random edge between two random vertices that are not already connected in either direction

addVertex(properties) → {algo.core.GraphVertex}

add a vertex to the graph and invoke the optional callback
Parameters:
Name Type Description properties
Returns:

findVertices(property, value)

find all vertices with a given property value.
Parameters:
Name Type Description property
value

getAdjacentVertices(vertex) → {Array}

return a set of vertices that are connected to the given vertex or vertex list by an in or out edge NOTE: The list does not include the starting vertex or vertices.
Parameters:
Name Type Description vertex
algo.core.GraphVertex  Array Returns:
 array of algo.core.GraphVertex Type
 Array

getComponents()

return a list of list of vertices where each sublist defines a discrete/connected component of the graph. The components are sorted according to size with the largest components first.

getEdges(v1, v2)

return all directed edges from v1 > v2
Parameters:
Name Type Description v1
v2

getInVertices(vertex) → {Array}

return a set of vertices that have edges pointing at the given vertex. Since multiedges are supported we ensure a set is returned
Parameters:
Name Type Description vertex
algo.core.GraphVertex Returns:
 array of algo.core.GraphVertex Type
 Array

getOutVertices(vertex) → {Array}

return a set of vertices that are connected to the given vertex by an out bound edge
Parameters:
Name Type Description vertex
algo.core.GraphVertex Returns:
 array of algo.core.GraphVertex Type
 Array

getVertexEdges(vertex) → {Array}

return all edges that are either in or out of the vertex
Parameters:
Name Type Description vertex
Returns:
all the edges attached to this vertex regardless of direction Type
 Array

hasEdge(source, target)

return true if there is an edge between source, target
Parameters:
Name Type Description source
target
Returns:
boolean 
removeEdge(edge)

remove an edge from the graph. Removed references to that edge from each vertex
Parameters:
Name Type Description edge

removeEdgelessVertices()

helper for making pretty graphs. Remove any vertex that has no edge

removeVertex(vertex) → {Array}

remove a vertex from the graph
Parameters:
Name Type Description vertex
algo.core.GraphVertex Returns:
any edges that were removed in addition to the vertex that was removed Type
 Array