contract_parallel_edges#
- graph_tool.generation.contract_parallel_edges(g, weight=None)[source]#
Contract all parallel edges into simple edges, keeping track of their multiplicities.
- 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_edgesexpand edge multiplicities into parallel edges.
Notes
This algorithm runs in time \(O(N + E)\) where \(N\) and \(E\) are the number of vertices and edges in the graph, respectively.
Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.
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