branching_weight#

branching_weight(G, attr='weight', default=1)[source]#

Returns the total weight of a branching.

You must access this function through the networkx.algorithms.tree module.

Parameters:
GDiGraph

The directed graph.

attrstr

The attribute to use as weights. If None, then each edge will be treated equally with a weight of 1.

defaultfloat

When attr is not None, then if an edge does not have that attribute, default specifies what value it should take.

Returns:
weight: int or float

The total weight of the branching.

Examples

>>> G = nx.DiGraph()
>>> G.add_weighted_edges_from([(0, 1, 2), (1, 2, 4), (2, 3, 3), (3, 4, 2)])
>>> nx.tree.branching_weight(G)
11