3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2008
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/dfs.h>
23 #include <lemon/path.h>
25 #include "graph_test.h"
26 #include "test_tools.h"
28 using namespace lemon;
30 void checkDfsCompile()
32 typedef concepts::Digraph Digraph;
33 typedef Dfs<Digraph> DType;
42 // DType::PredNodeMap pn(G);
49 e = dfs_test.predArc(n);
50 n = dfs_test.predNode(n);
51 d = dfs_test.distMap();
52 p = dfs_test.predMap();
53 // pn = dfs_test.predNodeMap();
54 b = dfs_test.reached(n);
56 Path<Digraph> pp = dfs_test.path(n);
59 void checkDfsFunctionCompile()
62 typedef concepts::Digraph Digraph;
63 typedef Digraph::Arc Arc;
64 typedef Digraph::Node Node;
68 dfs(g).source(Node()).run();
70 .predMap(concepts::WriteMap<Node,Arc>())
71 .distMap(concepts::WriteMap<Node,VType>())
72 .reachedMap(concepts::ReadWriteMap<Node,bool>())
73 .processedMap(concepts::WriteMap<Node,bool>())
77 template <class Digraph>
79 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
83 PetStruct<Digraph> ps = addPetersen(G, 5);
88 Dfs<Digraph> dfs_test(G);
91 Path<Digraph> p = dfs_test.path(t);
92 check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
93 check(checkPath(G, p),"path() found a wrong path.");
94 check(pathSource(G, p) == s,"path() found a wrong path.");
95 check(pathTarget(G, p) == t,"path() found a wrong path.");
97 for(NodeIt v(G); v!=INVALID; ++v) {
98 check(dfs_test.reached(v),"Each node should be reached.");
99 if ( dfs_test.predArc(v)!=INVALID ) {
100 Arc e=dfs_test.predArc(v);
102 check(u==dfs_test.predNode(v),"Wrong tree.");
103 check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
104 "Wrong distance. (" << dfs_test.dist(u) << "->"
105 <<dfs_test.dist(v) << ')');
112 checkDfs<ListDigraph>();
113 checkDfs<SmartDigraph>();