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/bfs.h>
24 #include <lemon/path.h>
26 #include "graph_test.h"
27 #include "test_tools.h"
29 using namespace lemon;
53 void checkBfsCompile()
55 typedef concepts::Digraph Digraph;
56 typedef Bfs<Digraph> BType;
71 e = bfs_test.predArc(n);
72 n = bfs_test.predNode(n);
73 d = bfs_test.distMap();
74 p = bfs_test.predMap();
75 b = bfs_test.reached(n);
77 Path<Digraph> pp = bfs_test.path(n);
80 void checkBfsFunctionCompile()
83 typedef concepts::Digraph Digraph;
84 typedef Digraph::Arc Arc;
85 typedef Digraph::Node Node;
90 b=bfs(g).run(Node(),Node());
93 .predMap(concepts::ReadWriteMap<Node,Arc>())
94 .distMap(concepts::ReadWriteMap<Node,VType>())
95 .reachedMap(concepts::ReadWriteMap<Node,bool>())
96 .processedMap(concepts::WriteMap<Node,bool>())
99 .predMap(concepts::ReadWriteMap<Node,Arc>())
100 .distMap(concepts::ReadWriteMap<Node,VType>())
101 .reachedMap(concepts::ReadWriteMap<Node,bool>())
102 .processedMap(concepts::WriteMap<Node,bool>())
103 .path(concepts::Path<Digraph>())
107 .predMap(concepts::ReadWriteMap<Node,Arc>())
108 .distMap(concepts::ReadWriteMap<Node,VType>())
109 .reachedMap(concepts::ReadWriteMap<Node,bool>())
110 .processedMap(concepts::WriteMap<Node,bool>())
114 template <class Digraph>
116 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
121 std::istringstream input(test_lgf);
122 digraphReader(input, G).
127 Bfs<Digraph> bfs_test(G);
130 check(bfs_test.dist(t)==2,"Bfs found a wrong path.");
132 Path<Digraph> p = bfs_test.path(t);
133 check(p.length()==2,"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.");
139 for(ArcIt a(G); a!=INVALID; ++a) {
142 check( !bfs_test.reached(u) ||
143 (bfs_test.dist(v) <= bfs_test.dist(u)+1),
144 "Wrong output. " << G.id(u) << "->" << G.id(v));
147 for(NodeIt v(G); v!=INVALID; ++v) {
148 if (bfs_test.reached(v)) {
149 check(v==s || bfs_test.predArc(v)!=INVALID, "Wrong tree.");
150 if (bfs_test.predArc(v)!=INVALID ) {
151 Arc a=bfs_test.predArc(v);
153 check(u==bfs_test.predNode(v),"Wrong tree.");
154 check(bfs_test.dist(v) - bfs_test.dist(u) == 1,
155 "Wrong distance. Difference: "
156 << std::abs(bfs_test.dist(v) - bfs_test.dist(u) - 1));
162 NullMap<Node,Arc> myPredMap;
163 bfs(G).predMap(myPredMap).run(s);
169 checkBfs<ListDigraph>();
170 checkBfs<SmartDigraph>();