1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2010
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #include <lemon/concepts/digraph.h>
20 #include <lemon/smart_graph.h>
21 #include <lemon/list_graph.h>
22 #include <lemon/lgf_reader.h>
23 #include <lemon/dfs.h>
24 #include <lemon/path.h>
26 #include "graph_test.h"
27 #include "test_tools.h"
29 using namespace lemon;
58 void checkDfsCompile()
60 typedef concepts::Digraph Digraph;
61 typedef Dfs<Digraph> DType;
62 typedef Digraph::Node Node;
63 typedef Digraph::Arc Arc;
73 concepts::ReadMap<Arc,bool> am;
77 const DType& const_dfs_test = dfs_test;
84 dfs_test.addSource(s);
85 e = dfs_test.processNextArc();
86 e = const_dfs_test.nextArc();
87 b = const_dfs_test.emptyQueue();
88 i = const_dfs_test.queueSize();
94 l = const_dfs_test.dist(t);
95 e = const_dfs_test.predArc(t);
96 s = const_dfs_test.predNode(t);
97 b = const_dfs_test.reached(t);
98 d = const_dfs_test.distMap();
99 p = const_dfs_test.predMap();
100 pp = const_dfs_test.path(t);
104 ::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
105 ::SetDistMap<concepts::ReadWriteMap<Node,int> >
106 ::SetReachedMap<concepts::ReadWriteMap<Node,bool> >
107 ::SetStandardProcessedMap
108 ::SetProcessedMap<concepts::WriteMap<Node,bool> >
109 ::Create dfs_test(G);
111 concepts::ReadWriteMap<Node,Arc> pred_map;
112 concepts::ReadWriteMap<Node,int> dist_map;
113 concepts::ReadWriteMap<Node,bool> reached_map;
114 concepts::WriteMap<Node,bool> processed_map;
119 .reachedMap(reached_map)
120 .processedMap(processed_map);
127 dfs_test.addSource(s);
128 e = dfs_test.processNextArc();
129 e = dfs_test.nextArc();
130 b = dfs_test.emptyQueue();
131 i = dfs_test.queueSize();
137 l = dfs_test.dist(t);
138 e = dfs_test.predArc(t);
139 s = dfs_test.predNode(t);
140 b = dfs_test.reached(t);
141 pp = dfs_test.path(t);
145 void checkDfsFunctionCompile()
148 typedef concepts::Digraph Digraph;
149 typedef Digraph::Arc Arc;
150 typedef Digraph::Node Node;
155 b=dfs(g).run(Node(),Node());
158 .predMap(concepts::ReadWriteMap<Node,Arc>())
159 .distMap(concepts::ReadWriteMap<Node,VType>())
160 .reachedMap(concepts::ReadWriteMap<Node,bool>())
161 .processedMap(concepts::WriteMap<Node,bool>())
164 .predMap(concepts::ReadWriteMap<Node,Arc>())
165 .distMap(concepts::ReadWriteMap<Node,VType>())
166 .reachedMap(concepts::ReadWriteMap<Node,bool>())
167 .processedMap(concepts::WriteMap<Node,bool>())
168 .path(concepts::Path<Digraph>())
172 .predMap(concepts::ReadWriteMap<Node,Arc>())
173 .distMap(concepts::ReadWriteMap<Node,VType>())
174 .reachedMap(concepts::ReadWriteMap<Node,bool>())
175 .processedMap(concepts::WriteMap<Node,bool>())
179 template <class Digraph>
181 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
187 std::istringstream input(test_lgf);
188 digraphReader(G, input).
195 Dfs<Digraph> dfs_test(G);
198 Path<Digraph> p = dfs_test.path(t);
199 check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
200 check(checkPath(G, p),"path() found a wrong path.");
201 check(pathSource(G, p) == s,"path() found a wrong path.");
202 check(pathTarget(G, p) == t,"path() found a wrong path.");
204 for(NodeIt v(G); v!=INVALID; ++v) {
205 if (dfs_test.reached(v)) {
206 check(v==s || dfs_test.predArc(v)!=INVALID, "Wrong tree.");
207 if (dfs_test.predArc(v)!=INVALID ) {
208 Arc e=dfs_test.predArc(v);
210 check(u==dfs_test.predNode(v),"Wrong tree.");
211 check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
212 "Wrong distance. (" << dfs_test.dist(u) << "->"
213 << dfs_test.dist(v) << ")");
220 check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6.");
224 NullMap<Node,Arc> myPredMap;
225 dfs(G).predMap(myPredMap).run(s);
231 checkDfs<ListDigraph>();
232 checkDfs<SmartDigraph>();