|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface GraphAnalyzer<T>
Interface for an object that analyzes basic graph structural statistics. Objects of this type provide a number of methods for calculating statistics about average graph topology, including shortest paths and connected components, diameter, degree distributions, etc.
Caching (optional).
The intent is that objects of this type accept a Graph
object in the constructor and then all operations are defined with
respect to that Graph. If this object is made immutable,
and the Graph is not changed during the existence of this
object, then the GraphAnalyzer can cache intermediate results.
For example, a number of operations require essentially the same loop
over the graph; the GraphAnalyzer can arrange to perform that
loop only once and to cache the results of the computation.
Regardless of whether implementations of this interface support caching, the constructor for any concrete implementations MUST run in O(1) time and consume only O(1) space. In particular, they MUST NOT pre-compute/pre-allocate any expensive values at construction time. They MUST wait until requested via one of the methods defined in this interface. This avoids potentially computing expensive results that will never be requested by the user.
The documentation of all methods in this interface assumes a
directed graph, G, containing V nodes and E
edges. The notation x^p represents "x raised to
the pth power", not "x xor p". The
notation x_{ij} should be read "x subscripted with
ij".
Note that none of the methods in this interface depend on the
type of the Graph's nodes -- GraphAnalyzer only
cares about the structure of the graph, not its contents.
However, objects of this type MUST be Java generics because they
will be initialized with Graphs of some specific type.
Efficiency The runtime bounds given for a number of the operations in this interface are fairly loose. It is certainly possible to carry out a number of these operations (such as all-pairs shortest paths and computation of strongly connected components) more efficiently than the values given here. But the values given here are amenable to simple implementations. Ambitious designers are encouraged to find more efficient implementations of these operations.
| Method Summary | |
|---|---|
int[][] |
allPairsShortestPaths()
Compute the all-pairs shortest paths distances between every pair of nodes in the graph. |
double |
avgInDegree()
Computes the average INDEGREE for any node in the graph. |
double |
avgOutDegree()
Computes the average OUTDEGREE for any node in the graph. |
double |
avgShortestPathDistance()
Returns the average distance between all reachable pairs of nodes. |
int |
countSCCs()
Returns the number of strongly connected components (SCCs) in the graph. |
int |
diameter()
Computes the diameter of the reachable portion of the graph. |
double[] |
inDegreeDistribution()
Calculate the probability mass function (PMF) of the indegrees of nodes in this graph. |
int |
maxInDegree()
Computes the maximum INDEGREE for any node in the graph. |
int |
maxOutDegree()
Computes the maximum OUTDEGREE for any node in the graph. |
int |
maxSCCSize()
Return the size of the largest strongly connected component (SCC) in the graph. |
int |
minInDegree()
Computes the minimum INDEGREE for any node in the graph. |
int |
minOutDegree()
Computes the minimum OUTDEGREE for any node in the graph. |
double[] |
outDegreeDistribution()
Calculate the probability mass function (PMF) of the outdegrees of nodes in this graph. |
| Method Detail |
|---|
int[][] allPairsShortestPaths()
The returned matrix has one row and one column for every node in the graph. The interpretation of this matrix is:
dist[i][j]==dmeans that the shortest distance starting at node
i and
ending at node j is d. (That is, nodes whose
Graph.getNodeID(Object) is i and j.)
The distance from node i to itself is 0 and
if j is not reachable from i then
dist[i][j]==Integer.MAX_VALUE (i.e., infinity).
If the graph is empty (contains no nodes or edges), then this
returns a size-0 matrix. That is, it returns essentially
new int[0].
This routine MUST run in O(V^3) time for a graph containing V nodes. It SHOULD require only O(V^2) space. It MAY use more than O(V^2) space, but not more than O(V^3) space.
double avgShortestPathDistance()
i,j, such that
dist[i][j]<Integer.MAX_VALUE and returns the average
distance over those nodes.
An empty graph is defined to have an average distance of 0.
This method MUST run in time O(V^2) beyond that
required by the allPairsShortestPaths() method. (That
is, this method MAY execute allPairsShortestPaths()
and then spend up to O(V^2) time beyond that.
int countSCCs()
An empty graph is defined to have 0 strongly connected components.
This MUST run in time O(V^3) and require at most O(V^2) space. However, most of that time/space is consumed in computing all-pairs shortest-paths (in the most straightforward implementation). This MUST require no more than O(V^2) time beyond that required by the all-pairs shortest paths execution, and comsume at most O(V) additional space.
int maxSCCSize()
countSCCs() finds how many
SCCs there are, this identifies the largest such component and
returns the size (number of nodes) of that component.
An empty graph is defined to have 0 SSCs, the largest of which is size 0.
This MUST run in time no more than O(S) beyond that required
by countSCCs(), for a graph containing S SCCs.
int diameter()
dmax=max_{i,j in V} ( d_{ij} )
subject to:
d_{ij}<Integer.MAX_VALUE
An empty graph is defined to have a diameter of 0.
This MUST run in time O(V^3)
int maxInDegree()
An empty graph is defined to have a max indegree of 0.
This method MUST run in O(V+E) time for a graph with V nodes.
int minInDegree()
An empty graph is defined to have a min indegree of 0.
This method MUST run in O(V+E) time for a graph with V nodes.
double avgInDegree()
An empty graph is defined to have an average indegree of 0.0.
This method MUST run in O(V+E) time for a graph with V nodes.
double[] inDegreeDistribution()
0, represented by result[0], and the
maximum is n, represented by result[n].
Note that this method is responsible for allocating space for the result array. It MUST NOT allocate more (or less) space than necessary.
If the graph is empty, this returns an empty distribution. That is, a distribution containing 0 elements.
This method MUST run in O(V+E) time for a graph with V nodes.
int maxOutDegree()
An empty graph is defined to have a max outdegree of 0.
This method MUST run in O(V) time for a graph with V nodes.
int minOutDegree()
An empty graph is defined to have a min outdegree of 0.
This method MUST run in O(V) time for a graph with V nodes.
double avgOutDegree()
An empty graph is defined to have an average outdegree of 0.0.
This method MUST run in O(V) time for a graph with V nodes.
double[] outDegreeDistribution()
0, represented by result[0], and the
maximum is n, represented by result[n].
Note that this method is responsible for allocating space for the result array. It MUST NOT allocate more (or less) space than necessary.
If the graph is empty, this returns an empty distribution. That is, a distribution containing 0 elements.
This method MUST run in O(V) time for a graph with V nodes.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||