Backport relevant parts of bugfixes [ad22262328b3], [61fdd06833a6] and [4add05447ca0] to branch 1.2 (#623)
1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2011
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;
70 ::lemon::ignore_unused_variable_warning(l,i,b);
75 concepts::ReadMap<Arc,bool> am;
79 const DType& const_dfs_test = dfs_test;
86 dfs_test.addSource(s);
87 e = dfs_test.processNextArc();
88 e = const_dfs_test.nextArc();
89 b = const_dfs_test.emptyQueue();
90 i = const_dfs_test.queueSize();
96 l = const_dfs_test.dist(t);
97 e = const_dfs_test.predArc(t);
98 s = const_dfs_test.predNode(t);
99 b = const_dfs_test.reached(t);
100 d = const_dfs_test.distMap();
101 p = const_dfs_test.predMap();
102 pp = const_dfs_test.path(t);
106 ::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
107 ::SetDistMap<concepts::ReadWriteMap<Node,int> >
108 ::SetReachedMap<concepts::ReadWriteMap<Node,bool> >
109 ::SetStandardProcessedMap
110 ::SetProcessedMap<concepts::WriteMap<Node,bool> >
111 ::Create dfs_test(G);
113 concepts::ReadWriteMap<Node,Arc> pred_map;
114 concepts::ReadWriteMap<Node,int> dist_map;
115 concepts::ReadWriteMap<Node,bool> reached_map;
116 concepts::WriteMap<Node,bool> processed_map;
121 .reachedMap(reached_map)
122 .processedMap(processed_map);
129 dfs_test.addSource(s);
130 e = dfs_test.processNextArc();
131 e = dfs_test.nextArc();
132 b = dfs_test.emptyQueue();
133 i = dfs_test.queueSize();
139 l = dfs_test.dist(t);
140 e = dfs_test.predArc(t);
141 s = dfs_test.predNode(t);
142 b = dfs_test.reached(t);
143 pp = dfs_test.path(t);
147 void checkDfsFunctionCompile()
150 typedef concepts::Digraph Digraph;
151 typedef Digraph::Arc Arc;
152 typedef Digraph::Node Node;
156 ::lemon::ignore_unused_variable_warning(b);
159 b=dfs(g).run(Node(),Node());
162 .predMap(concepts::ReadWriteMap<Node,Arc>())
163 .distMap(concepts::ReadWriteMap<Node,VType>())
164 .reachedMap(concepts::ReadWriteMap<Node,bool>())
165 .processedMap(concepts::WriteMap<Node,bool>())
168 .predMap(concepts::ReadWriteMap<Node,Arc>())
169 .distMap(concepts::ReadWriteMap<Node,VType>())
170 .reachedMap(concepts::ReadWriteMap<Node,bool>())
171 .processedMap(concepts::WriteMap<Node,bool>())
172 .path(concepts::Path<Digraph>())
176 .predMap(concepts::ReadWriteMap<Node,Arc>())
177 .distMap(concepts::ReadWriteMap<Node,VType>())
178 .reachedMap(concepts::ReadWriteMap<Node,bool>())
179 .processedMap(concepts::WriteMap<Node,bool>())
183 template <class Digraph>
185 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
191 std::istringstream input(test_lgf);
192 digraphReader(G, input).
199 Dfs<Digraph> dfs_test(G);
202 Path<Digraph> p = dfs_test.path(t);
203 check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
204 check(checkPath(G, p),"path() found a wrong path.");
205 check(pathSource(G, p) == s,"path() found a wrong path.");
206 check(pathTarget(G, p) == t,"path() found a wrong path.");
208 for(NodeIt v(G); v!=INVALID; ++v) {
209 if (dfs_test.reached(v)) {
210 check(v==s || dfs_test.predArc(v)!=INVALID, "Wrong tree.");
211 if (dfs_test.predArc(v)!=INVALID ) {
212 Arc e=dfs_test.predArc(v);
214 check(u==dfs_test.predNode(v),"Wrong tree.");
215 check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
216 "Wrong distance. (" << dfs_test.dist(u) << "->"
217 << dfs_test.dist(v) << ")");
224 check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6.");
228 NullMap<Node,Arc> myPredMap;
229 dfs(G).predMap(myPredMap).run(s);
235 checkDfs<ListDigraph>();
236 checkDfs<SmartDigraph>();