-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathbiconnected_components.m
73 lines (59 loc) · 2.15 KB
/
biconnected_components.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function [a,C] = biconnected_components(A,varargin)
% BICONNECTED_COMPONENTS Compute the biconnected components and
% articulation points for a symmetric graph A.
%
% [a C] = biconnected_components(A) returns a list of articulation points
% a and the component graph C where each non-zero indicates the connected
% component of the edge. That is, C is a matrix with the same non-zero
% structure as A, but with the values replaced with the index of the
% biconnected component of that edge. The vector a is a list of
% articulation points in the graph. Articulation points are vertices that
% belong to more than one biconnected component. Removing an articulation
% point disconnects the graph.
%
% If C is not requested, it is not built.
%
% This method works on undirected graphs.
% The runtime is O(V+E), the algorithm is just depth first search.
%
% ... = biconnected_components(A,...) takes a set of
% key-value pairs or an options structure. See set_matlab_bgl_options
% for the standard options.
% There are no additional options for this function.
%
% Note: the input to this function must be symmetric, so this function
% ignores the 'notrans' default option and never transposes the input.
%
% Note: this function does not depend upon the non-zero values of A, but
% only uses the non-zero structure of A.
%
% Example:
% load graphs/tarjan-biconn.mat
% biconnected_components(A)
%
% See also COMPONENTS
% David Gleich
% Copyright, Stanford University, 2006-2008
%% History
% 2006-04-19: Initial version
% 2006-05-31: Added full2sparse check
%%
[trans check full2sparse] = get_matlab_bgl_options(varargin{:});
if full2sparse && ~issparse(A), A = sparse(A); end
if trans, end
if check
% make sure the matrix is symmetric
check_matlab_bgl(A,struct('sym',1));
end;
% the graph has to be symmetric, so trans doesn't matter.
if (nargout > 1)
[a ci] = biconnected_components_mex(A);
% convert the indices from the graph back into a new matrix.
[i j] = find(A);
C = sparse(i,j,ci,size(A,1),size(A,1));
C = max(C,C');
else
a = biconnected_components_mex(A);
end;
% 0 a indicates it isn't an articulation point.
a = a(a > 0);