rustworkx.PyDiGraph.remove_node_retain_edges#
- PyDiGraph.remove_node_retain_edges(node, /, use_outgoing=False, condition=None)#
Remove a node from the graph and add edges from all predecessors to all successors
By default the data/weight on edges into the removed node will be used for the retained edges.
This function has a minimum time complexity of \(\mathcal O(e_i e_o)\), where \(e_i\) and \(e_o\) are the numbers of incoming and outgoing edges respectively. If your
condition
can be cast as an equality between two hashable quantities, consider usingremove_node_retain_edges_by_key()
instead, or if yourcondition
is referential object identity of the edge weights, considerremove_node_retain_edges_by_id()
.- Parameters:
node (int) – The index of the node to remove. If the index is not present in the graph it will be ingored and this function willl have no effect.
use_outgoing (bool) – If set to true the weight/data from the edge outgoing from
node
will be used in the retained edge instead of the default weight/data from the incoming edge.condition –
A callable that will be passed 2 edge weight/data objects, one from the incoming edge to
node
the other for the outgoing edge, and will return abool
on whether an edge should be retained. For example setting this kwarg to:lambda in_edge, out_edge: in_edge == out_edge
would only retain edges if the input edge to
node
had the same data payload as the outgoing edge.