| Description of bridges |
bridges
PURPOSE 
bridges(g,algo) --- find all cut edges in g
SYNOPSIS 
function blist = bridges(g,algo)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
- add add --- add edge(s) to the graph
- copy copy(g,h) --- overwrite g with a copy of h
- delete delete --- delete vertices or edges from a graph
- edges edges(g) --- list the edges in g as a 2-column matrix
- find_path find_path(g,u,v) --- find a shortest path from u to v
- free free(g) --- free the graph from the system
- full full(g) --- convert internal storage for g to full
- graph graph: constructor for the graph class
- has has --- check if the graph has a particular vertex or edge
- incidence_matrix incidence_matrix(g) --- return the vertex/edge incidence matrix.
- ne ne(g) --- number of edges in g or ne(g,h) --- check for inequality
This function is called by:
SUBFUNCTIONS 
SOURCE CODE 
0001 function blist = bridges(g,algo)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 DEFAULT_ALGORITHM = 'matrix';
0017
0018 if nargin < 2
0019 algo = DEFAULT_ALGORITHM;
0020 end
0021
0022 switch lower(algo)
0023 case {'path', 'paths'}
0024 blist = path_bridges(g);
0025 case 'matrix'
0026 blist = matrix_bridges(g);
0027 otherwise
0028 error(['Unknown algorithm: ', algo]);
0029 end
0030
0031 function blist = matrix_bridges(g)
0032
0033
0034
0035
0036 M = full(incidence_matrix(g,'signed'));
0037 N = null(M);
0038
0039
0040 N = abs(N) < 100*eps;
0041 idx = all(N,2);
0042
0043 blist = edges(g);
0044 blist = blist(idx,:);
0045
0046
0047 function blist = path_bridges(g)
0048
0049
0050 bgraph = graph;
0051 notbridges = graph;
0052 gsave = graph;
0053 copy(gsave,g);
0054
0055 elist = edges(g);
0056 m = ne(g);
0057
0058 for k=1:m
0059
0060 x = elist(k,1);
0061 y = elist(k,2);
0062
0063
0064 if (has(notbridges,x,y))
0065 continue
0066 end
0067
0068
0069 delete(g,x,y);
0070 P = find_path(g,x,y);
0071
0072
0073
0074 if isempty(P)
0075 add(bgraph,x,y)
0076 else
0077
0078 add(g,x,y);
0079 add(notbridges,x,y)
0080 for j=1:length(P)-1
0081 add(notbridges,P(j),P(j+1))
0082 end
0083 end
0084 end
0085
0086 blist = edges(bgraph);
0087
0088
0089 copy(g, gsave)
0090
0091 free(bgraph)
0092 free(notbridges)
0093 free(gsave)
Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003
|
|