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