Home > matgraph > @graph > cartesian.m

cartesian

PURPOSE ^

cartesian(g,h1,h2) --- overwrite g with the product of h1 and h2

SYNOPSIS ^

function cartesian(g,h1,h2)

DESCRIPTION ^

 cartesian(g,h1,h2) --- overwrite g with the product of h1 and h2

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function cartesian(g,h1,h2)
0002 % cartesian(g,h1,h2) --- overwrite g with the product of h1 and h2
0003 
0004 n1 = nv(h1);
0005 n2 = nv(h2);
0006 n = n1 * n2;
0007 
0008 resize(g,n);
0009 clear_edges(g);
0010 
0011 for u=1:n-1
0012     for v=u+1:n
0013         [u1,u2] = splitout(u,n1,n2);
0014         [v1,v2] = splitout(v,n1,n2);
0015         
0016         if (u1==v1) & has(h2,u2,v2)
0017             add(g,u,v);
0018         end
0019         if has(h1,u1,v1) & (u2==v2)
0020             add(g,u,v);
0021         end
0022     end
0023 end
0024 
0025 
0026 if hasxy(h1) & hasxy(h2)
0027     xy1 = getxy(h1);
0028     xy2 = getxy(h2);
0029     
0030     xy = zeros(n,4);
0031     
0032     for u=1:n
0033         [u1,u2] = splitout(u,n1,n2);
0034         xy(u,:) = [xy1(u1,:),xy2(u2,:)];
0035     end
0036     m = randn(4,2);
0037     [q,r] = qr(m);
0038     p = q(:,1:2);
0039     xy = xy*p;
0040     embed(g,xy);
0041     
0042 end
0043 
0044 
0045 if is_labeled(h1) & is_labeled(h2)
0046     for u=1:n
0047         [u1,u2] = splitout(u,n1,n2);
0048         lab1 = get_label(h1,u1);
0049         lab2 = get_label(h2,u2);
0050         label(g,u, ['(', lab1, ',', lab2, ')']);
0051     end
0052 end
0053 
0054 
0055 
0056 
0057 
0058 function [i,j] = splitout(k, n1, n2)
0059 
0060 j = mod(k-1,n2);
0061 i = (k-1-j)/n2;
0062 %i = floor((k-1)/n2);
0063 
0064 i=i+1;
0065 j=j+1;

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