contract_parallel_edges

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:
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 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