Fix multiple executions in matchings (fract. mathcings) (#356)
1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2009
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;
59 typedef Digraph::Node Node;
60 typedef Digraph::Arc Arc;
70 concepts::ReadMap<Arc,bool> am;
74 const DType& const_dfs_test = dfs_test;
81 dfs_test.addSource(s);
82 e = dfs_test.processNextArc();
83 e = const_dfs_test.nextArc();
84 b = const_dfs_test.emptyQueue();
85 i = const_dfs_test.queueSize();
91 l = const_dfs_test.dist(t);
92 e = const_dfs_test.predArc(t);
93 s = const_dfs_test.predNode(t);
94 b = const_dfs_test.reached(t);
95 d = const_dfs_test.distMap();
96 p = const_dfs_test.predMap();
97 pp = const_dfs_test.path(t);
101 ::SetPredMap<concepts::ReadWriteMap<Node,Arc> >
102 ::SetDistMap<concepts::ReadWriteMap<Node,int> >
103 ::SetReachedMap<concepts::ReadWriteMap<Node,bool> >
104 ::SetStandardProcessedMap
105 ::SetProcessedMap<concepts::WriteMap<Node,bool> >
106 ::Create dfs_test(G);
108 concepts::ReadWriteMap<Node,Arc> pred_map;
109 concepts::ReadWriteMap<Node,int> dist_map;
110 concepts::ReadWriteMap<Node,bool> reached_map;
111 concepts::WriteMap<Node,bool> processed_map;
116 .reachedMap(reached_map)
117 .processedMap(processed_map);
124 dfs_test.addSource(s);
125 e = dfs_test.processNextArc();
126 e = dfs_test.nextArc();
127 b = dfs_test.emptyQueue();
128 i = dfs_test.queueSize();
134 l = dfs_test.dist(t);
135 e = dfs_test.predArc(t);
136 s = dfs_test.predNode(t);
137 b = dfs_test.reached(t);
138 pp = dfs_test.path(t);
142 void checkDfsFunctionCompile()
145 typedef concepts::Digraph Digraph;
146 typedef Digraph::Arc Arc;
147 typedef Digraph::Node Node;
152 b=dfs(g).run(Node(),Node());
155 .predMap(concepts::ReadWriteMap<Node,Arc>())
156 .distMap(concepts::ReadWriteMap<Node,VType>())
157 .reachedMap(concepts::ReadWriteMap<Node,bool>())
158 .processedMap(concepts::WriteMap<Node,bool>())
161 .predMap(concepts::ReadWriteMap<Node,Arc>())
162 .distMap(concepts::ReadWriteMap<Node,VType>())
163 .reachedMap(concepts::ReadWriteMap<Node,bool>())
164 .processedMap(concepts::WriteMap<Node,bool>())
165 .path(concepts::Path<Digraph>())
169 .predMap(concepts::ReadWriteMap<Node,Arc>())
170 .distMap(concepts::ReadWriteMap<Node,VType>())
171 .reachedMap(concepts::ReadWriteMap<Node,bool>())
172 .processedMap(concepts::WriteMap<Node,bool>())
176 template <class Digraph>
178 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
183 std::istringstream input(test_lgf);
184 digraphReader(G, input).
189 Dfs<Digraph> dfs_test(G);
192 Path<Digraph> p = dfs_test.path(t);
193 check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
194 check(checkPath(G, p),"path() found a wrong path.");
195 check(pathSource(G, p) == s,"path() found a wrong path.");
196 check(pathTarget(G, p) == t,"path() found a wrong path.");
198 for(NodeIt v(G); v!=INVALID; ++v) {
199 if (dfs_test.reached(v)) {
200 check(v==s || dfs_test.predArc(v)!=INVALID, "Wrong tree.");
201 if (dfs_test.predArc(v)!=INVALID ) {
202 Arc e=dfs_test.predArc(v);
204 check(u==dfs_test.predNode(v),"Wrong tree.");
205 check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
206 "Wrong distance. (" << dfs_test.dist(u) << "->"
207 << dfs_test.dist(v) << ")");
213 NullMap<Node,Arc> myPredMap;
214 dfs(G).predMap(myPredMap).run(s);
220 checkDfs<ListDigraph>();
221 checkDfs<SmartDigraph>();