0
4
1
| 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
| 2 |
* |
|
| 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
| 4 |
* |
|
| 5 |
* Copyright (C) 2003-2009 |
|
| 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
| 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
| 8 |
* |
|
| 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. |
|
| 12 |
* |
|
| 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 |
|
| 15 |
* purpose. |
|
| 16 |
* |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
#include <lemon/euler.h> |
|
| 20 |
#include <lemon/list_graph.h> |
|
| 21 |
#include <test/test_tools.h> |
|
| 22 |
|
|
| 23 |
using namespace lemon; |
|
| 24 |
|
|
| 25 |
template <typename Digraph> |
|
| 26 |
void checkDiEulerIt(const Digraph& g) |
|
| 27 |
{
|
|
| 28 |
typename Digraph::template ArcMap<int> visitationNumber(g); |
|
| 29 |
|
|
| 30 |
DiEulerIt<Digraph> e(g); |
|
| 31 |
typename Digraph::Node firstNode = g.source(e); |
|
| 32 |
typename Digraph::Node lastNode; |
|
| 33 |
|
|
| 34 |
for (; e != INVALID; ++e) |
|
| 35 |
{
|
|
| 36 |
if (e != INVALID) |
|
| 37 |
{
|
|
| 38 |
lastNode = g.target(e); |
|
| 39 |
} |
|
| 40 |
++visitationNumber[e]; |
|
| 41 |
} |
|
| 42 |
|
|
| 43 |
check(firstNode == lastNode, |
|
| 44 |
"checkDiEulerIt: first and last node are not the same"); |
|
| 45 |
|
|
| 46 |
for (typename Digraph::ArcIt a(g); a != INVALID; ++a) |
|
| 47 |
{
|
|
| 48 |
check(visitationNumber[a] == 1, |
|
| 49 |
"checkDiEulerIt: not visited or multiple times visited arc found"); |
|
| 50 |
} |
|
| 51 |
} |
|
| 52 |
|
|
| 53 |
template <typename Graph> |
|
| 54 |
void checkEulerIt(const Graph& g) |
|
| 55 |
{
|
|
| 56 |
typename Graph::template EdgeMap<int> visitationNumber(g); |
|
| 57 |
|
|
| 58 |
EulerIt<Graph> e(g); |
|
| 59 |
typename Graph::Node firstNode = g.u(e); |
|
| 60 |
typename Graph::Node lastNode; |
|
| 61 |
|
|
| 62 |
for (; e != INVALID; ++e) |
|
| 63 |
{
|
|
| 64 |
if (e != INVALID) |
|
| 65 |
{
|
|
| 66 |
lastNode = g.v(e); |
|
| 67 |
} |
|
| 68 |
++visitationNumber[e]; |
|
| 69 |
} |
|
| 70 |
|
|
| 71 |
check(firstNode == lastNode, |
|
| 72 |
"checkEulerIt: first and last node are not the same"); |
|
| 73 |
|
|
| 74 |
for (typename Graph::EdgeIt e(g); e != INVALID; ++e) |
|
| 75 |
{
|
|
| 76 |
check(visitationNumber[e] == 1, |
|
| 77 |
"checkEulerIt: not visited or multiple times visited edge found"); |
|
| 78 |
} |
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
int main() |
|
| 82 |
{
|
|
| 83 |
typedef ListDigraph Digraph; |
|
| 84 |
typedef ListGraph Graph; |
|
| 85 |
|
|
| 86 |
Digraph digraphWithEulerianCircuit; |
|
| 87 |
{
|
|
| 88 |
Digraph& g = digraphWithEulerianCircuit; |
|
| 89 |
|
|
| 90 |
Digraph::Node n0 = g.addNode(); |
|
| 91 |
Digraph::Node n1 = g.addNode(); |
|
| 92 |
Digraph::Node n2 = g.addNode(); |
|
| 93 |
|
|
| 94 |
g.addArc(n0, n1); |
|
| 95 |
g.addArc(n1, n0); |
|
| 96 |
g.addArc(n1, n2); |
|
| 97 |
g.addArc(n2, n1); |
|
| 98 |
} |
|
| 99 |
|
|
| 100 |
Digraph digraphWithoutEulerianCircuit; |
|
| 101 |
{
|
|
| 102 |
Digraph& g = digraphWithoutEulerianCircuit; |
|
| 103 |
|
|
| 104 |
Digraph::Node n0 = g.addNode(); |
|
| 105 |
Digraph::Node n1 = g.addNode(); |
|
| 106 |
Digraph::Node n2 = g.addNode(); |
|
| 107 |
|
|
| 108 |
g.addArc(n0, n1); |
|
| 109 |
g.addArc(n1, n0); |
|
| 110 |
g.addArc(n1, n2); |
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
Graph graphWithEulerianCircuit; |
|
| 114 |
{
|
|
| 115 |
Graph& g = graphWithEulerianCircuit; |
|
| 116 |
|
|
| 117 |
Graph::Node n0 = g.addNode(); |
|
| 118 |
Graph::Node n1 = g.addNode(); |
|
| 119 |
Graph::Node n2 = g.addNode(); |
|
| 120 |
|
|
| 121 |
g.addEdge(n0, n1); |
|
| 122 |
g.addEdge(n1, n2); |
|
| 123 |
g.addEdge(n2, n0); |
|
| 124 |
} |
|
| 125 |
|
|
| 126 |
Graph graphWithoutEulerianCircuit; |
|
| 127 |
{
|
|
| 128 |
Graph& g = graphWithoutEulerianCircuit; |
|
| 129 |
|
|
| 130 |
Graph::Node n0 = g.addNode(); |
|
| 131 |
Graph::Node n1 = g.addNode(); |
|
| 132 |
Graph::Node n2 = g.addNode(); |
|
| 133 |
|
|
| 134 |
g.addEdge(n0, n1); |
|
| 135 |
g.addEdge(n1, n2); |
|
| 136 |
} |
|
| 137 |
|
|
| 138 |
checkDiEulerIt(digraphWithEulerianCircuit); |
|
| 139 |
|
|
| 140 |
checkEulerIt(graphWithEulerianCircuit); |
|
| 141 |
|
|
| 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"); |
|
| 146 |
|
|
| 147 |
check(eulerian(graphWithEulerianCircuit), |
|
| 148 |
"this graph should have an Eulerian circuit"); |
|
| 149 |
check(!eulerian(graphWithoutEulerianCircuit), |
|
| 150 |
"this graph should have an Eulerian circuit"); |
|
| 151 |
|
|
| 152 |
return 0; |
|
| 153 |
} |
| ... | ... |
@@ -9,96 +9,97 @@ |
| 9 | 9 |
lemon_libemon_la_SOURCES = \ |
| 10 | 10 |
lemon/arg_parser.cc \ |
| 11 | 11 |
lemon/base.cc \ |
| 12 | 12 |
lemon/color.cc \ |
| 13 | 13 |
lemon/lp_base.cc \ |
| 14 | 14 |
lemon/lp_skeleton.cc \ |
| 15 | 15 |
lemon/random.cc \ |
| 16 | 16 |
lemon/bits/windows.cc |
| 17 | 17 |
|
| 18 | 18 |
|
| 19 | 19 |
lemon_libemon_la_CXXFLAGS = \ |
| 20 | 20 |
$(GLPK_CFLAGS) \ |
| 21 | 21 |
$(CPLEX_CFLAGS) \ |
| 22 | 22 |
$(SOPLEX_CXXFLAGS) \ |
| 23 | 23 |
$(CLP_CXXFLAGS) |
| 24 | 24 |
|
| 25 | 25 |
lemon_libemon_la_LDFLAGS = \ |
| 26 | 26 |
$(GLPK_LIBS) \ |
| 27 | 27 |
$(CPLEX_LIBS) \ |
| 28 | 28 |
$(SOPLEX_LIBS) \ |
| 29 | 29 |
$(CLP_LIBS) |
| 30 | 30 |
|
| 31 | 31 |
if HAVE_GLPK |
| 32 | 32 |
lemon_libemon_la_SOURCES += lemon/glpk.cc |
| 33 | 33 |
endif |
| 34 | 34 |
|
| 35 | 35 |
if HAVE_CPLEX |
| 36 | 36 |
lemon_libemon_la_SOURCES += lemon/cplex.cc |
| 37 | 37 |
endif |
| 38 | 38 |
|
| 39 | 39 |
if HAVE_SOPLEX |
| 40 | 40 |
lemon_libemon_la_SOURCES += lemon/soplex.cc |
| 41 | 41 |
endif |
| 42 | 42 |
|
| 43 | 43 |
if HAVE_CLP |
| 44 | 44 |
lemon_libemon_la_SOURCES += lemon/clp.cc |
| 45 | 45 |
endif |
| 46 | 46 |
|
| 47 | 47 |
lemon_HEADERS += \ |
| 48 | 48 |
lemon/adaptors.h \ |
| 49 | 49 |
lemon/arg_parser.h \ |
| 50 | 50 |
lemon/assert.h \ |
| 51 | 51 |
lemon/bfs.h \ |
| 52 | 52 |
lemon/bin_heap.h \ |
| 53 | 53 |
lemon/circulation.h \ |
| 54 | 54 |
lemon/clp.h \ |
| 55 | 55 |
lemon/color.h \ |
| 56 | 56 |
lemon/concept_check.h \ |
| 57 |
lemon/connectivity.h \ |
|
| 57 | 58 |
lemon/counter.h \ |
| 58 | 59 |
lemon/core.h \ |
| 59 | 60 |
lemon/cplex.h \ |
| 60 | 61 |
lemon/dfs.h \ |
| 61 | 62 |
lemon/dijkstra.h \ |
| 62 | 63 |
lemon/dim2.h \ |
| 63 | 64 |
lemon/dimacs.h \ |
| 64 | 65 |
lemon/edge_set.h \ |
| 65 | 66 |
lemon/elevator.h \ |
| 66 | 67 |
lemon/error.h \ |
| 67 | 68 |
lemon/euler.h \ |
| 68 | 69 |
lemon/full_graph.h \ |
| 69 | 70 |
lemon/glpk.h \ |
| 70 | 71 |
lemon/graph_to_eps.h \ |
| 71 | 72 |
lemon/grid_graph.h \ |
| 72 | 73 |
lemon/hypercube_graph.h \ |
| 73 | 74 |
lemon/kruskal.h \ |
| 74 | 75 |
lemon/hao_orlin.h \ |
| 75 | 76 |
lemon/lgf_reader.h \ |
| 76 | 77 |
lemon/lgf_writer.h \ |
| 77 | 78 |
lemon/list_graph.h \ |
| 78 | 79 |
lemon/lp.h \ |
| 79 | 80 |
lemon/lp_base.h \ |
| 80 | 81 |
lemon/lp_skeleton.h \ |
| 81 | 82 |
lemon/list_graph.h \ |
| 82 | 83 |
lemon/maps.h \ |
| 83 | 84 |
lemon/math.h \ |
| 84 | 85 |
lemon/max_matching.h \ |
| 85 | 86 |
lemon/nauty_reader.h \ |
| 86 | 87 |
lemon/path.h \ |
| 87 | 88 |
lemon/preflow.h \ |
| 88 | 89 |
lemon/radix_sort.h \ |
| 89 | 90 |
lemon/random.h \ |
| 90 | 91 |
lemon/smart_graph.h \ |
| 91 | 92 |
lemon/soplex.h \ |
| 92 | 93 |
lemon/suurballe.h \ |
| 93 | 94 |
lemon/time_measure.h \ |
| 94 | 95 |
lemon/tolerance.h \ |
| 95 | 96 |
lemon/unionfind.h \ |
| 96 | 97 |
lemon/bits/windows.h |
| 97 | 98 |
|
| 98 | 99 |
bits_HEADERS += \ |
| 99 | 100 |
lemon/bits/alteration_notifier.h \ |
| 100 | 101 |
lemon/bits/array_map.h \ |
| 101 | 102 |
lemon/bits/base_extender.h \ |
| 102 | 103 |
lemon/bits/bezier.h \ |
| 103 | 104 |
lemon/bits/default_map.h \ |
| 104 | 105 |
lemon/bits/edge_set_extender.h \ |
| ... | ... |
@@ -9,259 +9,256 @@ |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_EULER_H |
| 20 | 20 |
#define LEMON_EULER_H |
| 21 | 21 |
|
| 22 | 22 |
#include<lemon/core.h> |
| 23 | 23 |
#include<lemon/adaptors.h> |
| 24 | 24 |
#include<lemon/connectivity.h> |
| 25 | 25 |
#include <list> |
| 26 | 26 |
|
| 27 | 27 |
/// \ingroup graph_prop |
| 28 | 28 |
/// \file |
| 29 | 29 |
/// \brief Euler tour |
| 30 | 30 |
/// |
| 31 | 31 |
///This file provides an Euler tour iterator and ways to check |
| 32 | 32 |
///if a digraph is euler. |
| 33 | 33 |
|
| 34 | 34 |
|
| 35 | 35 |
namespace lemon {
|
| 36 | 36 |
|
| 37 | 37 |
///Euler iterator for digraphs. |
| 38 | 38 |
|
| 39 | 39 |
/// \ingroup graph_prop |
| 40 | 40 |
///This iterator converts to the \c Arc type of the digraph and using |
| 41 | 41 |
///operator ++, it provides an Euler tour of a \e directed |
| 42 | 42 |
///graph (if there exists). |
| 43 | 43 |
/// |
| 44 | 44 |
///For example |
| 45 | 45 |
///if the given digraph is Euler (i.e it has only one nontrivial component |
| 46 | 46 |
///and the in-degree is equal to the out-degree for all nodes), |
| 47 | 47 |
///the following code will put the arcs of \c g |
| 48 | 48 |
///to the vector \c et according to an |
| 49 | 49 |
///Euler tour of \c g. |
| 50 | 50 |
///\code |
| 51 | 51 |
/// std::vector<ListDigraph::Arc> et; |
| 52 | 52 |
/// for(DiEulerIt<ListDigraph> e(g),e!=INVALID;++e) |
| 53 | 53 |
/// et.push_back(e); |
| 54 | 54 |
///\endcode |
| 55 | 55 |
///If \c g is not Euler then the resulted tour will not be full or closed. |
| 56 | 56 |
///\sa EulerIt |
| 57 |
///\todo Test required |
|
| 58 | 57 |
template<class Digraph> |
| 59 | 58 |
class DiEulerIt |
| 60 | 59 |
{
|
| 61 | 60 |
typedef typename Digraph::Node Node; |
| 62 | 61 |
typedef typename Digraph::NodeIt NodeIt; |
| 63 | 62 |
typedef typename Digraph::Arc Arc; |
| 64 | 63 |
typedef typename Digraph::ArcIt ArcIt; |
| 65 | 64 |
typedef typename Digraph::OutArcIt OutArcIt; |
| 66 | 65 |
typedef typename Digraph::InArcIt InArcIt; |
| 67 | 66 |
|
| 68 | 67 |
const Digraph &g; |
| 69 | 68 |
typename Digraph::template NodeMap<OutArcIt> nedge; |
| 70 | 69 |
std::list<Arc> euler; |
| 71 | 70 |
|
| 72 | 71 |
public: |
| 73 | 72 |
|
| 74 | 73 |
///Constructor |
| 75 | 74 |
|
| 76 | 75 |
///\param _g A digraph. |
| 77 | 76 |
///\param start The starting point of the tour. If it is not given |
| 78 | 77 |
/// the tour will start from the first node. |
| 79 | 78 |
DiEulerIt(const Digraph &_g,typename Digraph::Node start=INVALID) |
| 80 | 79 |
: g(_g), nedge(g) |
| 81 | 80 |
{
|
| 82 | 81 |
if(start==INVALID) start=NodeIt(g); |
| 83 | 82 |
for(NodeIt n(g);n!=INVALID;++n) nedge[n]=OutArcIt(g,n); |
| 84 | 83 |
while(nedge[start]!=INVALID) {
|
| 85 | 84 |
euler.push_back(nedge[start]); |
| 86 | 85 |
Node next=g.target(nedge[start]); |
| 87 | 86 |
++nedge[start]; |
| 88 | 87 |
start=next; |
| 89 | 88 |
} |
| 90 | 89 |
} |
| 91 | 90 |
|
| 92 | 91 |
///Arc Conversion |
| 93 | 92 |
operator Arc() { return euler.empty()?INVALID:euler.front(); }
|
| 94 | 93 |
bool operator==(Invalid) { return euler.empty(); }
|
| 95 | 94 |
bool operator!=(Invalid) { return !euler.empty(); }
|
| 96 | 95 |
|
| 97 | 96 |
///Next arc of the tour |
| 98 | 97 |
DiEulerIt &operator++() {
|
| 99 | 98 |
Node s=g.target(euler.front()); |
| 100 | 99 |
euler.pop_front(); |
| 101 | 100 |
//This produces a warning.Strange. |
| 102 | 101 |
//std::list<Arc>::iterator next=euler.begin(); |
| 103 | 102 |
typename std::list<Arc>::iterator next=euler.begin(); |
| 104 | 103 |
while(nedge[s]!=INVALID) {
|
| 105 | 104 |
euler.insert(next,nedge[s]); |
| 106 | 105 |
Node n=g.target(nedge[s]); |
| 107 | 106 |
++nedge[s]; |
| 108 | 107 |
s=n; |
| 109 | 108 |
} |
| 110 | 109 |
return *this; |
| 111 | 110 |
} |
| 112 | 111 |
///Postfix incrementation |
| 113 | 112 |
|
| 114 | 113 |
///\warning This incrementation |
| 115 | 114 |
///returns an \c Arc, not an \ref DiEulerIt, as one may |
| 116 | 115 |
///expect. |
| 117 | 116 |
Arc operator++(int) |
| 118 | 117 |
{
|
| 119 | 118 |
Arc e=*this; |
| 120 | 119 |
++(*this); |
| 121 | 120 |
return e; |
| 122 | 121 |
} |
| 123 | 122 |
}; |
| 124 | 123 |
|
| 125 | 124 |
///Euler iterator for graphs. |
| 126 | 125 |
|
| 127 | 126 |
/// \ingroup graph_prop |
| 128 | 127 |
///This iterator converts to the \c Arc (or \c Edge) |
| 129 | 128 |
///type of the digraph and using |
| 130 | 129 |
///operator ++, it provides an Euler tour of an undirected |
| 131 | 130 |
///digraph (if there exists). |
| 132 | 131 |
/// |
| 133 | 132 |
///For example |
| 134 | 133 |
///if the given digraph if Euler (i.e it has only one nontrivial component |
| 135 | 134 |
///and the degree of each node is even), |
| 136 | 135 |
///the following code will print the arc IDs according to an |
| 137 | 136 |
///Euler tour of \c g. |
| 138 | 137 |
///\code |
| 139 | 138 |
/// for(EulerIt<ListGraph> e(g),e!=INVALID;++e) {
|
| 140 | 139 |
/// std::cout << g.id(Edge(e)) << std::eol; |
| 141 | 140 |
/// } |
| 142 | 141 |
///\endcode |
| 143 | 142 |
///Although the iterator provides an Euler tour of an graph, |
| 144 | 143 |
///it still returns Arcs in order to indicate the direction of the tour. |
| 145 | 144 |
///(But Arc will convert to Edges, of course). |
| 146 | 145 |
/// |
| 147 | 146 |
///If \c g is not Euler then the resulted tour will not be full or closed. |
| 148 | 147 |
///\sa EulerIt |
| 149 |
///\todo Test required |
|
| 150 | 148 |
template<class Digraph> |
| 151 | 149 |
class EulerIt |
| 152 | 150 |
{
|
| 153 | 151 |
typedef typename Digraph::Node Node; |
| 154 | 152 |
typedef typename Digraph::NodeIt NodeIt; |
| 155 | 153 |
typedef typename Digraph::Arc Arc; |
| 156 | 154 |
typedef typename Digraph::Edge Edge; |
| 157 | 155 |
typedef typename Digraph::ArcIt ArcIt; |
| 158 | 156 |
typedef typename Digraph::OutArcIt OutArcIt; |
| 159 | 157 |
typedef typename Digraph::InArcIt InArcIt; |
| 160 | 158 |
|
| 161 | 159 |
const Digraph &g; |
| 162 | 160 |
typename Digraph::template NodeMap<OutArcIt> nedge; |
| 163 | 161 |
typename Digraph::template EdgeMap<bool> visited; |
| 164 | 162 |
std::list<Arc> euler; |
| 165 | 163 |
|
| 166 | 164 |
public: |
| 167 | 165 |
|
| 168 | 166 |
///Constructor |
| 169 | 167 |
|
| 170 | 168 |
///\param _g An graph. |
| 171 | 169 |
///\param start The starting point of the tour. If it is not given |
| 172 | 170 |
/// the tour will start from the first node. |
| 173 | 171 |
EulerIt(const Digraph &_g,typename Digraph::Node start=INVALID) |
| 174 | 172 |
: g(_g), nedge(g), visited(g,false) |
| 175 | 173 |
{
|
| 176 | 174 |
if(start==INVALID) start=NodeIt(g); |
| 177 | 175 |
for(NodeIt n(g);n!=INVALID;++n) nedge[n]=OutArcIt(g,n); |
| 178 | 176 |
while(nedge[start]!=INVALID) {
|
| 179 | 177 |
euler.push_back(nedge[start]); |
| 180 | 178 |
visited[nedge[start]]=true; |
| 181 | 179 |
Node next=g.target(nedge[start]); |
| 182 | 180 |
++nedge[start]; |
| 183 | 181 |
start=next; |
| 184 | 182 |
while(nedge[start]!=INVALID && visited[nedge[start]]) ++nedge[start]; |
| 185 | 183 |
} |
| 186 | 184 |
} |
| 187 | 185 |
|
| 188 | 186 |
///Arc Conversion |
| 189 | 187 |
operator Arc() const { return euler.empty()?INVALID:euler.front(); }
|
| 190 | 188 |
///Arc Conversion |
| 191 | 189 |
operator Edge() const { return euler.empty()?INVALID:euler.front(); }
|
| 192 | 190 |
///\e |
| 193 | 191 |
bool operator==(Invalid) const { return euler.empty(); }
|
| 194 | 192 |
///\e |
| 195 | 193 |
bool operator!=(Invalid) const { return !euler.empty(); }
|
| 196 | 194 |
|
| 197 | 195 |
///Next arc of the tour |
| 198 | 196 |
EulerIt &operator++() {
|
| 199 | 197 |
Node s=g.target(euler.front()); |
| 200 | 198 |
euler.pop_front(); |
| 201 | 199 |
typename std::list<Arc>::iterator next=euler.begin(); |
| 202 | 200 |
|
| 203 | 201 |
while(nedge[s]!=INVALID) {
|
| 204 | 202 |
while(nedge[s]!=INVALID && visited[nedge[s]]) ++nedge[s]; |
| 205 | 203 |
if(nedge[s]==INVALID) break; |
| 206 | 204 |
else {
|
| 207 | 205 |
euler.insert(next,nedge[s]); |
| 208 | 206 |
visited[nedge[s]]=true; |
| 209 | 207 |
Node n=g.target(nedge[s]); |
| 210 | 208 |
++nedge[s]; |
| 211 | 209 |
s=n; |
| 212 | 210 |
} |
| 213 | 211 |
} |
| 214 | 212 |
return *this; |
| 215 | 213 |
} |
| 216 | 214 |
|
| 217 | 215 |
///Postfix incrementation |
| 218 | 216 |
|
| 219 | 217 |
///\warning This incrementation |
| 220 | 218 |
///returns an \c Arc, not an \ref EulerIt, as one may |
| 221 | 219 |
///expect. |
| 222 | 220 |
Arc operator++(int) |
| 223 | 221 |
{
|
| 224 | 222 |
Arc e=*this; |
| 225 | 223 |
++(*this); |
| 226 | 224 |
return e; |
| 227 | 225 |
} |
| 228 | 226 |
}; |
| 229 | 227 |
|
| 230 | 228 |
|
| 231 | 229 |
///Checks if the graph is Eulerian |
| 232 | 230 |
|
| 233 | 231 |
/// \ingroup graph_prop |
| 234 | 232 |
///Checks if the graph is Eulerian. It works for both directed and undirected |
| 235 | 233 |
///graphs. |
| 236 | 234 |
///\note By definition, a digraph is called \e Eulerian if |
| 237 | 235 |
///and only if it is connected and the number of its incoming and outgoing |
| 238 | 236 |
///arcs are the same for each node. |
| 239 | 237 |
///Similarly, an undirected graph is called \e Eulerian if |
| 240 | 238 |
///and only if it is connected and the number of incident arcs is even |
| 241 | 239 |
///for each node. <em>Therefore, there are digraphs which are not Eulerian, |
| 242 | 240 |
///but still have an Euler tour</em>. |
| 243 |
///\todo Test required |
|
| 244 | 241 |
template<class Digraph> |
| 245 | 242 |
#ifdef DOXYGEN |
| 246 | 243 |
bool |
| 247 | 244 |
#else |
| 248 | 245 |
typename enable_if<UndirectedTagIndicator<Digraph>,bool>::type |
| 249 | 246 |
eulerian(const Digraph &g) |
| 250 | 247 |
{
|
| 251 | 248 |
for(typename Digraph::NodeIt n(g);n!=INVALID;++n) |
| 252 | 249 |
if(countIncEdges(g,n)%2) return false; |
| 253 | 250 |
return connected(g); |
| 254 | 251 |
} |
| 255 | 252 |
template<class Digraph> |
| 256 | 253 |
typename disable_if<UndirectedTagIndicator<Digraph>,bool>::type |
| 257 | 254 |
#endif |
| 258 | 255 |
eulerian(const Digraph &g) |
| 259 | 256 |
{
|
| 260 | 257 |
for(typename Digraph::NodeIt n(g);n!=INVALID;++n) |
| 261 | 258 |
if(countInArcs(g,n)!=countOutArcs(g,n)) return false; |
| 262 | 259 |
return connected(Undirector<const Digraph>(g)); |
| 263 | 260 |
} |
| 264 | 261 |
|
| 265 | 262 |
} |
| 266 | 263 |
|
| 267 | 264 |
#endif |
| 1 | 1 |
INCLUDE_DIRECTORIES( |
| 2 | 2 |
${CMAKE_SOURCE_DIR}
|
| 3 | 3 |
${CMAKE_BINARY_DIR}
|
| 4 | 4 |
) |
| 5 | 5 |
|
| 6 | 6 |
IF(HAVE_GLPK) |
| 7 | 7 |
INCLUDE_DIRECTORIES(${GLPK_INCLUDE_DIR})
|
| 8 | 8 |
ENDIF(HAVE_GLPK) |
| 9 | 9 |
|
| 10 | 10 |
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/lemon)
|
| 11 | 11 |
|
| 12 | 12 |
SET(TESTS |
| 13 | 13 |
adaptors_test |
| 14 | 14 |
bfs_test |
| 15 | 15 |
circulation_test |
| 16 | 16 |
counter_test |
| 17 | 17 |
dfs_test |
| 18 | 18 |
digraph_test |
| 19 | 19 |
dijkstra_test |
| 20 | 20 |
dim_test |
| 21 | 21 |
edge_set_test |
| 22 | 22 |
error_test |
| 23 |
euler_test |
|
| 23 | 24 |
graph_copy_test |
| 24 | 25 |
graph_test |
| 25 | 26 |
graph_utils_test |
| 26 | 27 |
hao_orlin_test |
| 27 | 28 |
heap_test |
| 28 | 29 |
kruskal_test |
| 29 | 30 |
maps_test |
| 30 | 31 |
max_matching_test |
| 31 | 32 |
path_test |
| 32 | 33 |
preflow_test |
| 33 | 34 |
radix_sort_test |
| 34 | 35 |
random_test |
| 35 | 36 |
suurballe_test |
| 36 | 37 |
time_measure_test |
| 37 | 38 |
unionfind_test) |
| 38 | 39 |
|
| 39 | 40 |
IF(HAVE_LP) |
| 40 | 41 |
ADD_EXECUTABLE(lp_test lp_test.cc) |
| 41 | 42 |
IF(HAVE_GLPK) |
| 42 | 43 |
TARGET_LINK_LIBRARIES(lp_test lemon ${GLPK_LIBRARIES})
|
| 43 | 44 |
ENDIF(HAVE_GLPK) |
| 44 | 45 |
ADD_TEST(lp_test lp_test) |
| 45 | 46 |
|
| 46 | 47 |
IF(WIN32 AND HAVE_GLPK) |
| 47 | 48 |
GET_TARGET_PROPERTY(TARGET_LOC lp_test LOCATION) |
| 48 | 49 |
GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH)
|
| 49 | 50 |
ADD_CUSTOM_COMMAND(TARGET lp_test POST_BUILD |
| 50 | 51 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/glpk.dll ${TARGET_PATH}
|
| 51 | 52 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/libltdl3.dll ${TARGET_PATH}
|
| 52 | 53 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH}
|
| 53 | 54 |
) |
| 54 | 55 |
ENDIF(WIN32 AND HAVE_GLPK) |
| 55 | 56 |
ENDIF(HAVE_LP) |
| 56 | 57 |
|
| 57 | 58 |
IF(HAVE_MIP) |
| 58 | 59 |
ADD_EXECUTABLE(mip_test mip_test.cc) |
| 59 | 60 |
IF(HAVE_GLPK) |
| 60 | 61 |
TARGET_LINK_LIBRARIES(mip_test lemon ${GLPK_LIBRARIES})
|
| 61 | 62 |
ENDIF(HAVE_GLPK) |
| 62 | 63 |
ADD_TEST(mip_test mip_test) |
| 63 | 64 |
|
| 64 | 65 |
IF(WIN32 AND HAVE_GLPK) |
| 65 | 66 |
GET_TARGET_PROPERTY(TARGET_LOC mip_test LOCATION) |
| 66 | 67 |
GET_FILENAME_COMPONENT(TARGET_PATH ${TARGET_LOC} PATH)
|
| 67 | 68 |
ADD_CUSTOM_COMMAND(TARGET mip_test POST_BUILD |
| 68 | 69 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/glpk.dll ${TARGET_PATH}
|
| 69 | 70 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/libltdl3.dll ${TARGET_PATH}
|
| 70 | 71 |
COMMAND cmake -E copy ${GLPK_BIN_DIR}/zlib1.dll ${TARGET_PATH}
|
| 1 | 1 |
EXTRA_DIST += \ |
| 2 | 2 |
test/CMakeLists.txt |
| 3 | 3 |
|
| 4 | 4 |
noinst_HEADERS += \ |
| 5 | 5 |
test/graph_test.h \ |
| 6 | 6 |
test/test_tools.h |
| 7 | 7 |
|
| 8 | 8 |
check_PROGRAMS += \ |
| 9 | 9 |
test/adaptors_test \ |
| 10 | 10 |
test/bfs_test \ |
| 11 | 11 |
test/circulation_test \ |
| 12 | 12 |
test/counter_test \ |
| 13 | 13 |
test/dfs_test \ |
| 14 | 14 |
test/digraph_test \ |
| 15 | 15 |
test/dijkstra_test \ |
| 16 | 16 |
test/dim_test \ |
| 17 | 17 |
test/edge_set_test \ |
| 18 | 18 |
test/error_test \ |
| 19 |
test/euler_test \ |
|
| 19 | 20 |
test/graph_copy_test \ |
| 20 | 21 |
test/graph_test \ |
| 21 | 22 |
test/graph_utils_test \ |
| 22 | 23 |
test/hao_orlin_test \ |
| 23 | 24 |
test/heap_test \ |
| 24 | 25 |
test/kruskal_test \ |
| 25 | 26 |
test/maps_test \ |
| 26 | 27 |
test/max_matching_test \ |
| 27 | 28 |
test/path_test \ |
| 28 | 29 |
test/preflow_test \ |
| 29 | 30 |
test/radix_sort_test \ |
| 30 | 31 |
test/random_test \ |
| 31 | 32 |
test/suurballe_test \ |
| 32 | 33 |
test/test_tools_fail \ |
| 33 | 34 |
test/test_tools_pass \ |
| 34 | 35 |
test/time_measure_test \ |
| 35 | 36 |
test/unionfind_test |
| 36 | 37 |
|
| 37 | 38 |
if HAVE_LP |
| 38 | 39 |
check_PROGRAMS += test/lp_test |
| 39 | 40 |
endif HAVE_LP |
| 40 | 41 |
if HAVE_MIP |
| 41 | 42 |
check_PROGRAMS += test/mip_test |
| 42 | 43 |
endif HAVE_MIP |
| 43 | 44 |
|
| 44 | 45 |
TESTS += $(check_PROGRAMS) |
| 45 | 46 |
XFAIL_TESTS += test/test_tools_fail$(EXEEXT) |
| 46 | 47 |
|
| 47 | 48 |
test_adaptors_test_SOURCES = test/adaptors_test.cc |
| 48 | 49 |
test_bfs_test_SOURCES = test/bfs_test.cc |
| 49 | 50 |
test_circulation_test_SOURCES = test/circulation_test.cc |
| 50 | 51 |
test_counter_test_SOURCES = test/counter_test.cc |
| 51 | 52 |
test_dfs_test_SOURCES = test/dfs_test.cc |
| 52 | 53 |
test_digraph_test_SOURCES = test/digraph_test.cc |
| 53 | 54 |
test_dijkstra_test_SOURCES = test/dijkstra_test.cc |
| 54 | 55 |
test_dim_test_SOURCES = test/dim_test.cc |
| 55 | 56 |
test_edge_set_test_SOURCES = test/edge_set_test.cc |
| 56 | 57 |
test_error_test_SOURCES = test/error_test.cc |
| 58 |
test_euler_test_SOURCES = test/euler_test.cc |
|
| 57 | 59 |
test_graph_copy_test_SOURCES = test/graph_copy_test.cc |
| 58 | 60 |
test_graph_test_SOURCES = test/graph_test.cc |
| 59 | 61 |
test_graph_utils_test_SOURCES = test/graph_utils_test.cc |
| 60 | 62 |
test_heap_test_SOURCES = test/heap_test.cc |
| 61 | 63 |
test_kruskal_test_SOURCES = test/kruskal_test.cc |
| 62 | 64 |
test_hao_orlin_test_SOURCES = test/hao_orlin_test.cc |
| 63 | 65 |
test_lp_test_SOURCES = test/lp_test.cc |
| 64 | 66 |
test_maps_test_SOURCES = test/maps_test.cc |
| 65 | 67 |
test_mip_test_SOURCES = test/mip_test.cc |
| 66 | 68 |
test_max_matching_test_SOURCES = test/max_matching_test.cc |
| 67 | 69 |
test_path_test_SOURCES = test/path_test.cc |
| 68 | 70 |
test_preflow_test_SOURCES = test/preflow_test.cc |
| 69 | 71 |
test_radix_sort_test_SOURCES = test/radix_sort_test.cc |
| 70 | 72 |
test_suurballe_test_SOURCES = test/suurballe_test.cc |
| 71 | 73 |
test_random_test_SOURCES = test/random_test.cc |
| 72 | 74 |
test_test_tools_fail_SOURCES = test/test_tools_fail.cc |
| 73 | 75 |
test_test_tools_pass_SOURCES = test/test_tools_pass.cc |
| 74 | 76 |
test_time_measure_test_SOURCES = test/time_measure_test.cc |
| 75 | 77 |
test_unionfind_test_SOURCES = test/unionfind_test.cc |
0 comments (0 inline)