Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/graph/dfs_test.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 % Do the example in fig 23.4 p479 of Cormen, Leiserson and Rivest (1994) | |
2 | |
3 u = 1; v = 2; w = 3; x = 4; y = 5; z = 6; | |
4 n = 6; | |
5 dag=zeros(n,n); | |
6 dag(u,[v x])=1; | |
7 dag(v,y)=1; | |
8 dag(w,[y z])=1; | |
9 dag(x,v)=1; | |
10 dag(y,x)=1; | |
11 dag(z,z)=1; | |
12 | |
13 [d, pre, post, cycle, f, pred] = dfs(dag, [], 1); | |
14 assert(isequal(d, [1 2 9 4 3 10])) | |
15 assert(isequal(f, [8 7 12 5 6 11]) | |
16 assert(cycle) | |
17 | |
18 % Now give it an undirected cyclic graph | |
19 G = mk_2D_lattice(2,2,0); | |
20 % 1 - 3 | |
21 % | | | |
22 % 2 - 4 | |
23 [d, pre, post, cycle, f, pred] = dfs(G, [], 0); | |
24 % d = [1 2 4 3] | |
25 assert(cycle) | |
26 | |
27 % Now break the cycle | |
28 G(1,2)=0; G(2,1)=0; | |
29 [d, pre, post, cycle, f, pred] = dfs(G, [], 0); | |
30 assert(~cycle) |