spanner#
- graph_tool.structure.spanner(g, stretch, weight=None)[git][source]#
Return a spanner of a graph.
- Parameters:
- g
Graph Graph to be used. Edge directions, self-loops, and parallel edges are ignored.
- stretch
float Largest allowed factor between the distances in the spanner and in the graph (at least one).
- weight
EdgePropertyMap(optional, default:None) Edge lengths.
- g
- Returns:
- spanner
EdgePropertyMap Boolean edge property map marking the edges of the spanner.
- spanner
See also
minimum_spanning_treeMinimum spanning tree
shortest_distanceShortest distances
Notes
A \(t\)-spanner is a subgraph in which the distance between any two vertices is at most \(t\) times that in the graph. With \(k = \lfloor(t+1)/2\rfloor\), the randomized algorithm of Baswana and Sen [baswana-simple-2007] grows \(k - 1\) levels of clusters, whose centers are sampled with probability \(V^{-1/k}\), and keeps the lightest edge from every vertex to each neighboring cluster that it does not join, which yields a \((2k-1)\)-spanner with \(O(kV^{1+1/k})\) edges in expectation, in expected time \(O(kE)\).
References
[baswana-simple-2007]Surender Baswana and Sandeep Sen, “A simple and linear time randomized algorithm for computing sparse spanners in weighted graphs”, Random Structures & Algorithms 30, 532-563 (2007), DOI: 10.1002/rsa.20130 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["netscience"] >>> s = gt.spanner(g, 3) >>> print(g.num_edges(), s.a.sum()) 2742 2687