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 sledgeset
Home > sltoolbox > graph > sledgeset.m

sledgeset

PURPOSE ^

SLEDGESET Construct the edge set representation of a graph

SYNOPSIS ^

function Gd = sledgeset(G, uv)

DESCRIPTION ^

SLEDGESET Construct the edge set representation of a graph

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

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

 $ Description $
   - Gd = sledgeset(G) constructs the edge set representation of the
     graph G with an automatic selection of uv scheme.

   - Gd = sledgeset(G, uv) constructs the edge set 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:
  • sladjlist2edgeset SLADJLIST2EDGESET Converts the adjacency list to edge set
  • slgraphinfo SLGRAPHINFO Extracts basic information of a given graph representation
This function is called by:

SOURCE CODE ^

0001 function Gd = sledgeset(G, uv)
0002 %SLEDGESET Construct the edge set representation of a graph
0003 %
0004 % $ Syntax $
0005 %   - Gd = sledgeset(G)
0006 %   - Gd = sledgeset(G, uv)
0007 %
0008 % $ Arguments $
0009 %   - G:        The input graph (or bigraph)
0010 %   - Gd:       The output edge set representation of the graph
0011 %   - uv:       The using-value scheme
0012 %
0013 % $ Description $
0014 %   - Gd = sledgeset(G) constructs the edge set representation of the
0015 %     graph G with an automatic selection of uv scheme.
0016 %
0017 %   - Gd = sledgeset(G, uv) constructs the edge set 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 %% decide scheme
0040 % sch:
0041 %   0:  no value -> no value
0042 %   1:  no value -> has value
0043 %   2:  has value -> no value
0044 %   3:  has value -> has value
0045 
0046 switch uv
0047     case 'auto'
0048         if gi.valued
0049             sch = 3;
0050         else
0051             sch = 0;
0052         end
0053     case 'on'
0054         if gi.valued
0055             sch = 3;
0056         else
0057             sch = 1;
0058         end
0059     case 'off'
0060         if gi.valued
0061             sch = 2;
0062         else
0063             sch = 0;
0064         end
0065     otherwise
0066         error('sltoolbox:invalidarg', ...
0067             'Invalid using-value scheme: %s', uv);
0068 end
0069 
0070 %% do construction
0071 
0072 switch gi.type
0073     case 'ge'
0074         Gd = struct('n', gi.n);
0075     case 'bi'
0076         Gd = struct('n', gi.n, 'nt', gi.nt);
0077 end
0078 
0079 switch gi.form
0080     case 'edgeset'
0081         switch sch
0082             case {0, 3}
0083                 Gd.edges = G.edges;
0084                 
0085             case 1
0086                 if ~isempty(G.edges)
0087                     vals = ones(size(G.edges, 1), 1);
0088                     Gd.edges = [G.edges, vals];
0089                 else
0090                     Gd.edges = [];
0091                 end
0092             case 2
0093                 if ~isempty(G.edges)
0094                     Gd.edges = G.edges(:, 1:2);
0095                 else
0096                     Gd.edges = [];
0097                 end
0098         end
0099         
0100     case 'adjlist'
0101         Gd.edges = sladjlist2edgeset(G.targets, sch);
0102         
0103     case 'adjmat'
0104         switch sch
0105             case {0, 2}
0106                 [I, J] = find(G);
0107                 Gd.edges = [I, J];
0108             case 1
0109                 [I, J] = find(G);
0110                 ne = length(I);
0111                 Gd.edges = [I, J, ones(ne, 1)];
0112             case 3
0113                 [I, J, V] = find(G);
0114                 Gd.edges = [I, J, V];
0115         end
0116 end
0117                 
0118

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

Contact us at files@mathworks.com