1 | /* -*- C++ -*- |
---|
2 | * test/dfs_test.cc - Part of LEMON, a generic C++ optimization library |
---|
3 | * |
---|
4 | * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
5 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
6 | * |
---|
7 | * Permission to use, modify and distribute this software is granted |
---|
8 | * provided that this copyright notice appears in all copies. For |
---|
9 | * precise terms see the accompanying LICENSE file. |
---|
10 | * |
---|
11 | * This software is provided "AS IS" with no warranty of any kind, |
---|
12 | * express or implied, and with no claim as to its suitability for any |
---|
13 | * purpose. |
---|
14 | * |
---|
15 | */ |
---|
16 | |
---|
17 | #include "test_tools.h" |
---|
18 | #include <lemon/smart_graph.h> |
---|
19 | #include <lemon/dfs.h> |
---|
20 | #include <lemon/path.h> |
---|
21 | #include <lemon/concept/graph.h> |
---|
22 | |
---|
23 | using namespace lemon; |
---|
24 | |
---|
25 | const int PET_SIZE =5; |
---|
26 | |
---|
27 | |
---|
28 | void check_Dfs_SmartGraph_Compile() |
---|
29 | { |
---|
30 | typedef concept::StaticGraph Graph; |
---|
31 | |
---|
32 | typedef Graph::Edge Edge; |
---|
33 | typedef Graph::Node Node; |
---|
34 | typedef Graph::EdgeIt EdgeIt; |
---|
35 | typedef Graph::NodeIt NodeIt; |
---|
36 | |
---|
37 | typedef Dfs<Graph> DType; |
---|
38 | |
---|
39 | Graph G; |
---|
40 | Node n; |
---|
41 | Edge e; |
---|
42 | int l; |
---|
43 | bool b; |
---|
44 | DType::DistMap d(G); |
---|
45 | DType::PredMap p(G); |
---|
46 | // DType::PredNodeMap pn(G); |
---|
47 | |
---|
48 | DType dfs_test(G); |
---|
49 | |
---|
50 | dfs_test.run(n); |
---|
51 | |
---|
52 | l = dfs_test.dist(n); |
---|
53 | e = dfs_test.pred(n); |
---|
54 | n = dfs_test.predNode(n); |
---|
55 | d = dfs_test.distMap(); |
---|
56 | p = dfs_test.predMap(); |
---|
57 | // pn = dfs_test.predNodeMap(); |
---|
58 | b = dfs_test.reached(n); |
---|
59 | |
---|
60 | DirPath<Graph> pp(G); |
---|
61 | dfs_test.getPath(pp,n); |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | void check_Dfs_Function_Compile() |
---|
66 | { |
---|
67 | typedef int VType; |
---|
68 | typedef concept::StaticGraph Graph; |
---|
69 | |
---|
70 | typedef Graph::Edge Edge; |
---|
71 | typedef Graph::Node Node; |
---|
72 | typedef Graph::EdgeIt EdgeIt; |
---|
73 | typedef Graph::NodeIt NodeIt; |
---|
74 | typedef concept::ReadMap<Edge,VType> LengthMap; |
---|
75 | |
---|
76 | dfs(Graph(),Node()).run(); |
---|
77 | dfs(Graph()).source(Node()).run(); |
---|
78 | dfs(Graph()) |
---|
79 | .predMap(concept::WriteMap<Node,Edge>()) |
---|
80 | .distMap(concept::WriteMap<Node,VType>()) |
---|
81 | .reachedMap(concept::ReadWriteMap<Node,bool>()) |
---|
82 | .processedMap(concept::WriteMap<Node,bool>()) |
---|
83 | .run(Node()); |
---|
84 | |
---|
85 | } |
---|
86 | |
---|
87 | int main() |
---|
88 | { |
---|
89 | |
---|
90 | typedef SmartGraph Graph; |
---|
91 | |
---|
92 | typedef Graph::Edge Edge; |
---|
93 | typedef Graph::Node Node; |
---|
94 | typedef Graph::EdgeIt EdgeIt; |
---|
95 | typedef Graph::NodeIt NodeIt; |
---|
96 | typedef Graph::EdgeMap<int> LengthMap; |
---|
97 | |
---|
98 | Graph G; |
---|
99 | Node s, t; |
---|
100 | PetStruct<Graph> ps = addPetersen(G,PET_SIZE); |
---|
101 | |
---|
102 | s=ps.outer[2]; |
---|
103 | t=ps.inner[0]; |
---|
104 | |
---|
105 | Dfs<Graph> dfs_test(G); |
---|
106 | dfs_test.run(s); |
---|
107 | |
---|
108 | DirPath<Graph> p(G); |
---|
109 | check(dfs_test.getPath(p,t),"getPath() failed to set the path."); |
---|
110 | check(p.length()==dfs_test.dist(t),"getPath() found a wrong path."); |
---|
111 | |
---|
112 | for(NodeIt v(G); v!=INVALID; ++v) { |
---|
113 | check(dfs_test.reached(v),"Each node should be reached."); |
---|
114 | if ( dfs_test.pred(v)!=INVALID ) { |
---|
115 | Edge e=dfs_test.pred(v); |
---|
116 | Node u=G.source(e); |
---|
117 | check(u==dfs_test.predNode(v),"Wrong tree."); |
---|
118 | check(dfs_test.dist(v) - dfs_test.dist(u) == 1, |
---|
119 | "Wrong distance. (" << dfs_test.dist(u) << "->" |
---|
120 | <<dfs_test.dist(v) << ')'); |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|