diameter#
- graph_tool.structure.diameter(g, weights=None, epsilon=1e-08)[git][source]#
Compute the diameter of the graph.
- Parameters:
- g
Graph Graph to be used.
- weights
EdgePropertyMap(optional, default:None) Non-negative edge weights. If not supplied, every edge has unit length.
- epsilon
float(optional, default:1e-8) Relative tolerance with which lower and upper bounds are considered equal, if the weights are floating-point numbers.
- g
- Returns:
- diameter
intorfloat The diameter of the graph.
- end_pointspair of
Vertex Two vertices whose distance is the diameter.
- diameter
See also
radiusMinimum eccentricity
eccentricityEccentricity of every vertex
pseudo_diameterFast lower bound on the diameter
harmonic_diameterDiameter that accounts for disconnected pairs
peripheryVertices of maximum eccentricity
Notes
The diameter is the largest eccentricity of the vertices (see
eccentricity()), i.e. the length of the longest of the shortest paths between any two vertices. Pairs of vertices that are not connected by a path are ignored, so that the diameter of a disconnected graph is the largest diameter of its components.For undirected graphs, the algorithm of [takes-determining-2011] is used, which bounds the eccentricities as in
eccentricity(), but stops as soon as the largest lower and upper bounds coincide, and does not search from vertices that cannot change either of them. In large sparse networks, this usually requires only a few searches, each taking time \(O(V+E)\), or \(O((V+E)\log V)\) with weights, although in the worst case \(V\) searches are needed. For directed graphs, a search is made from every vertex.The function
pseudo_diameter()gives a lower bound with a few searches, without a guarantee of exactness.Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.
References
[takes-determining-2011]Frank W. Takes and Walter A. Kosters, “Determining the diameter of small world networks”, Proceedings of the 20th ACM International Conference on Information and Knowledge Management (CIKM), 1191-1196 (2011), DOI: 10.1145/2063576.2063748 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["polblogs"] >>> g = gt.extract_largest_component(g, directed=False, prune=True) >>> g.set_directed(False) >>> d, ends = gt.diameter(g) >>> print(d) 8