Home > matgraph > @graph > shiftgraph.m

shiftgraph

PURPOSE ^

shiftgraph(g,k,t) -- create a shiftgraph g based on t-tuples of k symbols

SYNOPSIS ^

function shiftgraph(g,k,t)

DESCRIPTION ^

 shiftgraph(g,k,t) -- create a shiftgraph g based on t-tuples of k symbols

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function shiftgraph(g,k,t)
0002 % shiftgraph(g,k,t) -- create a shiftgraph g based on t-tuples of k symbols
0003 
0004 resize(g,0);
0005 n = k^t;
0006 if (n>1000) 
0007     sparse(g)
0008 end
0009 resize(g,n);
0010 
0011 edgelist = [];
0012 
0013 
0014 for v=1:n
0015     vec = num2tuple(v-1,k,t);
0016     label(g,v,int2str(vec))
0017     for j=0:k-1
0018         wec = shift(vec,j);
0019         w = tuple2num(wec,k)+1;
0020         if (v~=w)
0021             edgelist = [edgelist; [v,w]];
0022         end
0023     end
0024 end
0025 add(g,edgelist);
0026 
0027 
0028 function tup = num2tuple(n,k,t)
0029 % convert a number into a base-k t-tuple
0030 tup = zeros(1,t);
0031 for i=1:t
0032     tup(i) = mod(n,k);
0033     n = n - tup(i);
0034     n = n/k;
0035 end
0036 
0037 
0038 function n = tuple2num(tup, k)
0039 % convert a base-k tuple into a number
0040 t = length(tup);
0041 pows = k.^(0:t-1);
0042 n = dot(pows,tup);
0043 
0044 
0045 function tt = shift(t,s)
0046 % shift type symbol s into the tuple t and drop the last element
0047 n = length(t);
0048 tt = [s, t(1:n-1)];

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003