I am trying to analyze a weighted network, and I am focusing on identifying the bottleneck nodes and edges coefficients. I have never done that before on Python and I have the following code:
import networkx as nx
# create a weighted graph
G = nx.Graph()
G.add_weighted_edges_from([(1, 2, 10), (1, 3, 5), (2, 3, 4), (2, 4, 8), (3, 4, 3)])
# compute the edge bottlenecks
edge_bottlenecks = {}
for u, v, data in G.edges(data=True):
# Compute the minimum weight cut using the Karger algorithm
edge_cut_value, edge_partition = nx.minimum_cut(G, u, v, flow_func=nx.algorithms.flow.edmonds_karp)
# Compute the bottleneck value for the edge
edge_bottleneck = edge_cut_value / data['weight']
edge_bottlenecks[(u, v)] = edge_bottleneck
# compute the node bottlenecks
node_bottlenecks = {}
for node in G.nodes():
# Compute the minimum weight cut using the Karger algorithm
node_cut_value, node_partition = nx.minimum_cut(G, node, flow_func=nx.algorithms.flow.edmonds_karp)
# Compute the bottleneck value for the node
node_bottleneck = node_cut_value / sum([G.edges[u, v]['weight'] for u, v in G.edges(node)])
node_bottlenecks[node] = node_bottleneck
print("Edge bottlenecks:", edge_bottlenecks)
print("Node bottlenecks:", node_bottlenecks)
I get an error message saying "NetworkXUnbounded: Infinite capacity path, flow unbounded above." I can't understand why I am getting such an error message. How can I solve the issue? Thank you.