Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of sladjlist
Home > sltoolbox > graph > sladjlist.m

sladjlist

PURPOSE ^

SLADJLIST Construct the adjacency list representation of a graph

SYNOPSIS ^

function Gd = sladjlist(G, uv)

DESCRIPTION ^

SLADJLIST Construct the adjacency list representation of a graph

 $ Syntax $
   - Gd = sladjlist(G)
   - Gd = sladjlist(G, uv)

 $ Arguments $
   - G:        The input graph (or bigraph)
   - Gd:       The output adjacency list representation of the graph
   - uv:       The using-value scheme

 $ Description $
   - Gd = sladjlist(G) constructs the adjacency list representation of the
     graph G with an automatic selection of uv scheme.

   - Gd = sladjlist(G, uv) constructs the adjacency list representation of 
     the graph G with a specified uv scheme.
     There are the following uv schems:
       - 'auto':   automatic selection (default)
                   If G has values then use the values for construction,
                   otherwise not use.
       - 'on':     force to use values, if G has no values then assign
                   1 to all edges
       - 'off':    force not to use values even if G has values.

 $ History $
   - Created by Dahua Lin, on Sep 9, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • sledgeset2adjlist SLEDGESET2ADJLIST Converts edge set to adjacency list
  • slgraphinfo SLGRAPHINFO Extracts basic information of a given graph representation
This function is called by:

SOURCE CODE ^

0001 function Gd = sladjlist(G, uv)
0002 %SLADJLIST Construct the adjacency list representation of a graph
0003 %
0004 % $ Syntax $
0005 %   - Gd = sladjlist(G)
0006 %   - Gd = sladjlist(G, uv)
0007 %
0008 % $ Arguments $
0009 %   - G:        The input graph (or bigraph)
0010 %   - Gd:       The output adjacency list representation of the graph
0011 %   - uv:       The using-value scheme
0012 %
0013 % $ Description $
0014 %   - Gd = sladjlist(G) constructs the adjacency list representation of the
0015 %     graph G with an automatic selection of uv scheme.
0016 %
0017 %   - Gd = sladjlist(G, uv) constructs the adjacency list representation of
0018 %     the graph G with a specified uv scheme.
0019 %     There are the following uv schems:
0020 %       - 'auto':   automatic selection (default)
0021 %                   If G has values then use the values for construction,
0022 %                   otherwise not use.
0023 %       - 'on':     force to use values, if G has no values then assign
0024 %                   1 to all edges
0025 %       - 'off':    force not to use values even if G has values.
0026 %
0027 % $ History $
0028 %   - Created by Dahua Lin, on Sep 9, 2006
0029 %
0030 
0031 %% parse and verify input
0032 
0033 gi = slgraphinfo(G);
0034 
0035 if nargin < 2 || isempty(uv)
0036     uv = 'auto';
0037 end
0038 
0039 
0040 %% decide scheme
0041 % sch:
0042 %   0:  no value -> no value
0043 %   1:  no value -> has value
0044 %   2:  has value -> no value
0045 %   3:  has value -> has value
0046 
0047 switch uv
0048     case 'auto'
0049         if gi.valued
0050             sch = 3;
0051         else
0052             sch = 0;
0053         end
0054     case 'on'
0055         if gi.valued
0056             sch = 3;
0057         else
0058             sch = 1;
0059         end
0060     case 'off'
0061         if gi.valued
0062             sch = 2;
0063         else
0064             sch = 0;
0065         end
0066     otherwise
0067         error('sltoolbox:invalidarg', ...
0068             'Invalid using-value scheme: %s', uv);
0069 end
0070 
0071 %% do construction
0072 
0073 switch gi.type
0074     case 'ge'
0075         Gd = struct('n', gi.n);
0076     case 'bi'
0077         Gd = struct('n', gi.n, 'nt', gi.nt);
0078 end
0079 
0080 switch gi.form
0081     case 'edgeset'
0082         Gd.targets = sledgeset2adjlist(G.n, G.edges, sch);
0083         
0084     case 'adjlist'
0085         switch sch
0086             case {0, 3}
0087                 Gd.targets = G.targets;
0088             case 1
0089                 Gd.targets = cell(size(G.targets));
0090                 nc = numel(G.targets);
0091                 for i = 1 : nc
0092                     ci = G.targets{i};                  
0093                     if ~isempty(ci)
0094                         cn = size(ci, 1);
0095                         ci = [ci, ones(cn,1)];
0096                         Gd.targets{i} = ci;
0097                     end
0098                 end
0099             case 2
0100                 Gd.targets = cell(size(G.targets));
0101                 nc = numel(G.targets);
0102                 for i = 1 : nc
0103                     ci = G.targets{i};                  
0104                     if ~isempty(ci)
0105                         Gd.targets{i} = ci(:, 1);
0106                     end
0107                 end
0108         end
0109         
0110     case 'adjmat'
0111         if gi.valued
0112             [I, J, V] = find(G);
0113             edges = [I, J, V];
0114             clear I J V;
0115         else
0116             [I, J] = find(G);
0117             edges = [I, J];
0118             clear I J;
0119         end
0120         Gd.targets = sledgeset2adjlist(size(G,1), edges, sch);
0121 end
0122 
0123             
0124                 
0125 
0126 
0127 
0128 
0129 
0130 
0131 
0132

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com