1

It would be great if someone could help me.

I have an undirected graph where every vertex has a weight and where no edges have weights. I want to find a set of nodes with minimum total weight for which their removal makes the graph disconnected. For example, between removing one node with a weight of 10 that make the graph disconnected and removing 2 nodes with a total weight of 6 that make the graph disconnected, the result set should contain those 2 nodes.

Is there any known algorithm for this problem?

Here is what I've done so far. I've made my code using networkx (python). I've already changed my graph to be directed. For instance, for node 1, I consider 1in and 1out node. and I connect 1in to 1out by the weight of node 1. I also add s and t nodes (I'm not sure if it's correct or not). I defined also capacity for each edge in new directed graph.

When run the code, I get this error: NetworkXUnbounded: Infinite capacity path, flow unbounded above.

deg_G = nx.degree(G)
max_weight = max([deg for i,deg in deg_G])+1

st_Weighted_Complement_G = nx.DiGraph()
r = np.arange(len(Complement_G.nodes))

nodes = ['s','t']
edges = []
for i in r:
    nIn = (str(i)+'in')
    nOut = (str(i)+'out')
    nodes.extend([nIn,nOut])
    edges.extend([(nIn,nOut,{'capacity':deg_G[i],'weight':deg_G[i]}),('s',nIn,{'capacity':math.inf,'weight':0}),
                  (nOut,'t',{'capacity':math.inf,'weight':0})])

for edge in Complement_G.edges:
    print(edge[0],edge[1])
    edges.extend([((str(edge[0]))+'out',(str(edge[1]))+'in',{'capacity':max_weight,'weight':0}),
                  ((str(edge[1]))+'out',(str(edge[0]))+'in',{'capacity':max_weight,'weight':0})])

print(edges)
st_Weighted_Complement_G.add_nodes_from(nodes)
st_Weighted_Complement_G.add_weighted_edges_from(edges)

mincostFlow = nx.max_flow_min_cost(st_Weighted_Complement_G, 's', 't',capacity='capacity',weight='weight')
print(mincostFlow)

Thanks

Dominique Fortin
  • 2,212
  • 15
  • 20
SaRa
  • 51
  • 5
  • At first, you talk about an undirected graph (`I have an undirected graph`), but in the code you make directed graph (`st_Weighted_Complement_G = nx.DiGraph()`). Is it an error? – Dominique Fortin Nov 13 '18 at 22:26
  • to use max flow minimum cut I need to change undirected graph to directed and since the nodes are weighted I need to put the weight of each node on the edge between. for instance: node 1 is changing to 1in and 1out and if it has a weight 6 we put this weight as the edge weight between them(1in,1out). – SaRa Nov 14 '18 at 10:02

0 Answers0