Finding the minimum cost set of nodes so that once removed, the graph is disconnected












0














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










share|improve this question
























  • 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 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 at 10:02
















0














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










share|improve this question
























  • 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 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 at 10:02














0












0








0







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










share|improve this question















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







python networkx graph-theory ford-fulkerson minimum-cut






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 17:31









Dominique Fortin

1,640816




1,640816










asked Nov 11 at 16:54









SaRa

11




11












  • 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 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 at 10:02


















  • 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 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 at 10:02
















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 at 22:26






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 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 at 10:02




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 at 10:02

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251024%2ffinding-the-minimum-cost-set-of-nodes-so-that-once-removed-the-graph-is-disconn%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251024%2ffinding-the-minimum-cost-set-of-nodes-so-that-once-removed-the-graph-is-disconn%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini