is_forest#

is_forest(G)[源码]#

如果 G 是森林,则返回 True。

森林是没有无向圈的图。

对于有向图,如果其基础图是森林,则 G 是森林。基础图是将每条有向边视为多重图中的一条无向边而得到的。

参数:
Ggraph

要测试的图。

返回值:
bbool

如果 G 是森林,则为 True 的布尔值。

抛出异常:
NetworkXPointlessConcept

如果 G 为空。

另请参阅

is_branching

注意

在另一种约定中,有向森林被称为 polyforest,而 forest 则对应于 branching

示例

>>> G = nx.Graph()
>>> G.add_edges_from([(1, 2), (1, 3), (2, 4), (2, 5)])
>>> nx.is_forest(G)
True
>>> G.add_edge(4, 1)
>>> nx.is_forest(G)
False
----

其他后端也实现了此函数

cugraph :GPU 加速后端。