I am trying to solve a minimum cost flow problem given in the paper: https://www.researchgate.net/publication/334843578_Balanced_Clustering_A_Uniform_Model_and_Fast_Algorithm. The paper guarantees a feasible solution provided certain conditions are met. I am using Networkx to solve the problem for a dummy graph; however, Networkx can't find a feasible solution to the problem.
Hereunder is the code that I am using to solve the problem:
# directed graph
G = nx.MultiDiGraph()
# no. of nodes in graph
Nxi = 5 #source nodes
Nci = 2 #intermediate nodes
Ns = 1 #sink node
# define edges
e_x_c = [('x_'+str(i),'c_'+str(j), {'weight': 1, 'capacity': 1}) for i in range(Nxi) for j in range(Nci)] # each x_i is only connected to each c_i
e_c_s = [('c_'+str(j),'s', {'weight': (n+1)**2 - n**2, 'capacity': 1}) for n in range(Nxi) for j in range(Nci) ] # nxi no. of edges with increasing weights for each c_i to s.
G.add_edges_from(e_x_c)
G.add_edges_from(e_c_s)
# define nodes
nx.set_node_attributes(G, name='demand', values={**{'x_'+str(i):1 for i in range(Nxi)}, **{'c_'+str(j):0 for j in range(Nci)}, **{'s':-Nxi}})
nx.min_cost_flow(G)
Graph looks like:
Any pointers on where I am doing it wrong?
