Class DistanceStatistics
java.lang.Object
edu.uci.ics.jung.algorithms.shortestpath.DistanceStatistics
Statistics relating to vertex-vertex distances in a graph.
Formerly known as GraphStatistics in JUNG 1.x.
- Author:
- Scott White, Joshua O'Madadhain
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <V,E> com.google.common.base.Function <V, Double> averageDistances(Hypergraph<V, E> g) For each vertexving, calculates the average shortest path length fromvto all other vertices ing, ignoring edge weights.static <V,E> com.google.common.base.Function <V, Double> averageDistances(Hypergraph<V, E> graph, Distance<V> d) For each vertexvingraph, calculates the average shortest path length fromvto all other vertices ingraphusing the metric specified byd, and returns the results in aMapfrom vertices toDoublevalues.static <V,E> double diameter(Hypergraph<V, E> g) Returns the diameter ofg, ignoring edge weights.static <V,E> double diameter(Hypergraph<V, E> g, Distance<V> d) Returns the diameter ofgusing the metric specified byd.static <V,E> double diameter(Hypergraph<V, E> g, Distance<V> d, boolean use_max) Returns the diameter ofgusing the metric specified byd.
-
Constructor Details
-
DistanceStatistics
public DistanceStatistics()
-
-
Method Details
-
averageDistances
public static <V,E> com.google.common.base.Function<V,Double> averageDistances(Hypergraph<V, E> graph, Distance<V> d) For each vertexvingraph, calculates the average shortest path length fromvto all other vertices ingraphusing the metric specified byd, and returns the results in aMapfrom vertices toDoublevalues. If there exists an ordered pair<u,v>for whichd.getDistance(u,v)returnsnull, then the average distance value foruwill be stored asDouble.POSITIVE_INFINITY).Does not include self-distances (path lengths from
vtov).To calculate the average distances, ignoring edge weights if any:
Map distances = DistanceStatistics.averageDistances(g, new UnweightedShortestPath(g));
To calculate the average distances respecting edge weights:DijkstraShortestPath dsp = new DijkstraShortestPath(g, nev); Map distances = DistanceStatistics.averageDistances(g, dsp);
wherenevis an instance ofTransformerthat is used to fetch the weight for each edge.- Type Parameters:
V- the vertex typeE- the edge type- Parameters:
graph- the graph for which distances are to be calculatedd- the distance metric to use for the calculation- Returns:
- a map from each vertex to the mean distance to each other (reachable) vertex
- See Also:
-
averageDistances
For each vertexving, calculates the average shortest path length fromvto all other vertices ing, ignoring edge weights.- Type Parameters:
V- the vertex typeE- the edge type- Parameters:
g- the graph for which distances are to be calculated- Returns:
- a map from each vertex to the mean distance to each other (reachable) vertex
- See Also:
-
diameter
Returns the diameter ofgusing the metric specified byd. The diameter is defined to be the maximum, over all pairs of verticesu,v, of the length of the shortest path fromutov. If the graph is disconnected (that is, not all pairs of vertices are reachable from one another), the value returned will depend onuse_max: ifuse_max == true, the value returned will be the the maximum shortest path length over all pairs of connected vertices; otherwise it will beDouble.POSITIVE_INFINITY.- Type Parameters:
V- the vertex typeE- the edge type- Parameters:
g- the graph for which distances are to be calculatedd- the distance metric to use for the calculationuse_max- iftrue, return the maximum shortest path length for all graphs; otherwise, returnDouble.POSITIVE_INFINITYfor disconnected graphs- Returns:
- the longest distance from any vertex to any other
-
diameter
Returns the diameter ofgusing the metric specified byd. The diameter is defined to be the maximum, over all pairs of verticesu,v, of the length of the shortest path fromutov, orDouble.POSITIVE_INFINITYif any of these distances do not exist.- Type Parameters:
V- the vertex typeE- the edge type- Parameters:
g- the graph for which distances are to be calculatedd- the distance metric to use for the calculation- Returns:
- the longest distance from any vertex to any other
- See Also:
-
diameter
Returns the diameter ofg, ignoring edge weights.- Type Parameters:
V- the vertex typeE- the edge type- Parameters:
g- the graph for which distances are to be calculated- Returns:
- the longest distance from any vertex to any other
- See Also:
-