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_adjacent_node_by_edge#
- PyDiGraph.find_adjacent_node_by_edge(node, predicate, /)#
Find any adjacent (successor) node connected with an edge that matches the condition
This method is used to find a target node that is a adjacent to a given node as a successor given an edge condition. 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, 1, 10), (1, 2, 10), (1, 3, 20), (1, 4, 30)]) >>> G.find_adjacent_node_by_edge(1, lambda x: x < 25) 'D'
- Parameters:
node (int) – The index of 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 by an edge to the given node as a successor which matches the provided condition
- Return type:
S
- Raises:
NoSuitableNeighbors: If there are no suitable nodes