contract_parallel_edges#
- graph_tool.generation.contract_parallel_edges(g, weight=None)[source]#
Contract all parallel edges into simple edges.
- Parameters:
- g
Graph
Graph to be modified.
- weight
EdgePropertyMap
, optional (default:None
) Edge multiplicities.
- g
- Returns:
- weight
EdgePropertyMap
Edge multiplicities.
- weight
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