Backport relevant parts of bugfixes [ad22262328b3], [61fdd06833a6] and [4add05447ca0] to branch 1.2 (#623)
1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2010
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/euler.h>
20 #include <lemon/list_graph.h>
21 #include <lemon/adaptors.h>
22 #include "test_tools.h"
24 using namespace lemon;
26 template <typename Digraph>
27 void checkDiEulerIt(const Digraph& g,
28 const typename Digraph::Node& start = INVALID)
30 typename Digraph::template ArcMap<int> visitationNumber(g, 0);
32 DiEulerIt<Digraph> e(g, start);
33 if (e == INVALID) return;
34 typename Digraph::Node firstNode = g.source(e);
35 typename Digraph::Node lastNode = g.target(e);
36 if (start != INVALID) {
37 check(firstNode == start, "checkDiEulerIt: Wrong first node");
40 for (; e != INVALID; ++e) {
41 if (e != INVALID) lastNode = g.target(e);
42 ++visitationNumber[e];
45 check(firstNode == lastNode,
46 "checkDiEulerIt: First and last nodes are not the same");
48 for (typename Digraph::ArcIt a(g); a != INVALID; ++a)
50 check(visitationNumber[a] == 1,
51 "checkDiEulerIt: Not visited or multiple times visited arc found");
55 template <typename Graph>
56 void checkEulerIt(const Graph& g,
57 const typename Graph::Node& start = INVALID)
59 typename Graph::template EdgeMap<int> visitationNumber(g, 0);
61 EulerIt<Graph> e(g, start);
62 if (e == INVALID) return;
63 typename Graph::Node firstNode = g.source(typename Graph::Arc(e));
64 typename Graph::Node lastNode = g.target(typename Graph::Arc(e));
65 if (start != INVALID) {
66 check(firstNode == start, "checkEulerIt: Wrong first node");
69 for (; e != INVALID; ++e) {
70 if (e != INVALID) lastNode = g.target(typename Graph::Arc(e));
71 ++visitationNumber[e];
74 check(firstNode == lastNode,
75 "checkEulerIt: First and last nodes are not the same");
77 for (typename Graph::EdgeIt e(g); e != INVALID; ++e)
79 check(visitationNumber[e] == 1,
80 "checkEulerIt: Not visited or multiple times visited edge found");
86 typedef ListDigraph Digraph;
87 typedef Undirector<Digraph> Graph;
97 check(eulerian(d), "This graph is Eulerian");
98 check(eulerian(g), "This graph is Eulerian");
103 Digraph::Node n = d.addNode();
104 ::lemon::ignore_unused_variable_warning(n);
110 check(eulerian(d), "This graph is Eulerian");
111 check(eulerian(g), "This graph is Eulerian");
116 Digraph::Node n = d.addNode();
123 check(eulerian(d), "This graph is Eulerian");
124 check(eulerian(g), "This graph is Eulerian");
129 Digraph::Node n1 = d.addNode();
130 Digraph::Node n2 = d.addNode();
131 Digraph::Node n3 = d.addNode();
139 checkDiEulerIt(d, n2);
141 checkDiEulerIt(g, n2);
145 check(eulerian(d), "This graph is Eulerian");
146 check(eulerian(g), "This graph is Eulerian");
151 Digraph::Node n1 = d.addNode();
152 Digraph::Node n2 = d.addNode();
153 Digraph::Node n3 = d.addNode();
154 Digraph::Node n4 = d.addNode();
155 Digraph::Node n5 = d.addNode();
156 Digraph::Node n6 = d.addNode();
171 checkDiEulerIt(d, n1);
172 checkDiEulerIt(d, n5);
175 checkDiEulerIt(g, n1);
176 checkDiEulerIt(g, n5);
181 check(eulerian(d), "This graph is Eulerian");
182 check(eulerian(g), "This graph is Eulerian");
187 Digraph::Node n0 = d.addNode();
188 Digraph::Node n1 = d.addNode();
189 Digraph::Node n2 = d.addNode();
190 Digraph::Node n3 = d.addNode();
191 Digraph::Node n4 = d.addNode();
192 Digraph::Node n5 = d.addNode();
193 ::lemon::ignore_unused_variable_warning(n0,n4,n5);
200 checkDiEulerIt(d, n2);
203 checkDiEulerIt(g, n2);
207 check(!eulerian(d), "This graph is not Eulerian");
208 check(!eulerian(g), "This graph is not Eulerian");
213 Digraph::Node n1 = d.addNode();
214 Digraph::Node n2 = d.addNode();
215 Digraph::Node n3 = d.addNode();
220 check(!eulerian(d), "This graph is not Eulerian");
221 check(!eulerian(g), "This graph is not Eulerian");