Algorithm for edge connectivity of a digraph?
12 次查看(过去 30 天)
显示 更早的评论
Hi,
What is the best way to compute edge connectivity of a digraph? Is there an algorithm or built-in matlab function I can use?
I don't have much experience with graph theory, and am trying to calculate the edge connectivity of a few digraphs with 50 nodes. Thanks!
0 个评论
采纳的回答
Christine Tobler
2023-7-27
编辑:Christine Tobler
2023-7-27
There is no direct method in MATLAB for computing the edge connectivity. Based on the Wikipedia page, you should be able to compute it quite efficiently for small graphs by calling maxflow in a loop:
% Completely connected graph:
g = graph(ones(4));
edgeConnectivity(g)
% Line graph:
g = graph(1:4, 2:5);
edgeConnectivity(g)
% Circle graph:
g = graph(1:4, [2:4 1]);
edgeConnectivity(g)
% Completely connected graph with 50 nodes:
g = graph(ones(50));
tic
edgeConnectivity(g)
toc
function k = edgeConnectivity(g)
% Make sure the graph is unweighted:
if contains("Weight", g.Edges.Properties.VariableNames)
g.Edges.Weight = [];
end
% Compute the maximum flow from node 1 to every other node
mf = zeros(1, numnodes(g)-1);
for ii=2:numnodes(g)
mf(ii-1) = maxflow(g, 1, ii);
end
% The edge connectivity is the minimum of these maximum flows
k = min(mf);
end
"A simple algorithm would, for every pair (u,v), determine the maximum flow from u to v with the capacity of all edges in G set to 1 for both directions. A graph is k-edge-connected if and only if the maximum flow from u to v is at least k for any pair (u,v), so k is the least u-v-flow among all (u,v).
[...]
An improved algorithm will solve the maximum flow problem for every pair (u,v) where u is arbitrarily fixed while v varies over all vertices. This [...] is sound since, if a cut of capacity less than k exists, it is bound to separate u from some other vertex.
"
Note this isn't the most efficient implementation in terms of code complexity, but the timing looks quite good for a graph with 50 nodes.
3 个评论
Alain
2023-11-16
As far as I understand the output of the proposed function is not the edge-connectivity of the graph. As quoted in the comment, to obtain the edge-connectivity one needs to consider all pairs (u,v). In the code, u is fixed to 1.
Christine Tobler
2023-11-16
This is because of the second part of the citation from wikipedia above: "An improved algorithm will solve the maximum flow problem for every pair (u,v) where u is arbitrarily fixed while v varies over all vertices." I have arbitrarily fixed vertex u to 1 in the above code.
更多回答(1 个)
Mrutyunjaya Hiremath
2023-7-27
- To compute the edge connectivity of a directed graph (digraph) in MATLAB, you can use the built-in function "edgeconncomp". This function calculates the edge connectivity of a graph by finding the minimum number of edges that need to be removed to disconnect the graph.
% Create your directed graph (digraph) using the 'digraph' function or other methods.
% For example:
% G = digraph(edges, nodes); % Replace 'edges' and 'nodes' with your actual graph data.
% Compute the edge connectivity using the 'edgeconncomp' function.
connectivity = edgeconncomp(G);
% 'connectivity' will contain the minimum number of edges that need to be removed to disconnect the graph.
disp(['Edge Connectivity: ', num2str(connectivity)]);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!