rustworkx.PyDiGraph.predecessors#

PyDiGraph.predecessors(node, /)#

返回一个有向图中所有节点前驱的数据列表

前置节点是指通过有向边指向指定节点的节点。在多图中,两个节点可以通过多条边连接,每个前置节点只返回一次。

>>> G = rx.PyDiGraph()
>>> G.add_nodes_from(["A", "B", "C", "D", "E"])
NodeIndices[0, 1, 2, 3, 4]
>>> G.extend_from_edge_list([(0, 3), (1, 3), (2, 3), (3, 4)])
>>> G.predecessors(3)  # predecessors of the 'D' node
['C', 'B', 'A']
>>> G.predecessors(10) # predecessors of an non-existing node
[]

另见

要根据连接边的属性筛选前置节点,请参阅find_predecessors_by_edge()

另请参见 successors()

对于无向图,请参见neighbors()

要获取更远的先行节点,请参阅ancestors()

Parameters:

节点 (int) – 要获取其前驱节点的索引

Returns:

所有节点前驱节点的节点数据列表

Return type:

列表[S]