rustworkx.PyDiGraph.predecessor_indices#

PyDiGraph.predecessor_indices(node, /)#

在有向图中返回前驱节点索引的列表

前驱节点的定义是拥有指向指定节点的有向边的节点。在多重图(multigraph)中,两个节点可能由多条边连接,每个前驱节点的索引仅返回一次。

>>> 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.predecessor_indices(3)  # predecessors of the 'D' node
NodeIndices[2, 1, 0]

要获取这些节点的数据,请参见[predecessors]

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

参见 successor_indices()

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

Parameters:

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

Returns:

所有节点的前驱节点的索引列表

Return type:

NodeIndices