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;
82 e = dfs_test.predArc(t);
83 s = dfs_test.predNode(t);
84 b = dfs_test.reached(t);
85 d = dfs_test.distMap();
86 p = dfs_test.predMap();
87 pp = dfs_test.path(t);
91 ::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
92 ::SetDistMap<concepts::ReadWriteMap<Node,int> >
93 ::SetReachedMap<concepts::ReadWriteMap<Node,bool> >
94 ::SetProcessedMap<concepts::WriteMap<Node,bool> >
95 ::SetStandardProcessedMap
102 l = dfs_test.dist(t);
103 e = dfs_test.predArc(t);
104 s = dfs_test.predNode(t);
105 b = dfs_test.reached(t);
106 pp = dfs_test.path(t);
110 void checkDfsFunctionCompile()
113 typedef concepts::Digraph Digraph;
114 typedef Digraph::Arc Arc;
115 typedef Digraph::Node Node;
120 b=dfs(g).run(Node(),Node());
123 .predMap(concepts::ReadWriteMap<Node,Arc>())
124 .distMap(concepts::ReadWriteMap<Node,VType>())
125 .reachedMap(concepts::ReadWriteMap<Node,bool>())
126 .processedMap(concepts::WriteMap<Node,bool>())
129 .predMap(concepts::ReadWriteMap<Node,Arc>())
130 .distMap(concepts::ReadWriteMap<Node,VType>())
131 .reachedMap(concepts::ReadWriteMap<Node,bool>())
132 .processedMap(concepts::WriteMap<Node,bool>())
133 .path(concepts::Path<Digraph>())
137 .predMap(concepts::ReadWriteMap<Node,Arc>())
138 .distMap(concepts::ReadWriteMap<Node,VType>())
139 .reachedMap(concepts::ReadWriteMap<Node,bool>())
140 .processedMap(concepts::WriteMap<Node,bool>())
144 template <class Digraph>
146 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
152 std::istringstream input(test_lgf);
153 digraphReader(G, input).
160 Dfs<Digraph> dfs_test(G);
163 Path<Digraph> p = dfs_test.path(t);
164 check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
165 check(checkPath(G, p),"path() found a wrong path.");
166 check(pathSource(G, p) == s,"path() found a wrong path.");
167 check(pathTarget(G, p) == t,"path() found a wrong path.");
169 for(NodeIt v(G); v!=INVALID; ++v) {
170 if (dfs_test.reached(v)) {
171 check(v==s || dfs_test.predArc(v)!=INVALID, "Wrong tree.");
172 if (dfs_test.predArc(v)!=INVALID ) {
173 Arc e=dfs_test.predArc(v);
175 check(u==dfs_test.predNode(v),"Wrong tree.");
176 check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
177 "Wrong distance. (" << dfs_test.dist(u) << "->"
178 << dfs_test.dist(v) << ")");
185 check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6.");
189 NullMap<Node,Arc> myPredMap;
190 dfs(G).predMap(myPredMap).run(s);
196 checkDfs<ListDigraph>();
197 checkDfs<SmartDigraph>();