Note

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.

rustworkx.PyDiGraph.find_predecessor_node_by_edge#

PyDiGraph.find_predecessor_node_by_edge(node, predicate, /)#

Find any predecessor node connected with an edge that matches the condition

A predecessor is defined as a node that has a directed edge pointing to the specified node. This method returns one arbitrary node where the edge matches the condition.

>>> G = rx.PyDiGraph()
>>> G.add_nodes_from(["A", "B", "C", "D", "E"])
NodeIndices[0, 1, 2, 3, 4]
>>> G.extend_from_weighted_edge_list([(0, 3, 10), (1, 3, 20), (2, 3, 30), (3, 4, 10)])
>>> G.find_predecessor_node_by_edge(3, lambda x: x < 25)
'B'

To get all such nodes, see find_predecessors_by_edge().

Parameters:
  • node (int) – The node to use as the source of the search

  • predicate (Callable) – A Python callable that will take a single parameter, the edge object, and will return a boolean if the edge matches or not

Returns:

The node object that is connected as a predecessor by an edge to the given node which matches the provided condition

Return type:

S

Raises:

NoSuitableNeighbors: If there are no suitable nodes