lemongraph 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +8 -0
- data/LICENSE +674 -0
- data/README.md +6 -0
- data/ext/lemon-1.3.1/AUTHORS +26 -0
- data/ext/lemon-1.3.1/CMakeLists.txt +371 -0
- data/ext/lemon-1.3.1/INSTALL +167 -0
- data/ext/lemon-1.3.1/LICENSE +32 -0
- data/ext/lemon-1.3.1/NEWS +337 -0
- data/ext/lemon-1.3.1/README +50 -0
- data/ext/lemon-1.3.1/cmake/FindCOIN.cmake +110 -0
- data/ext/lemon-1.3.1/cmake/FindGLPK.cmake +55 -0
- data/ext/lemon-1.3.1/cmake/FindGhostscript.cmake +10 -0
- data/ext/lemon-1.3.1/cmake/FindILOG.cmake +102 -0
- data/ext/lemon-1.3.1/cmake/FindSOPLEX.cmake +23 -0
- data/ext/lemon-1.3.1/cmake/LEMONConfig.cmake.in +13 -0
- data/ext/lemon-1.3.1/cmake/nsis/lemon.ico +0 -0
- data/ext/lemon-1.3.1/cmake/nsis/uninstall.ico +0 -0
- data/ext/lemon-1.3.1/cmake/version.cmake +1 -0
- data/ext/lemon-1.3.1/cmake/version.cmake.in +1 -0
- data/ext/lemon-1.3.1/contrib/CMakeLists.txt +19 -0
- data/ext/lemon-1.3.1/lemon/CMakeLists.txt +91 -0
- data/ext/lemon-1.3.1/lemon/adaptors.h +3638 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.cc +474 -0
- data/ext/lemon-1.3.1/lemon/arg_parser.h +440 -0
- data/ext/lemon-1.3.1/lemon/assert.h +214 -0
- data/ext/lemon-1.3.1/lemon/base.cc +37 -0
- data/ext/lemon-1.3.1/lemon/bellman_ford.h +1116 -0
- data/ext/lemon-1.3.1/lemon/bfs.h +1754 -0
- data/ext/lemon-1.3.1/lemon/bin_heap.h +347 -0
- data/ext/lemon-1.3.1/lemon/binomial_heap.h +445 -0
- data/ext/lemon-1.3.1/lemon/bits/alteration_notifier.h +472 -0
- data/ext/lemon-1.3.1/lemon/bits/array_map.h +351 -0
- data/ext/lemon-1.3.1/lemon/bits/bezier.h +174 -0
- data/ext/lemon-1.3.1/lemon/bits/default_map.h +182 -0
- data/ext/lemon-1.3.1/lemon/bits/edge_set_extender.h +627 -0
- data/ext/lemon-1.3.1/lemon/bits/enable_if.h +131 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_adaptor_extender.h +401 -0
- data/ext/lemon-1.3.1/lemon/bits/graph_extender.h +1332 -0
- data/ext/lemon-1.3.1/lemon/bits/lock.h +65 -0
- data/ext/lemon-1.3.1/lemon/bits/map_extender.h +332 -0
- data/ext/lemon-1.3.1/lemon/bits/path_dump.h +177 -0
- data/ext/lemon-1.3.1/lemon/bits/solver_bits.h +194 -0
- data/ext/lemon-1.3.1/lemon/bits/traits.h +388 -0
- data/ext/lemon-1.3.1/lemon/bits/variant.h +494 -0
- data/ext/lemon-1.3.1/lemon/bits/vector_map.h +244 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.cc +166 -0
- data/ext/lemon-1.3.1/lemon/bits/windows.h +44 -0
- data/ext/lemon-1.3.1/lemon/bucket_heap.h +594 -0
- data/ext/lemon-1.3.1/lemon/capacity_scaling.h +1014 -0
- data/ext/lemon-1.3.1/lemon/cbc.cc +460 -0
- data/ext/lemon-1.3.1/lemon/cbc.h +129 -0
- data/ext/lemon-1.3.1/lemon/christofides_tsp.h +254 -0
- data/ext/lemon-1.3.1/lemon/circulation.h +807 -0
- data/ext/lemon-1.3.1/lemon/clp.cc +464 -0
- data/ext/lemon-1.3.1/lemon/clp.h +164 -0
- data/ext/lemon-1.3.1/lemon/color.cc +44 -0
- data/ext/lemon-1.3.1/lemon/color.h +204 -0
- data/ext/lemon-1.3.1/lemon/concept_check.h +77 -0
- data/ext/lemon-1.3.1/lemon/concepts/bpgraph.h +1029 -0
- data/ext/lemon-1.3.1/lemon/concepts/digraph.h +491 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph.h +788 -0
- data/ext/lemon-1.3.1/lemon/concepts/graph_components.h +2134 -0
- data/ext/lemon-1.3.1/lemon/concepts/heap.h +324 -0
- data/ext/lemon-1.3.1/lemon/concepts/maps.h +223 -0
- data/ext/lemon-1.3.1/lemon/concepts/path.h +312 -0
- data/ext/lemon-1.3.1/lemon/config.h.in +22 -0
- data/ext/lemon-1.3.1/lemon/connectivity.h +1688 -0
- data/ext/lemon-1.3.1/lemon/core.h +2506 -0
- data/ext/lemon-1.3.1/lemon/cost_scaling.h +1607 -0
- data/ext/lemon-1.3.1/lemon/counter.h +249 -0
- data/ext/lemon-1.3.1/lemon/cplex.cc +994 -0
- data/ext/lemon-1.3.1/lemon/cplex.h +292 -0
- data/ext/lemon-1.3.1/lemon/cycle_canceling.h +1230 -0
- data/ext/lemon-1.3.1/lemon/dfs.h +1637 -0
- data/ext/lemon-1.3.1/lemon/dheap.h +352 -0
- data/ext/lemon-1.3.1/lemon/dijkstra.h +1303 -0
- data/ext/lemon-1.3.1/lemon/dim2.h +726 -0
- data/ext/lemon-1.3.1/lemon/dimacs.h +448 -0
- data/ext/lemon-1.3.1/lemon/edge_set.h +1420 -0
- data/ext/lemon-1.3.1/lemon/edmonds_karp.h +556 -0
- data/ext/lemon-1.3.1/lemon/elevator.h +982 -0
- data/ext/lemon-1.3.1/lemon/error.h +276 -0
- data/ext/lemon-1.3.1/lemon/euler.h +287 -0
- data/ext/lemon-1.3.1/lemon/fib_heap.h +475 -0
- data/ext/lemon-1.3.1/lemon/fractional_matching.h +2139 -0
- data/ext/lemon-1.3.1/lemon/full_graph.h +1082 -0
- data/ext/lemon-1.3.1/lemon/glpk.cc +1012 -0
- data/ext/lemon-1.3.1/lemon/glpk.h +263 -0
- data/ext/lemon-1.3.1/lemon/gomory_hu.h +568 -0
- data/ext/lemon-1.3.1/lemon/graph_to_eps.h +1186 -0
- data/ext/lemon-1.3.1/lemon/greedy_tsp.h +251 -0
- data/ext/lemon-1.3.1/lemon/grid_graph.h +699 -0
- data/ext/lemon-1.3.1/lemon/grosso_locatelli_pullan_mc.h +840 -0
- data/ext/lemon-1.3.1/lemon/hao_orlin.h +1015 -0
- data/ext/lemon-1.3.1/lemon/hartmann_orlin_mmc.h +654 -0
- data/ext/lemon-1.3.1/lemon/howard_mmc.h +651 -0
- data/ext/lemon-1.3.1/lemon/hypercube_graph.h +459 -0
- data/ext/lemon-1.3.1/lemon/insertion_tsp.h +533 -0
- data/ext/lemon-1.3.1/lemon/karp_mmc.h +590 -0
- data/ext/lemon-1.3.1/lemon/kruskal.h +324 -0
- data/ext/lemon-1.3.1/lemon/lemon.pc.in +10 -0
- data/ext/lemon-1.3.1/lemon/lgf_reader.h +3854 -0
- data/ext/lemon-1.3.1/lemon/lgf_writer.h +2687 -0
- data/ext/lemon-1.3.1/lemon/list_graph.h +2510 -0
- data/ext/lemon-1.3.1/lemon/lp.h +95 -0
- data/ext/lemon-1.3.1/lemon/lp_base.cc +30 -0
- data/ext/lemon-1.3.1/lemon/lp_base.h +2147 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.cc +143 -0
- data/ext/lemon-1.3.1/lemon/lp_skeleton.h +234 -0
- data/ext/lemon-1.3.1/lemon/maps.h +4057 -0
- data/ext/lemon-1.3.1/lemon/matching.h +3505 -0
- data/ext/lemon-1.3.1/lemon/math.h +77 -0
- data/ext/lemon-1.3.1/lemon/max_cardinality_search.h +794 -0
- data/ext/lemon-1.3.1/lemon/min_cost_arborescence.h +808 -0
- data/ext/lemon-1.3.1/lemon/nagamochi_ibaraki.h +702 -0
- data/ext/lemon-1.3.1/lemon/nauty_reader.h +113 -0
- data/ext/lemon-1.3.1/lemon/nearest_neighbor_tsp.h +238 -0
- data/ext/lemon-1.3.1/lemon/network_simplex.h +1659 -0
- data/ext/lemon-1.3.1/lemon/opt2_tsp.h +367 -0
- data/ext/lemon-1.3.1/lemon/pairing_heap.h +474 -0
- data/ext/lemon-1.3.1/lemon/path.h +1164 -0
- data/ext/lemon-1.3.1/lemon/planarity.h +2754 -0
- data/ext/lemon-1.3.1/lemon/preflow.h +985 -0
- data/ext/lemon-1.3.1/lemon/quad_heap.h +343 -0
- data/ext/lemon-1.3.1/lemon/radix_heap.h +438 -0
- data/ext/lemon-1.3.1/lemon/radix_sort.h +487 -0
- data/ext/lemon-1.3.1/lemon/random.cc +29 -0
- data/ext/lemon-1.3.1/lemon/random.h +1005 -0
- data/ext/lemon-1.3.1/lemon/smart_graph.h +1344 -0
- data/ext/lemon-1.3.1/lemon/soplex.cc +465 -0
- data/ext/lemon-1.3.1/lemon/soplex.h +158 -0
- data/ext/lemon-1.3.1/lemon/static_graph.h +476 -0
- data/ext/lemon-1.3.1/lemon/suurballe.h +776 -0
- data/ext/lemon-1.3.1/lemon/time_measure.h +610 -0
- data/ext/lemon-1.3.1/lemon/tolerance.h +242 -0
- data/ext/lemon-1.3.1/lemon/unionfind.h +1824 -0
- data/ext/lemon-1.3.1/scripts/unify-sources.sh +390 -0
- data/ext/lemon-1.3.1/scripts/valgrind-wrapper.sh +22 -0
- data/ext/lemongraph/arc_map.cc +1007 -0
- data/ext/lemongraph/digraph.cc +282 -0
- data/ext/lemongraph/digraph_arc.cc +153 -0
- data/ext/lemongraph/digraph_node.cc +277 -0
- data/ext/lemongraph/edge_map.cc +770 -0
- data/ext/lemongraph/extconf.rb +53 -0
- data/ext/lemongraph/graph.cc +351 -0
- data/ext/lemongraph/graph_arc.cc +95 -0
- data/ext/lemongraph/graph_edge.cc +153 -0
- data/ext/lemongraph/graph_item.cc +76 -0
- data/ext/lemongraph/graph_node.cc +321 -0
- data/ext/lemongraph/lemongraph.cc +260 -0
- data/ext/lemongraph/lemongraph.hh +295 -0
- data/ext/lemongraph/lemongraph.map +6 -0
- data/ext/lemongraph/lemongraph_export.hh +31 -0
- data/ext/lemongraph/node_map.cc +1011 -0
- data/lemongraph.gemspec +176 -0
- data/lib/lemongraph/graphviz.rb +240 -0
- data/lib/lemongraph/version.rb +4 -0
- data/lib/lemongraph.rb +21 -0
- data/samples/lemondeps.rb +38 -0
- metadata +202 -0
|
@@ -0,0 +1,276 @@
|
|
|
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
|
+
#ifndef LEMON_ERROR_H
|
|
20
|
+
#define LEMON_ERROR_H
|
|
21
|
+
|
|
22
|
+
/// \ingroup exceptions
|
|
23
|
+
/// \file
|
|
24
|
+
/// \brief Basic exception classes and error handling.
|
|
25
|
+
|
|
26
|
+
#include <exception>
|
|
27
|
+
#include <string>
|
|
28
|
+
#include <sstream>
|
|
29
|
+
#include <iostream>
|
|
30
|
+
#include <cstdlib>
|
|
31
|
+
#include <memory>
|
|
32
|
+
|
|
33
|
+
namespace lemon {
|
|
34
|
+
|
|
35
|
+
/// \addtogroup exceptions
|
|
36
|
+
/// @{
|
|
37
|
+
|
|
38
|
+
/// \brief Generic exception class.
|
|
39
|
+
///
|
|
40
|
+
/// Base class for exceptions used in LEMON.
|
|
41
|
+
///
|
|
42
|
+
class Exception : public std::exception {
|
|
43
|
+
public:
|
|
44
|
+
///Constructor
|
|
45
|
+
Exception() throw() {}
|
|
46
|
+
///Virtual destructor
|
|
47
|
+
virtual ~Exception() throw() {}
|
|
48
|
+
///A short description of the exception
|
|
49
|
+
virtual const char* what() const throw() {
|
|
50
|
+
return "lemon::Exception";
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/// \brief Input-Output error
|
|
55
|
+
///
|
|
56
|
+
/// This exception is thrown when a file operation cannot be
|
|
57
|
+
/// succeeded.
|
|
58
|
+
class IoError : public Exception {
|
|
59
|
+
protected:
|
|
60
|
+
std::string _message;
|
|
61
|
+
std::string _file;
|
|
62
|
+
|
|
63
|
+
mutable std::string _what;
|
|
64
|
+
public:
|
|
65
|
+
|
|
66
|
+
/// Copy constructor
|
|
67
|
+
IoError(const IoError &error) throw() : Exception() {
|
|
68
|
+
message(error._message);
|
|
69
|
+
file(error._file);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// Constructor
|
|
73
|
+
explicit IoError(const char *message) throw() {
|
|
74
|
+
IoError::message(message);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// Constructor
|
|
78
|
+
explicit IoError(const std::string &message) throw() {
|
|
79
|
+
IoError::message(message);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// Constructor
|
|
83
|
+
explicit IoError(const char *message,
|
|
84
|
+
const std::string &file) throw() {
|
|
85
|
+
IoError::message(message);
|
|
86
|
+
IoError::file(file);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/// Constructor
|
|
90
|
+
explicit IoError(const std::string &message,
|
|
91
|
+
const std::string &file) throw() {
|
|
92
|
+
IoError::message(message);
|
|
93
|
+
IoError::file(file);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/// Virtual destructor
|
|
97
|
+
virtual ~IoError() throw() {}
|
|
98
|
+
|
|
99
|
+
/// Set the error message
|
|
100
|
+
void message(const char *message) throw() {
|
|
101
|
+
try {
|
|
102
|
+
_message = message;
|
|
103
|
+
} catch (...) {}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// Set the error message
|
|
107
|
+
void message(const std::string& message) throw() {
|
|
108
|
+
try {
|
|
109
|
+
_message = message;
|
|
110
|
+
} catch (...) {}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// Set the file name
|
|
114
|
+
void file(const std::string &file) throw() {
|
|
115
|
+
try {
|
|
116
|
+
_file = file;
|
|
117
|
+
} catch (...) {}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/// Returns the error message
|
|
121
|
+
const std::string& message() const throw() {
|
|
122
|
+
return _message;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/// \brief Returns the filename
|
|
126
|
+
///
|
|
127
|
+
/// Returns the filename or an empty string if it was not specified.
|
|
128
|
+
const std::string& file() const throw() {
|
|
129
|
+
return _file;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/// \brief Returns a short error message
|
|
133
|
+
///
|
|
134
|
+
/// Returns a short error message which contains the message and the
|
|
135
|
+
/// file name.
|
|
136
|
+
virtual const char* what() const throw() {
|
|
137
|
+
try {
|
|
138
|
+
_what.clear();
|
|
139
|
+
std::ostringstream oss;
|
|
140
|
+
oss << "lemon:IoError" << ": ";
|
|
141
|
+
oss << _message;
|
|
142
|
+
if (!_file.empty()) {
|
|
143
|
+
oss << " ('" << _file << "')";
|
|
144
|
+
}
|
|
145
|
+
_what = oss.str();
|
|
146
|
+
}
|
|
147
|
+
catch (...) {}
|
|
148
|
+
if (!_what.empty()) return _what.c_str();
|
|
149
|
+
else return "lemon:IoError";
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/// \brief Format error
|
|
155
|
+
///
|
|
156
|
+
/// This exception is thrown when an input file has wrong
|
|
157
|
+
/// format or a data representation is not legal.
|
|
158
|
+
class FormatError : public Exception {
|
|
159
|
+
protected:
|
|
160
|
+
std::string _message;
|
|
161
|
+
std::string _file;
|
|
162
|
+
int _line;
|
|
163
|
+
|
|
164
|
+
mutable std::string _what;
|
|
165
|
+
public:
|
|
166
|
+
|
|
167
|
+
/// Copy constructor
|
|
168
|
+
FormatError(const FormatError &error) throw() : Exception() {
|
|
169
|
+
message(error._message);
|
|
170
|
+
file(error._file);
|
|
171
|
+
line(error._line);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/// Constructor
|
|
175
|
+
explicit FormatError(const char *message) throw() {
|
|
176
|
+
FormatError::message(message);
|
|
177
|
+
_line = 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/// Constructor
|
|
181
|
+
explicit FormatError(const std::string &message) throw() {
|
|
182
|
+
FormatError::message(message);
|
|
183
|
+
_line = 0;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/// Constructor
|
|
187
|
+
explicit FormatError(const char *message,
|
|
188
|
+
const std::string &file, int line = 0) throw() {
|
|
189
|
+
FormatError::message(message);
|
|
190
|
+
FormatError::file(file);
|
|
191
|
+
FormatError::line(line);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/// Constructor
|
|
195
|
+
explicit FormatError(const std::string &message,
|
|
196
|
+
const std::string &file, int line = 0) throw() {
|
|
197
|
+
FormatError::message(message);
|
|
198
|
+
FormatError::file(file);
|
|
199
|
+
FormatError::line(line);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/// Virtual destructor
|
|
203
|
+
virtual ~FormatError() throw() {}
|
|
204
|
+
|
|
205
|
+
/// Set the line number
|
|
206
|
+
void line(int line) throw() { _line = line; }
|
|
207
|
+
|
|
208
|
+
/// Set the error message
|
|
209
|
+
void message(const char *message) throw() {
|
|
210
|
+
try {
|
|
211
|
+
_message = message;
|
|
212
|
+
} catch (...) {}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/// Set the error message
|
|
216
|
+
void message(const std::string& message) throw() {
|
|
217
|
+
try {
|
|
218
|
+
_message = message;
|
|
219
|
+
} catch (...) {}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// Set the file name
|
|
223
|
+
void file(const std::string &file) throw() {
|
|
224
|
+
try {
|
|
225
|
+
_file = file;
|
|
226
|
+
} catch (...) {}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/// \brief Returns the line number
|
|
230
|
+
///
|
|
231
|
+
/// Returns the line number or zero if it was not specified.
|
|
232
|
+
int line() const throw() { return _line; }
|
|
233
|
+
|
|
234
|
+
/// Returns the error message
|
|
235
|
+
const std::string& message() const throw() {
|
|
236
|
+
return _message;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/// \brief Returns the filename
|
|
240
|
+
///
|
|
241
|
+
/// Returns the filename or an empty string if it was not specified.
|
|
242
|
+
const std::string& file() const throw() {
|
|
243
|
+
return _file;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/// \brief Returns a short error message
|
|
247
|
+
///
|
|
248
|
+
/// Returns a short error message which contains the message, the
|
|
249
|
+
/// file name and the line number.
|
|
250
|
+
virtual const char* what() const throw() {
|
|
251
|
+
try {
|
|
252
|
+
_what.clear();
|
|
253
|
+
std::ostringstream oss;
|
|
254
|
+
oss << "lemon:FormatError" << ": ";
|
|
255
|
+
oss << _message;
|
|
256
|
+
if (!_file.empty() || _line != 0) {
|
|
257
|
+
oss << " (";
|
|
258
|
+
if (!_file.empty()) oss << "in file '" << _file << "'";
|
|
259
|
+
if (!_file.empty() && _line != 0) oss << " ";
|
|
260
|
+
if (_line != 0) oss << "at line " << _line;
|
|
261
|
+
oss << ")";
|
|
262
|
+
}
|
|
263
|
+
_what = oss.str();
|
|
264
|
+
}
|
|
265
|
+
catch (...) {}
|
|
266
|
+
if (!_what.empty()) return _what.c_str();
|
|
267
|
+
else return "lemon:FormatError";
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/// @}
|
|
273
|
+
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
#endif // LEMON_ERROR_H
|
|
@@ -0,0 +1,287 @@
|
|
|
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-2013
|
|
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
|
+
#ifndef LEMON_EULER_H
|
|
20
|
+
#define LEMON_EULER_H
|
|
21
|
+
|
|
22
|
+
#include<lemon/core.h>
|
|
23
|
+
#include<lemon/adaptors.h>
|
|
24
|
+
#include<lemon/connectivity.h>
|
|
25
|
+
#include <list>
|
|
26
|
+
|
|
27
|
+
/// \ingroup graph_properties
|
|
28
|
+
/// \file
|
|
29
|
+
/// \brief Euler tour iterators and a function for checking the \e Eulerian
|
|
30
|
+
/// property.
|
|
31
|
+
///
|
|
32
|
+
///This file provides Euler tour iterators and a function to check
|
|
33
|
+
///if a (di)graph is \e Eulerian.
|
|
34
|
+
|
|
35
|
+
namespace lemon {
|
|
36
|
+
|
|
37
|
+
///Euler tour iterator for digraphs.
|
|
38
|
+
|
|
39
|
+
/// \ingroup graph_properties
|
|
40
|
+
///This iterator provides an Euler tour (Eulerian circuit) of a \e directed
|
|
41
|
+
///graph (if there exists) and it converts to the \c Arc type of the digraph.
|
|
42
|
+
///
|
|
43
|
+
///For example, if the given digraph has an Euler tour (i.e it has only one
|
|
44
|
+
///non-trivial component and the in-degree is equal to the out-degree
|
|
45
|
+
///for all nodes), then the following code will put the arcs of \c g
|
|
46
|
+
///to the vector \c et according to an Euler tour of \c g.
|
|
47
|
+
///\code
|
|
48
|
+
/// std::vector<ListDigraph::Arc> et;
|
|
49
|
+
/// for(DiEulerIt<ListDigraph> e(g); e!=INVALID; ++e)
|
|
50
|
+
/// et.push_back(e);
|
|
51
|
+
///\endcode
|
|
52
|
+
///If \c g has no Euler tour, then the resulted walk will not be closed
|
|
53
|
+
///or not contain all arcs.
|
|
54
|
+
///\sa EulerIt
|
|
55
|
+
template<typename GR>
|
|
56
|
+
class DiEulerIt
|
|
57
|
+
{
|
|
58
|
+
typedef typename GR::Node Node;
|
|
59
|
+
typedef typename GR::NodeIt NodeIt;
|
|
60
|
+
typedef typename GR::Arc Arc;
|
|
61
|
+
typedef typename GR::ArcIt ArcIt;
|
|
62
|
+
typedef typename GR::OutArcIt OutArcIt;
|
|
63
|
+
typedef typename GR::InArcIt InArcIt;
|
|
64
|
+
|
|
65
|
+
const GR &g;
|
|
66
|
+
typename GR::template NodeMap<OutArcIt> narc;
|
|
67
|
+
std::list<Arc> euler;
|
|
68
|
+
|
|
69
|
+
public:
|
|
70
|
+
|
|
71
|
+
///Constructor
|
|
72
|
+
|
|
73
|
+
///Constructor.
|
|
74
|
+
///\param gr A digraph.
|
|
75
|
+
///\param start The starting point of the tour. If it is not given,
|
|
76
|
+
///the tour will start from the first node that has an outgoing arc.
|
|
77
|
+
DiEulerIt(const GR &gr, typename GR::Node start = INVALID)
|
|
78
|
+
: g(gr), narc(g)
|
|
79
|
+
{
|
|
80
|
+
if (start==INVALID) {
|
|
81
|
+
NodeIt n(g);
|
|
82
|
+
while (n!=INVALID && OutArcIt(g,n)==INVALID) ++n;
|
|
83
|
+
start=n;
|
|
84
|
+
}
|
|
85
|
+
if (start!=INVALID) {
|
|
86
|
+
for (NodeIt n(g); n!=INVALID; ++n) narc[n]=OutArcIt(g,n);
|
|
87
|
+
while (narc[start]!=INVALID) {
|
|
88
|
+
euler.push_back(narc[start]);
|
|
89
|
+
Node next=g.target(narc[start]);
|
|
90
|
+
++narc[start];
|
|
91
|
+
start=next;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
///Arc conversion
|
|
97
|
+
operator Arc() { return euler.empty()?INVALID:euler.front(); }
|
|
98
|
+
///Compare with \c INVALID
|
|
99
|
+
bool operator==(Invalid) { return euler.empty(); }
|
|
100
|
+
///Compare with \c INVALID
|
|
101
|
+
bool operator!=(Invalid) { return !euler.empty(); }
|
|
102
|
+
|
|
103
|
+
///Next arc of the tour
|
|
104
|
+
|
|
105
|
+
///Next arc of the tour
|
|
106
|
+
///
|
|
107
|
+
DiEulerIt &operator++() {
|
|
108
|
+
Node s=g.target(euler.front());
|
|
109
|
+
euler.pop_front();
|
|
110
|
+
typename std::list<Arc>::iterator next=euler.begin();
|
|
111
|
+
while(narc[s]!=INVALID) {
|
|
112
|
+
euler.insert(next,narc[s]);
|
|
113
|
+
Node n=g.target(narc[s]);
|
|
114
|
+
++narc[s];
|
|
115
|
+
s=n;
|
|
116
|
+
}
|
|
117
|
+
return *this;
|
|
118
|
+
}
|
|
119
|
+
///Postfix incrementation
|
|
120
|
+
|
|
121
|
+
/// Postfix incrementation.
|
|
122
|
+
///
|
|
123
|
+
///\warning This incrementation
|
|
124
|
+
///returns an \c Arc, not a \ref DiEulerIt, as one may
|
|
125
|
+
///expect.
|
|
126
|
+
Arc operator++(int)
|
|
127
|
+
{
|
|
128
|
+
Arc e=*this;
|
|
129
|
+
++(*this);
|
|
130
|
+
return e;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
///Euler tour iterator for graphs.
|
|
135
|
+
|
|
136
|
+
/// \ingroup graph_properties
|
|
137
|
+
///This iterator provides an Euler tour (Eulerian circuit) of an
|
|
138
|
+
///\e undirected graph (if there exists) and it converts to the \c Arc
|
|
139
|
+
///and \c Edge types of the graph.
|
|
140
|
+
///
|
|
141
|
+
///For example, if the given graph has an Euler tour (i.e it has only one
|
|
142
|
+
///non-trivial component and the degree of each node is even),
|
|
143
|
+
///the following code will print the arc IDs according to an
|
|
144
|
+
///Euler tour of \c g.
|
|
145
|
+
///\code
|
|
146
|
+
/// for(EulerIt<ListGraph> e(g); e!=INVALID; ++e) {
|
|
147
|
+
/// std::cout << g.id(Edge(e)) << std::eol;
|
|
148
|
+
/// }
|
|
149
|
+
///\endcode
|
|
150
|
+
///Although this iterator is for undirected graphs, it still returns
|
|
151
|
+
///arcs in order to indicate the direction of the tour.
|
|
152
|
+
///(But arcs convert to edges, of course.)
|
|
153
|
+
///
|
|
154
|
+
///If \c g has no Euler tour, then the resulted walk will not be closed
|
|
155
|
+
///or not contain all edges.
|
|
156
|
+
template<typename GR>
|
|
157
|
+
class EulerIt
|
|
158
|
+
{
|
|
159
|
+
typedef typename GR::Node Node;
|
|
160
|
+
typedef typename GR::NodeIt NodeIt;
|
|
161
|
+
typedef typename GR::Arc Arc;
|
|
162
|
+
typedef typename GR::Edge Edge;
|
|
163
|
+
typedef typename GR::ArcIt ArcIt;
|
|
164
|
+
typedef typename GR::OutArcIt OutArcIt;
|
|
165
|
+
typedef typename GR::InArcIt InArcIt;
|
|
166
|
+
|
|
167
|
+
const GR &g;
|
|
168
|
+
typename GR::template NodeMap<OutArcIt> narc;
|
|
169
|
+
typename GR::template EdgeMap<bool> visited;
|
|
170
|
+
std::list<Arc> euler;
|
|
171
|
+
|
|
172
|
+
public:
|
|
173
|
+
|
|
174
|
+
///Constructor
|
|
175
|
+
|
|
176
|
+
///Constructor.
|
|
177
|
+
///\param gr A graph.
|
|
178
|
+
///\param start The starting point of the tour. If it is not given,
|
|
179
|
+
///the tour will start from the first node that has an incident edge.
|
|
180
|
+
EulerIt(const GR &gr, typename GR::Node start = INVALID)
|
|
181
|
+
: g(gr), narc(g), visited(g, false)
|
|
182
|
+
{
|
|
183
|
+
if (start==INVALID) {
|
|
184
|
+
NodeIt n(g);
|
|
185
|
+
while (n!=INVALID && OutArcIt(g,n)==INVALID) ++n;
|
|
186
|
+
start=n;
|
|
187
|
+
}
|
|
188
|
+
if (start!=INVALID) {
|
|
189
|
+
for (NodeIt n(g); n!=INVALID; ++n) narc[n]=OutArcIt(g,n);
|
|
190
|
+
while(narc[start]!=INVALID) {
|
|
191
|
+
euler.push_back(narc[start]);
|
|
192
|
+
visited[narc[start]]=true;
|
|
193
|
+
Node next=g.target(narc[start]);
|
|
194
|
+
++narc[start];
|
|
195
|
+
start=next;
|
|
196
|
+
while(narc[start]!=INVALID && visited[narc[start]]) ++narc[start];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
///Arc conversion
|
|
202
|
+
operator Arc() const { return euler.empty()?INVALID:euler.front(); }
|
|
203
|
+
///Edge conversion
|
|
204
|
+
operator Edge() const { return euler.empty()?INVALID:euler.front(); }
|
|
205
|
+
///Compare with \c INVALID
|
|
206
|
+
bool operator==(Invalid) const { return euler.empty(); }
|
|
207
|
+
///Compare with \c INVALID
|
|
208
|
+
bool operator!=(Invalid) const { return !euler.empty(); }
|
|
209
|
+
|
|
210
|
+
///Next arc of the tour
|
|
211
|
+
|
|
212
|
+
///Next arc of the tour
|
|
213
|
+
///
|
|
214
|
+
EulerIt &operator++() {
|
|
215
|
+
Node s=g.target(euler.front());
|
|
216
|
+
euler.pop_front();
|
|
217
|
+
typename std::list<Arc>::iterator next=euler.begin();
|
|
218
|
+
while(narc[s]!=INVALID) {
|
|
219
|
+
while(narc[s]!=INVALID && visited[narc[s]]) ++narc[s];
|
|
220
|
+
if(narc[s]==INVALID) break;
|
|
221
|
+
else {
|
|
222
|
+
euler.insert(next,narc[s]);
|
|
223
|
+
visited[narc[s]]=true;
|
|
224
|
+
Node n=g.target(narc[s]);
|
|
225
|
+
++narc[s];
|
|
226
|
+
s=n;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return *this;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
///Postfix incrementation
|
|
233
|
+
|
|
234
|
+
/// Postfix incrementation.
|
|
235
|
+
///
|
|
236
|
+
///\warning This incrementation returns an \c Arc (which converts to
|
|
237
|
+
///an \c Edge), not an \ref EulerIt, as one may expect.
|
|
238
|
+
Arc operator++(int)
|
|
239
|
+
{
|
|
240
|
+
Arc e=*this;
|
|
241
|
+
++(*this);
|
|
242
|
+
return e;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
///Check if the given graph is Eulerian
|
|
248
|
+
|
|
249
|
+
/// \ingroup graph_properties
|
|
250
|
+
///This function checks if the given graph is Eulerian.
|
|
251
|
+
///It works for both directed and undirected graphs.
|
|
252
|
+
///
|
|
253
|
+
///By definition, a digraph is called \e Eulerian if
|
|
254
|
+
///and only if it is connected and the number of incoming and outgoing
|
|
255
|
+
///arcs are the same for each node.
|
|
256
|
+
///Similarly, an undirected graph is called \e Eulerian if
|
|
257
|
+
///and only if it is connected and the number of incident edges is even
|
|
258
|
+
///for each node.
|
|
259
|
+
///
|
|
260
|
+
///\note There are (di)graphs that are not Eulerian, but still have an
|
|
261
|
+
/// Euler tour, since they may contain isolated nodes.
|
|
262
|
+
///
|
|
263
|
+
///\sa DiEulerIt, EulerIt
|
|
264
|
+
template<typename GR>
|
|
265
|
+
#ifdef DOXYGEN
|
|
266
|
+
bool
|
|
267
|
+
#else
|
|
268
|
+
typename enable_if<UndirectedTagIndicator<GR>,bool>::type
|
|
269
|
+
eulerian(const GR &g)
|
|
270
|
+
{
|
|
271
|
+
for(typename GR::NodeIt n(g);n!=INVALID;++n)
|
|
272
|
+
if(countIncEdges(g,n)%2) return false;
|
|
273
|
+
return connected(g);
|
|
274
|
+
}
|
|
275
|
+
template<class GR>
|
|
276
|
+
typename disable_if<UndirectedTagIndicator<GR>,bool>::type
|
|
277
|
+
#endif
|
|
278
|
+
eulerian(const GR &g)
|
|
279
|
+
{
|
|
280
|
+
for(typename GR::NodeIt n(g);n!=INVALID;++n)
|
|
281
|
+
if(countInArcs(g,n)!=countOutArcs(g,n)) return false;
|
|
282
|
+
return connected(undirector(g));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
#endif
|