local_bridges

Contents

local_bridges#

graph_tool.structure.local_bridges(g, with_span=True)[git][source]#

Return the local bridges of a graph and their spans.

Parameters:
gGraph

Graph to be used. Edge directions are ignored.

with_spanbool (optional, default: True)

If True, the spans are computed.

Returns:
localEdgePropertyMap

Boolean edge property map marking the local bridges.

spanEdgePropertyMap

The distance between the endpoints of every local bridge after its removal (\(\infty\) for bridges), and zero for the other edges. Only returned if with_span == True.

See also

find_bridges

Edges whose removal disconnects the graph

graph_tool.clustering.edge_clustering

Number of triangles of every edge

Notes

A local bridge [granovetter-strength-1973] is an edge whose endpoints have no common neighbor, so that it is not part of a triangle. The span is found by a breadth-first search between the endpoints without the edge, in parallel; the time is \(O(E\bar k)\) for the detection and up to \(O(V + E)\) per local bridge for the spans.

References

[granovetter-strength-1973]

Mark S. Granovetter, “The strength of weak ties”, American Journal of Sociology 78, 1360-1380 (1973), DOI: 10.1086/225469 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> local, span = gt.local_bridges(g)
>>> print(local.a.sum(), span.a.max())
11 inf

The local bridges can be highlighted in a drawing of the network:

>>> ecolor = g.new_ep("string", vals=np.where(local.a, "#e41a1c",
...                                           "#999999"))
>>> ewidth = g.new_ep("double", vals=np.where(local.a, 2.5, 1))
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color="#cccccc",
...               edge_color=ecolor, edge_pen_width=ewidth,
...               output="local_bridges-karate.pdf")
<...>
../_images/local_bridges-karate.png

Local bridges of Zachary’s karate club network, shown in red.#