edge_boundary

Contents

edge_boundary#

graph_tool.structure.edge_boundary(g, S, T=None)[git][source]#

Return the edge boundary of a set of vertices.

Parameters:
gGraph

Graph to be used.

Siterable of int or VertexPropertyMap

Set of vertices, as a sequence of vertices or a Boolean vertex property map.

Titerable of int or VertexPropertyMap (optional, default: None)

Second set of vertices. If not given, the complement of S is used.

Returns:
edgesnumpy.ndarray

Array with one row (s, t, i) for every edge of the boundary, where s is in S, t in T, and i is the edge index.

See also

vertex_boundary

Vertex counterpart

cut_size

Size of the cut between two sets of vertices

Notes

The edge boundary contains the edges with one endpoint in \(S\) and the other in \(T\); for directed graphs, only the out-edges of the vertices in \(S\) are considered. The time is \(O(V + E)\).

Examples

>>> g = gt.collection.data["karate"]
>>> print(gt.edge_boundary(g, [0, 1, 2])[:4])
[[0 3 3]
 [1 3 4]
 [2 3 5]
 [0 4 6]]

The set and its boundary can be shown in a drawing of the network:

>>> es = gt.edge_boundary(g, [0, 1, 2])
>>> vcolor = g.new_vp("string", val="#cccccc")
>>> for v in [0, 1, 2]:
...     vcolor[v] = "#9bbedc"
>>> inb = g.new_ep("bool")
>>> inb.a[es[:, 2]] = True
>>> ecolor = g.new_ep("string", vals=np.where(inb.a, "#e41a1c",
...                                           "#999999"))
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=vcolor,
...               edge_color=ecolor, output="edge_boundary-karate.pdf")
<...>
../_images/edge_boundary-karate.png

Edge boundary (red) of the set of vertices 0, 1 and 2 (blue) of Zachary’s karate club network.#