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/euler.h>
20 #include <lemon/list_graph.h>
21 #include <test/test_tools.h>
23 using namespace lemon;
25 template <typename Digraph>
26 void checkDiEulerIt(const Digraph& g)
28 typename Digraph::template ArcMap<int> visitationNumber(g, 0);
30 DiEulerIt<Digraph> e(g);
31 typename Digraph::Node firstNode = g.source(e);
32 typename Digraph::Node lastNode = g.target(e);
34 for (; e != INVALID; ++e)
38 lastNode = g.target(e);
40 ++visitationNumber[e];
43 check(firstNode == lastNode,
44 "checkDiEulerIt: first and last node are not the same");
46 for (typename Digraph::ArcIt a(g); a != INVALID; ++a)
48 check(visitationNumber[a] == 1,
49 "checkDiEulerIt: not visited or multiple times visited arc found");
53 template <typename Graph>
54 void checkEulerIt(const Graph& g)
56 typename Graph::template EdgeMap<int> visitationNumber(g, 0);
59 typename Graph::Node firstNode = g.u(e);
60 typename Graph::Node lastNode = g.v(e);
62 for (; e != INVALID; ++e)
68 ++visitationNumber[e];
71 check(firstNode == lastNode,
72 "checkEulerIt: first and last node are not the same");
74 for (typename Graph::EdgeIt e(g); e != INVALID; ++e)
76 check(visitationNumber[e] == 1,
77 "checkEulerIt: not visited or multiple times visited edge found");
83 typedef ListDigraph Digraph;
84 typedef ListGraph Graph;
86 Digraph digraphWithEulerianCircuit;
88 Digraph& g = digraphWithEulerianCircuit;
90 Digraph::Node n0 = g.addNode();
91 Digraph::Node n1 = g.addNode();
92 Digraph::Node n2 = g.addNode();
100 Digraph digraphWithoutEulerianCircuit;
102 Digraph& g = digraphWithoutEulerianCircuit;
104 Digraph::Node n0 = g.addNode();
105 Digraph::Node n1 = g.addNode();
106 Digraph::Node n2 = g.addNode();
113 Graph graphWithEulerianCircuit;
115 Graph& g = graphWithEulerianCircuit;
117 Graph::Node n0 = g.addNode();
118 Graph::Node n1 = g.addNode();
119 Graph::Node n2 = g.addNode();
126 Graph graphWithoutEulerianCircuit;
128 Graph& g = graphWithoutEulerianCircuit;
130 Graph::Node n0 = g.addNode();
131 Graph::Node n1 = g.addNode();
132 Graph::Node n2 = g.addNode();
138 checkDiEulerIt(digraphWithEulerianCircuit);
140 checkEulerIt(graphWithEulerianCircuit);
142 check(eulerian(digraphWithEulerianCircuit),
143 "this graph should have an Eulerian circuit");
144 check(!eulerian(digraphWithoutEulerianCircuit),
145 "this graph should not have an Eulerian circuit");
147 check(eulerian(graphWithEulerianCircuit),
148 "this graph should have an Eulerian circuit");
149 check(!eulerian(graphWithoutEulerianCircuit),
150 "this graph should have an Eulerian circuit");