简体   繁体   English

maximum_spanning_tree networkx 没有属性

[英]maximum_spanning_tree networkx has no attribute

I am trying to find maximum spanning tree of a network using networkx python module.我正在尝试使用 networkx python 模块查找网络的最大生成树。 According to documentation specified[link below], nx.maximum_spanning_tree(G) should do this work.根据指定的文档[链接如下],nx.maximum_spanning_tree(G) 应该完成这项工作。 But i am getting error但我收到错误

  File "air_traffic_network_base.py", line 65, in <module>
    max_spanning_tree = nx.maximum_spanning_tree(net)
AttributeError: 'module' object has no attribute 'maximum_spanning_tree'

Here is the code snippet:这是代码片段:

net = nx.read_weighted_edgelist(graph_file)
min_spanning_tree = nx.minimum_spanning_tree(net) #no error
max_spanning_tree = nx.maximum_spanning_tree(net) #error here

Documentation: http://networkx.readthedocs.org/en/latest/reference/generated/networkx.algorithms.tree.mst.maximum_spanning_tree.html文档: http : //networkx.readthedocs.org/en/latest/reference/generated/networkx.algorithms.tree.mst.maximum_spanning_tree.html

Networkx version (nx.__version__):
1.10

I believe i am using latest networkx python module.(minimum_spanning_tree function call works without any error).我相信我正在使用最新的 networkx python 模块。(minimum_spanning_tree 函数调用没有任何错误)。

Please help.请帮忙。

I believe this is due to your net being directed.我相信这是由于您的网络被定向。 If that is the case, maximum_spanning_tree will not work.如果是这种情况,maximum_spanning_tree 将不起作用。 Since as the documentation reports, it can only be done on an undirected graph.由于文档报告,它只能在无向图上完成。

The models that can be represented by the two are equivalent, and so it's just a change to the way you represent the model with factors.可以由两者表示的模型是等效的,因此这只是您用因子表示模型的方式的改变。 To make a directed tree from an undirected one, just pick any node as the root and orient the edges away from the root.要从无向树制作有向树,只需选择任何节点作为根并将边缘定向为远离根。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM