2

I have a directed network with 27000 arcs, each with a weight.

With the code:

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

I get the error:

NetworkXUnbounded: Infinite capacity path, flow unbounded above.

Does anyone know how to get the maximum flow value?

By the way, when I run: G.edges(data=True), I get a dictionary with stuff like this in it:

 ('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}),

Thanks.

tuomastik
  • 4,559
  • 5
  • 36
  • 48
Chi
  • 43
  • 6

2 Answers2

3

That's not much info to work with.

But i'm pretty sure the reason is simple: you did not define any capacities. It's obvious, that there is no upper bound on the flow as we can push an infinite amount of flow through the graph! (because no explicit capacity is interpreted as infinite capacity)

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’.

One more remark: you are solving the maximum-flow problem here. There is no use of weights! Those are for max-flow-min-cost and co. (also supported within networkx).

Community
  • 1
  • 1
sascha
  • 32,238
  • 6
  • 68
  • 110
  • oh, so does this mean that I must set an attribute capacity to all of the nodes? – Chi Jun 28 '17 at 02:29
  • Grab some basics on the max-flow problem. Yes you should post *some capacities* or else there is no upper bound. But this is typically something coming naturally from your problem. – sascha Jun 28 '17 at 02:50
0

nx.maximum_flow() uses capacity attribute of the edges for computing the maximum flow.

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.

Since your edges do not have the capacity attribute, it defaults to infinity. You should either set this attribute for each edge or if it makes sense for your problem, you could use weight as the capacity as follows:

nx.maximum_flow(G,'CHN',"CHL", capacity='weight')
Nirmal
  • 1,285
  • 2
  • 13
  • 23