This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.
- PyDiGraph.contract_nodes(nodes, obj, /, check_cycle=None, weight_combo_fn=None)#
Substitute a set of nodes with a single new node.
nodes (list) – A set of nodes to be removed and replaced by the new node. Any nodes not in the graph are ignored. If empty, this method behaves like
obj (object) – The data/weight to associate with the new node.
check_cycle (bool) – If set to
True, validates that the contraction will not introduce cycles before modifying the graph. If set to
False, validation is skipped. If not provided, inherits the value of
check_cyclefrom this instance of
weight_combo_fn – An optional python callable that, when specified, is used to merge parallel edges introduced by the contraction, which will occur when multiple nodes in
nodeshave an incoming edge from the same source node or when multiple nodes in
nodeshave an outgoing edge to the same target node. If this instance of
PyDiGraphis a multigraph, leave this unspecified to preserve parallel edges. If unspecified when not a multigraph, parallel edges and their weights will be combined by choosing one of the edge’s weights arbitrarily based on an internal iteration order, subject to change.
The index of the newly created node.
DAGWouldCycle – The cycle check is enabled and the contraction would introduce cycle(s).