alpar@2260
|
1 |
/* -*- C++ -*-
|
alpar@2260
|
2 |
*
|
alpar@2260
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@2260
|
4 |
*
|
alpar@2260
|
5 |
* Copyright (C) 2003-2006
|
alpar@2260
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@2260
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@2260
|
8 |
*
|
alpar@2260
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@2260
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@2260
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@2260
|
12 |
*
|
alpar@2260
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@2260
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@2260
|
15 |
* purpose.
|
alpar@2260
|
16 |
*
|
alpar@2260
|
17 |
*/
|
alpar@2260
|
18 |
|
alpar@2260
|
19 |
///\ingroup concept
|
alpar@2260
|
20 |
///\file
|
alpar@2260
|
21 |
///\brief Classes for representing paths in graphs.
|
alpar@2260
|
22 |
///
|
alpar@2260
|
23 |
///\todo Iterators have obsolete style
|
alpar@2260
|
24 |
|
alpar@2260
|
25 |
#ifndef LEMON_CONCEPT_PATH_H
|
alpar@2260
|
26 |
#define LEMON_CONCEPT_PATH_H
|
alpar@2260
|
27 |
|
alpar@2260
|
28 |
#include <lemon/bits/invalid.h>
|
deba@2335
|
29 |
#include <lemon/bits/utility.h>
|
alpar@2260
|
30 |
#include <lemon/concept_check.h>
|
alpar@2260
|
31 |
|
alpar@2260
|
32 |
namespace lemon {
|
alpar@2260
|
33 |
namespace concepts {
|
deba@2335
|
34 |
|
alpar@2260
|
35 |
/// \addtogroup concept
|
alpar@2260
|
36 |
/// @{
|
alpar@2260
|
37 |
|
deba@2335
|
38 |
/// \brief A skeleton structure for representing directed paths in
|
deba@2335
|
39 |
/// a graph.
|
deba@2335
|
40 |
///
|
deba@2335
|
41 |
/// A skeleton structure for representing directed paths in a
|
deba@2335
|
42 |
/// graph.
|
deba@2335
|
43 |
/// \param _Graph The graph type in which the path is.
|
deba@2335
|
44 |
///
|
deba@2335
|
45 |
/// In a sense, the path can be treated as a list of edges. The
|
deba@2335
|
46 |
/// lemon path type stores just this list. As a consequence it
|
deba@2335
|
47 |
/// cannot enumerate the nodes in the path and the zero length
|
deba@2335
|
48 |
/// paths cannot store the source.
|
deba@2335
|
49 |
///
|
deba@2335
|
50 |
template <typename _Graph>
|
alpar@2260
|
51 |
class Path {
|
alpar@2260
|
52 |
public:
|
alpar@2260
|
53 |
|
alpar@2260
|
54 |
/// Type of the underlying graph.
|
alpar@2260
|
55 |
typedef _Graph Graph;
|
alpar@2260
|
56 |
/// Edge type of the underlying graph.
|
alpar@2260
|
57 |
typedef typename Graph::Edge Edge;
|
alpar@2260
|
58 |
|
alpar@2260
|
59 |
class EdgeIt;
|
alpar@2260
|
60 |
|
deba@2335
|
61 |
/// \brief Default constructor
|
deba@2335
|
62 |
Path() {}
|
deba@2335
|
63 |
|
deba@2335
|
64 |
/// \brief Template constructor
|
deba@2335
|
65 |
template <typename CPath>
|
deba@2335
|
66 |
Path(const CPath& cpath) {}
|
deba@2335
|
67 |
|
deba@2335
|
68 |
/// \brief Template assigment
|
deba@2335
|
69 |
template <typename CPath>
|
deba@2335
|
70 |
Path& operator=(const CPath& cpath) {}
|
alpar@2260
|
71 |
|
alpar@2260
|
72 |
/// Length of the path ie. the number of edges in the path.
|
deba@2335
|
73 |
int length() const { return 0;}
|
alpar@2260
|
74 |
|
alpar@2260
|
75 |
/// Returns whether the path is empty.
|
alpar@2260
|
76 |
bool empty() const { return true;}
|
alpar@2260
|
77 |
|
alpar@2260
|
78 |
/// Resets the path to an empty path.
|
alpar@2260
|
79 |
void clear() {}
|
alpar@2260
|
80 |
|
deba@2335
|
81 |
/// \brief Lemon style iterator for path edges
|
alpar@2260
|
82 |
///
|
deba@2335
|
83 |
/// This class is used to iterate on the edges of the paths.
|
alpar@2260
|
84 |
class EdgeIt {
|
alpar@2260
|
85 |
public:
|
alpar@2260
|
86 |
/// Default constructor
|
alpar@2260
|
87 |
EdgeIt() {}
|
alpar@2260
|
88 |
/// Invalid constructor
|
alpar@2260
|
89 |
EdgeIt(Invalid) {}
|
deba@2335
|
90 |
/// Constructor for first edge
|
alpar@2260
|
91 |
EdgeIt(const Path &) {}
|
alpar@2260
|
92 |
|
deba@2335
|
93 |
/// Conversion to Edge
|
alpar@2260
|
94 |
operator Edge() const { return INVALID; }
|
alpar@2260
|
95 |
|
alpar@2260
|
96 |
/// Next edge
|
alpar@2260
|
97 |
EdgeIt& operator++() {return *this;}
|
alpar@2260
|
98 |
|
alpar@2260
|
99 |
/// Comparison operator
|
alpar@2260
|
100 |
bool operator==(const EdgeIt&) const {return true;}
|
alpar@2260
|
101 |
/// Comparison operator
|
alpar@2260
|
102 |
bool operator!=(const EdgeIt&) const {return true;}
|
alpar@2260
|
103 |
/// Comparison operator
|
alpar@2260
|
104 |
bool operator<(const EdgeIt&) const {return false;}
|
alpar@2260
|
105 |
|
alpar@2260
|
106 |
};
|
alpar@2260
|
107 |
|
deba@2335
|
108 |
template <typename _Path>
|
deba@2335
|
109 |
struct Constraints {
|
deba@2335
|
110 |
void constraints() {
|
deba@2335
|
111 |
Path<Graph> pc;
|
deba@2335
|
112 |
_Path p, pp(pc);
|
deba@2335
|
113 |
int l = p.length();
|
deba@2335
|
114 |
int e = p.empty();
|
deba@2335
|
115 |
p.clear();
|
alpar@2260
|
116 |
|
deba@2335
|
117 |
p = pc;
|
alpar@2260
|
118 |
|
deba@2335
|
119 |
typename _Path::EdgeIt id, ii(INVALID), i(p);
|
deba@2335
|
120 |
|
deba@2335
|
121 |
++i;
|
deba@2335
|
122 |
typename Graph::Edge ed = i;
|
deba@2335
|
123 |
|
deba@2335
|
124 |
e = (i == ii);
|
deba@2335
|
125 |
e = (i != ii);
|
deba@2335
|
126 |
e = (i < ii);
|
deba@2335
|
127 |
|
deba@2335
|
128 |
ignore_unused_variable_warning(l);
|
deba@2335
|
129 |
ignore_unused_variable_warning(pp);
|
deba@2335
|
130 |
ignore_unused_variable_warning(e);
|
deba@2335
|
131 |
ignore_unused_variable_warning(id);
|
deba@2335
|
132 |
ignore_unused_variable_warning(ii);
|
deba@2335
|
133 |
ignore_unused_variable_warning(ed);
|
deba@2335
|
134 |
}
|
deba@2335
|
135 |
};
|
deba@2335
|
136 |
|
deba@2335
|
137 |
};
|
deba@2335
|
138 |
|
deba@2335
|
139 |
namespace _path_bits {
|
deba@2335
|
140 |
|
deba@2335
|
141 |
template <typename _Graph, typename _Path, typename RevPathTag = void>
|
deba@2335
|
142 |
struct PathDumperConstraints {
|
deba@2335
|
143 |
void constraints() {
|
deba@2335
|
144 |
int l = p.length();
|
deba@2335
|
145 |
int e = p.empty();
|
deba@2335
|
146 |
|
deba@2335
|
147 |
typename _Path::EdgeIt id, ii(INVALID), i(p);
|
deba@2335
|
148 |
|
deba@2335
|
149 |
++i;
|
deba@2335
|
150 |
typename _Graph::Edge ed = i;
|
deba@2335
|
151 |
|
deba@2335
|
152 |
e = (i == ii);
|
deba@2335
|
153 |
e = (i != ii);
|
deba@2335
|
154 |
e = (i < ii);
|
deba@2335
|
155 |
|
deba@2335
|
156 |
ignore_unused_variable_warning(l);
|
deba@2335
|
157 |
ignore_unused_variable_warning(e);
|
deba@2335
|
158 |
ignore_unused_variable_warning(id);
|
deba@2335
|
159 |
ignore_unused_variable_warning(ii);
|
deba@2335
|
160 |
ignore_unused_variable_warning(ed);
|
deba@2335
|
161 |
}
|
deba@2335
|
162 |
_Path& p;
|
deba@2335
|
163 |
};
|
deba@2335
|
164 |
|
deba@2335
|
165 |
template <typename _Graph, typename _Path>
|
deba@2335
|
166 |
struct PathDumperConstraints<
|
deba@2335
|
167 |
_Graph, _Path,
|
deba@2335
|
168 |
typename enable_if<typename _Path::RevPathTag, void>::type
|
deba@2335
|
169 |
> {
|
deba@2335
|
170 |
void constraints() {
|
deba@2335
|
171 |
int l = p.length();
|
deba@2335
|
172 |
int e = p.empty();
|
deba@2335
|
173 |
|
deba@2335
|
174 |
typename _Path::RevIt id, ii(INVALID), i(p);
|
deba@2335
|
175 |
|
deba@2335
|
176 |
++i;
|
deba@2335
|
177 |
typename _Graph::Edge ed = i;
|
deba@2335
|
178 |
|
deba@2335
|
179 |
e = (i == ii);
|
deba@2335
|
180 |
e = (i != ii);
|
deba@2335
|
181 |
e = (i < ii);
|
deba@2335
|
182 |
|
deba@2335
|
183 |
ignore_unused_variable_warning(l);
|
deba@2335
|
184 |
ignore_unused_variable_warning(e);
|
deba@2335
|
185 |
ignore_unused_variable_warning(id);
|
deba@2335
|
186 |
ignore_unused_variable_warning(ii);
|
deba@2335
|
187 |
ignore_unused_variable_warning(ed);
|
deba@2335
|
188 |
}
|
deba@2335
|
189 |
_Path& p;
|
deba@2335
|
190 |
};
|
deba@2335
|
191 |
|
deba@2335
|
192 |
}
|
deba@2335
|
193 |
|
deba@2335
|
194 |
|
deba@2335
|
195 |
/// \brief A skeleton structure for path dumpers.
|
deba@2335
|
196 |
///
|
deba@2335
|
197 |
/// A skeleton structure for path dumpers. The path dumpers are
|
deba@2335
|
198 |
/// the generalization of the paths. The path dumpers can
|
deba@2335
|
199 |
/// enumerate the edges of the path wheter in forward or in
|
deba@2335
|
200 |
/// backward order. In most time these classes are not used
|
deba@2335
|
201 |
/// directly rather it used to assign a dumped class to a real
|
deba@2335
|
202 |
/// path type.
|
deba@2335
|
203 |
///
|
deba@2335
|
204 |
/// The main purpose of this concept is that the shortest path
|
deba@2335
|
205 |
/// algorithms can enumerate easily the edges in reverse order.
|
deba@2335
|
206 |
/// If we would like to give back a real path from these
|
deba@2335
|
207 |
/// algorithms then we should create a temporarly path object. In
|
deba@2335
|
208 |
/// Lemon such algorithms gives back a path dumper what can
|
deba@2335
|
209 |
/// assigned to a real path and the dumpers can be implemented as
|
deba@2335
|
210 |
/// an adaptor class to the predecessor map.
|
deba@2335
|
211 |
|
deba@2335
|
212 |
/// \param _Graph The graph type in which the path is.
|
deba@2335
|
213 |
///
|
deba@2335
|
214 |
/// The paths can be constructed from any path type by a
|
deba@2335
|
215 |
/// template constructor or a template assignment operator.
|
deba@2335
|
216 |
///
|
deba@2335
|
217 |
template <typename _Graph>
|
deba@2335
|
218 |
class PathDumper {
|
deba@2335
|
219 |
public:
|
deba@2335
|
220 |
|
deba@2335
|
221 |
/// Type of the underlying graph.
|
deba@2335
|
222 |
typedef _Graph Graph;
|
deba@2335
|
223 |
/// Edge type of the underlying graph.
|
deba@2335
|
224 |
typedef typename Graph::Edge Edge;
|
deba@2335
|
225 |
|
deba@2335
|
226 |
/// Length of the path ie. the number of edges in the path.
|
deba@2335
|
227 |
int length() const { return 0;}
|
deba@2335
|
228 |
|
deba@2335
|
229 |
/// Returns whether the path is empty.
|
deba@2335
|
230 |
bool empty() const { return true;}
|
deba@2335
|
231 |
|
deba@2335
|
232 |
/// \brief Forward or reverse dumping
|
alpar@2260
|
233 |
///
|
deba@2335
|
234 |
/// If the RevPathTag is defined and true then reverse dumping
|
deba@2335
|
235 |
/// is provided in the path proxy. In this case instead of the
|
deba@2335
|
236 |
/// EdgeIt the RevIt iterator should be implemented in the
|
deba@2335
|
237 |
/// proxy.
|
deba@2335
|
238 |
typedef False RevPathTag;
|
deba@2335
|
239 |
|
deba@2335
|
240 |
/// \brief Lemon style iterator for path edges
|
alpar@2260
|
241 |
///
|
deba@2335
|
242 |
/// This class is used to iterate on the edges of the paths.
|
deba@2335
|
243 |
class EdgeIt {
|
deba@2335
|
244 |
public:
|
deba@2335
|
245 |
/// Default constructor
|
deba@2335
|
246 |
EdgeIt() {}
|
deba@2335
|
247 |
/// Invalid constructor
|
deba@2335
|
248 |
EdgeIt(Invalid) {}
|
deba@2335
|
249 |
/// Constructor for first edge
|
deba@2335
|
250 |
EdgeIt(const PathDumper&) {}
|
deba@2335
|
251 |
|
deba@2335
|
252 |
/// Conversion to Edge
|
deba@2335
|
253 |
operator Edge() const { return INVALID; }
|
deba@2335
|
254 |
|
deba@2335
|
255 |
/// Next edge
|
deba@2335
|
256 |
EdgeIt& operator++() {return *this;}
|
deba@2335
|
257 |
|
deba@2335
|
258 |
/// Comparison operator
|
deba@2335
|
259 |
bool operator==(const EdgeIt&) const {return true;}
|
deba@2335
|
260 |
/// Comparison operator
|
deba@2335
|
261 |
bool operator!=(const EdgeIt&) const {return true;}
|
deba@2335
|
262 |
/// Comparison operator
|
deba@2335
|
263 |
bool operator<(const EdgeIt&) const {return false;}
|
deba@2335
|
264 |
|
deba@2335
|
265 |
};
|
deba@2335
|
266 |
|
deba@2335
|
267 |
/// \brief Lemon style iterator for path edges
|
alpar@2260
|
268 |
///
|
deba@2335
|
269 |
/// This class is used to iterate on the edges of the paths in
|
deba@2335
|
270 |
/// reverse direction.
|
deba@2335
|
271 |
class RevIt {
|
alpar@2260
|
272 |
public:
|
deba@2335
|
273 |
/// Default constructor
|
deba@2335
|
274 |
RevIt() {}
|
deba@2335
|
275 |
/// Invalid constructor
|
deba@2335
|
276 |
RevIt(Invalid) {}
|
deba@2335
|
277 |
/// Constructor for first edge
|
deba@2335
|
278 |
RevIt(const PathDumper &) {}
|
alpar@2260
|
279 |
|
deba@2335
|
280 |
/// Conversion to Edge
|
deba@2335
|
281 |
operator Edge() const { return INVALID; }
|
alpar@2260
|
282 |
|
deba@2335
|
283 |
/// Next edge
|
deba@2335
|
284 |
RevIt& operator++() {return *this;}
|
alpar@2260
|
285 |
|
deba@2335
|
286 |
/// Comparison operator
|
deba@2335
|
287 |
bool operator==(const RevIt&) const {return true;}
|
deba@2335
|
288 |
/// Comparison operator
|
deba@2335
|
289 |
bool operator!=(const RevIt&) const {return true;}
|
deba@2335
|
290 |
/// Comparison operator
|
deba@2335
|
291 |
bool operator<(const RevIt&) const {return false;}
|
alpar@2260
|
292 |
|
alpar@2260
|
293 |
};
|
alpar@2260
|
294 |
|
alpar@2260
|
295 |
template <typename _Path>
|
alpar@2260
|
296 |
struct Constraints {
|
deba@2335
|
297 |
void constraints() {
|
deba@2335
|
298 |
function_requires<_path_bits::
|
deba@2335
|
299 |
PathDumperConstraints<Graph, _Path> >();
|
deba@2335
|
300 |
}
|
alpar@2260
|
301 |
};
|
alpar@2260
|
302 |
|
alpar@2260
|
303 |
};
|
alpar@2260
|
304 |
|
deba@2335
|
305 |
|
deba@2335
|
306 |
///@}
|
alpar@2260
|
307 |
}
|
alpar@2260
|
308 |
|
alpar@2260
|
309 |
} // namespace lemon
|
alpar@2260
|
310 |
|
alpar@2260
|
311 |
#endif // LEMON_CONCEPT_PATH_H
|