Class DirectedGraph

A directed graph.
Some methods in this class have two versions, one that operates
on graph nodes, and another that operates on
node weights. The latter form is called the weights version.
More specifically, the weights version of an operation takes individual
node weights or arrays of weights as arguments, and, when applicable, returns
individual weights or arrays of weights.

Multiple edges in a graph can be directed between the same pair of nodes.
Thus, directed multigraphs are supported.

Constructor Detail

DirectedGraph

DirectedGraph

Construct an empty directed graph with enough storage allocated
for the specified number of nodes. Memory management is more
efficient with this constructor if the number of nodes is
known.

Parameters:

nodeCount - The integer specifying the number of nodes

DirectedGraph

public DirectedGraph(int nodeCount,
int edgeCount)

Construct an empty directed graph with enough storage allocated for the
specified number of edges, and number of nodes. Memory
management is more efficient with this constructor if the
number of nodes and edges is known.

backwardReachableNodes

Find all the nodes that can be reached backward from the
specified node (weights version).
If the specified weight
is null, find all the nodes that can be reached backward from any node
that is unweighted.
The reachable nodes do not include the argument unless
there is a loop from the specified node back to itself.

Parameters:

weight - A node weight in this graph.

Returns:

An array of node weights that are backward-reachable from the
nodes that have the specified weight; each element is an
Object.

backwardReachableNodes

Find all the nodes that can be reached backward from the
specified collection of nodes.
The reachable nodes do not include the specific ones unless
there is a loop from the specified node back to itself.

Parameters:

nodeCollection - A collection of nodes in this graph;
each element is a Node.

Returns:

The collection of nodes that are backward-reachable from
the specified nodes; each element is a Node.

backwardReachableNodes

Find all the nodes that can be reached backward from the
specified collection of nodes (weights version).
The reachable nodes do not include the weights in the argument unless
there is a loop from the specified node back to itself.

Parameters:

weights - An array of node weights in this graph; each
element is an Object.

Returns:

An array of node weights that are backward-reachable from the
nodes that have the specified weights; each element is an
Object.

predecessors

Return all of the predecessors of a given node in the form of a
a collection. Each element of the collection is a Node.
A predecessor of a node X is a node that is the source
of an edge whose sink is X. All elements in the returned collection
are unique nodes.

reachableNodes

public java.lang.Object[] reachableNodes(java.lang.Object weight)

Find all the nodes that can be reached from any node that has the
specified node weight (weights version). If the specified weight
is null, find all the nodes that can be reached from any node
that is unweighted.

Parameters:

weight - The specified node weight.

Returns:

An array of node weights reachable from the specified weight;
each element is an Object.

reachableNodes

public java.lang.Object[] reachableNodes(java.lang.Object[] weights)

Find all the nodes that can be reached from the specified collection
of nodes (weights version). The reachable nodes do not include a
specified one unless there is a loop from the specified node back to
itself.

Parameters:

weights - An array of node weights; each element is an
Object.

Returns:

The array of nodes that are reachable from
the specified one; each element is an Object.

selfLoopEdgeCount

Return the number of self loop edges of a specified node.
A directed self loop edge (an edge whose source and sink nodes are
identical) is both an input edge and an output
edge of the incident node, but it is not duplicated in the set of
incident edges. Thus, the number of edges incident edges
to a node is equal to
I + O - S, where I is the number of input edges,
O is the number of output edges, and S is the number
of self loop edges.

successors

Return all of the successors of a given node in the form of a
a collection. Each element of the collection is a Node.
A successor of a node X is a node that is the sink
of an edge whose source is X. All elements in the returned collection
are unique nodes.

topologicalSort

Sort a collection of graph nodes in their topological order as long as
no two of the given nodes are mutually reachable by each other.
This method uses the transitive closure matrix. Since generally
the graph is checked for cyclicity before this method is
called, the use of the transitive closure matrix should
not add any overhead. A bubble sort is used for the internal
implementation, so the complexity is O(V^2).

Parameters:

nodeCollection - The collection of nodes to be sorted;
each element is a Node.

Returns:

The nodes in their sorted order in the form of a list;
each element is a Node.

topologicalSort

Sort the given nodes in their topological order as long as
no two of the given nodes are mutually reachable by each other
(weights version).
The set of nodes to sort is taken as the set of nodes whose
weights are contained in the specified weight set.
The weights of the sorted nodes are returned.

_connectedSubGraph

Given a node, get all the edges and nodes that are connected
to it directly and/or indirectly. Add them in the given graph.
Remove the nodes from the remaining nodes.
FIXME: Hidden edges not considered.

Parameters:

node - The given node.

graph - The given graph.

remainingNodes - Set of nodes that haven't been reached.

_disconnect

Disconnect an edge from a node that it is incident to.
Specifically, this method removes the edge from the set of
edges that are considered incident to the node in this graph.
This method does nothing if the given edge is not incident to the
given node.
This method should be overridden to incorporate additional operations
that are required to disconnect an edge from a node (see, for
example, DirectedGraph.#_disconnect(Edge, Node)).