| Description of add |
add
PURPOSE 
add --- add edge(s) to the graph
SYNOPSIS 
function add(g,i,j)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
- full full(g) --- convert internal storage for g to full
- isfull isfull(g) --- check if g's adjacency matrix is full
- nv nv(g) --- number of vertices in g
- resize resize(g,n) --- change the number of vertices in g to n
- size size(g) --- returns [nv,ne] for the graph
- sparse sparse(g) --- convert internal storage for g to sparse
This function is called by:
- bfstree bfstree(t,g,v) --- create a breadth-first spanning tree of g
- bridges bridges(g,algo) --- find all cut edges in g
- cartesian cartesian(g,h1,h2) --- overwrite g with the product of h1 and h2
- cayley cayley(g,perms) -- create a Cayley graph (undirected)
- circulant circulant(g,n,k) --- overwrite g with an n,k circulant graph
- contract contract(g,u,v) --- contract v into u
- cube cube(g,k) --- create a k-cube (default k = 3)
- cycle cycle(g,n) --- create a cycle graph on n vertices
- dfstree dfstree(t,g,v) --- create a depth-first spanning tree of g
- dodecahedron dodecahedron(g) --- overwrite g with the dodecahedron graph
- euler_trail euler_trail(g) --- find an euler trail in g (if one exists)
- graph graph: constructor for the graph class
- grid grid(g,a,b) --- create an a-by-b grid graph
- hamiltonian_cycle hamiltonian_cycle(g) --- find a Hamiltonian cycle in g (if one exists)
- icosahedron icosahedron(g) --- overwrite g with the icosahedron graph
- interval_graph interval_graph(g,ilist) --- create an interval graph
- line_graph line_graph(g,h) --- set g to be the line graph of h
- load load(g,filename) --- read a saved graph on disk
- mobius mobius(g,nverts) --- create a Mobius ladder graph
- octahedron octahedron(g) --- overwrite g with the octahedron graph, K(2,2,2)
- paley paley(g,n) --- create a Paley graph with n vertices
- path path(g,n) --- make g a path on n vertices
- petersen petersen(g) --- overwrite g with the Petersen graph
- prufer prufer --- convert a tree to/from its Prufer code
- random_planar random_planar(g,n) --- create a random planar triangulation
- random_regular random_regular(g,n,k) --- create a random regular graph
- random_tree random_tree(t,n) --- overwrite t with a random tree on n vertices
- selective selective(g,n,n0,d) --- selective attachment random graph
- sgf sgf --- simple graph format: a 2-column matrix representation
- shiftgraph shiftgraph(g,k,t) -- create a shiftgraph g based on t-tuples of k symbols
- sl2graph sl2graph(g,p) -- create an SL(2,p) graph
- wheel wheel(g,n) --- overwrite g with a wheel graph on n vertices
SOURCE CODE 
0001 function add(g,i,j)
0002
0003
0004
0005
0006
0007
0008
0009 global GRAPH_MAGIC
0010 n = nv(g);
0011
0012
0013 if nargin == 3
0014 if (i==j) || (i<1) || (j<1)
0015 return
0016 end
0017
0018 maxij = max(i,j);
0019 if maxij > n
0020 resize(g,maxij)
0021 end
0022
0023 GRAPH_MAGIC.graphs{g.idx}.array(i,j) = 1;
0024 GRAPH_MAGIC.graphs{g.idx}.array(j,i) = 1;
0025 return
0026 end
0027
0028 if nargin == 2
0029 [nr,nc] = size(i);
0030
0031 if (nc ~= 2)
0032 error('in add(elist), elist should have exactly two columns');
0033 end
0034
0035 maxv = max(max(i));
0036 if maxv > n
0037 if maxv > set_large
0038 sparse(g)
0039 end
0040 resize(g,maxv)
0041 end
0042 n = nv(g);
0043 was_full = isfull(g);
0044
0045 data = [i; n,n];
0046 m = size(data,1);
0047 data = [data, ones(m,1)];
0048 A = spconvert(data);
0049 for k=1:n
0050 A(k,k)=0;
0051 end
0052
0053 A = (A+A')>0;
0054 A = logical(A);
0055 if (was_full)
0056 A = full(A);
0057 end
0058 GRAPH_MAGIC.graphs{g.idx}.array = GRAPH_MAGIC.graphs{g.idx}.array | A;
0059 return
0060 end
Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003
|
|