1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
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/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;
55 void checkDfsCompile()
57 typedef concepts::Digraph Digraph;
58 typedef Dfs<Digraph> DType;
73 e = dfs_test.predArc(n);
74 n = dfs_test.predNode(n);
75 d = dfs_test.distMap();
76 p = dfs_test.predMap();
77 b = dfs_test.reached(n);
79 Path<Digraph> pp = dfs_test.path(n);
82 void checkDfsFunctionCompile()
85 typedef concepts::Digraph Digraph;
86 typedef Digraph::Arc Arc;
87 typedef Digraph::Node Node;
92 b=dfs(g).run(Node(),Node());
95 .predMap(concepts::ReadWriteMap<Node,Arc>())
96 .distMap(concepts::ReadWriteMap<Node,VType>())
97 .reachedMap(concepts::ReadWriteMap<Node,bool>())
98 .processedMap(concepts::WriteMap<Node,bool>())
101 .predMap(concepts::ReadWriteMap<Node,Arc>())
102 .distMap(concepts::ReadWriteMap<Node,VType>())
103 .reachedMap(concepts::ReadWriteMap<Node,bool>())
104 .processedMap(concepts::WriteMap<Node,bool>())
105 .path(concepts::Path<Digraph>())
109 .predMap(concepts::ReadWriteMap<Node,Arc>())
110 .distMap(concepts::ReadWriteMap<Node,VType>())
111 .reachedMap(concepts::ReadWriteMap<Node,bool>())
112 .processedMap(concepts::WriteMap<Node,bool>())
116 template <class Digraph>
118 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
123 std::istringstream input(test_lgf);
124 digraphReader(input, G).
129 Dfs<Digraph> dfs_test(G);
132 Path<Digraph> p = dfs_test.path(t);
133 check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
134 check(checkPath(G, p),"path() found a wrong path.");
135 check(pathSource(G, p) == s,"path() found a wrong path.");
136 check(pathTarget(G, p) == t,"path() found a wrong path.");
138 for(NodeIt v(G); v!=INVALID; ++v) {
139 if (dfs_test.reached(v)) {
140 check(v==s || dfs_test.predArc(v)!=INVALID, "Wrong tree.");
141 if (dfs_test.predArc(v)!=INVALID ) {
142 Arc e=dfs_test.predArc(v);
144 check(u==dfs_test.predNode(v),"Wrong tree.");
145 check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
146 "Wrong distance. (" << dfs_test.dist(u) << "->"
147 << dfs_test.dist(v) << ")");
153 NullMap<Node,Arc> myPredMap;
154 dfs(G).predMap(myPredMap).run(s);
160 checkDfs<ListDigraph>();
161 checkDfs<SmartDigraph>();