2017-06-28 128 views
1

我有一个有27000个弧的定向网络,每个都有一个重量。用有向图的网络计算最大流量值

随着代码:

G=nx.Graph(G) 
nx.maximum_flow(G,'CHN',"CHL") 

我得到的错误:

NetworkXUnbounded: Infinite capacity path, flow unbounded above.

有谁知道如何获得最大流量值?

顺便说一句,当我运行:G.edges(data=True),我得到了它这样的东西一本字典:

('BGR', 'NCL', {'Edge Id': u'3727', 'weight': 334716.84}), 
('BGR', 'ARE', {'Edge Id': u'3606', 'weight': 28347011.33}), 
('BGR', 'ARG', {'Edge Id': u'3733', 'weight': 26294089.16}), 
('BGR', 'SDN', {'Edge Id': u'3591', 'weight': 78929738.06}), 

感谢。

回答

1

这不是很多信息的工作。

但我很确定原因很简单:您没有定义任何容量。很明显,没有流量上限,因为我们可以通过图表推动无限量的流量! (因为没有明确的容量被解释为无限容量)

Excerpt from the docs

capacity (string)

Edges of the graph G are expected to have an attribute capacity that indicates how much flow the edge can support. If this attribute is not present, the edge is considered to have infinite capacity. Default value: ‘capacity’.

还有一个备注:你在这里解决最大流问题。没有重量的使用!这些是最大流量最小成本和合作。 (也在networkx中支持)。

+0

哦,这是否意味着我必须为所有节点设置一个属性容量? – Chi

+0

抓住最大流量问题的一些基础知识。是的,你应该发布*一些能力*或者没有上限。但这通常是你的问题自然而然的事情。 – sascha