graph_tool.generation.contract_parallel_edges#

graph_tool.generation.contract_parallel_edges(g, weight=None)[source]#

Contract all parallel edges into simple edges.

Parameters:
gGraph

Graph to be modified.

weightEdgePropertyMap, optional (default: None)

Edge multiplicities.

Returns:
weightEdgePropertyMap

Edge multiplicities.

See also

expand_parallel_edges

expand edge multiplicities into parallel edges.

Notes

This algorithm runs in time \(O(N + E)\) where \(N\) and \(E\) are the number of nodes and edges in the graph, respectively.

Examples

>>> u = gt.collection.data["polblogs"].copy()
>>> u.set_directed(False)
>>> g = u.copy()
>>> w = gt.contract_parallel_edges(g)
>>> gt.expand_parallel_edges(g, w)
>>> gt.similarity(g, u)
1.0