1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2013
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
21 ///\brief The concept of paths
24 #ifndef LEMON_CONCEPTS_PATH_H
25 #define LEMON_CONCEPTS_PATH_H
27 #include <lemon/core.h>
28 #include <lemon/concept_check.h>
29 #include <lemon/bits/stl_iterators.h>
34 /// \addtogroup concept
37 /// \brief A skeleton structure for representing directed paths in
40 /// A skeleton structure for representing directed paths in a
42 /// In a sense, a path can be treated as a list of arcs.
43 /// LEMON path types just store this list. As a consequence, they cannot
44 /// enumerate the nodes on the path directly and a zero length path
45 /// cannot store its source node.
47 /// The arcs of a path should be stored in the order of their directions,
48 /// i.e. the target node of each arc should be the same as the source
49 /// node of the next arc. This consistency could be checked using
51 /// The source and target nodes of a (consistent) path can be obtained
52 /// using \ref pathSource() and \ref pathTarget().
54 /// A path can be constructed from another path of any type using the
55 /// copy constructor or the assignment operator.
57 /// \tparam GR The digraph type in which the path is.
58 template <typename GR>
62 /// Type of the underlying digraph.
64 /// Arc type of the underlying digraph.
65 typedef typename Digraph::Arc Arc;
69 /// \brief Default constructor
72 /// \brief Template copy constructor
73 template <typename CPath>
74 Path(const CPath& cpath) {}
76 /// \brief Template assigment operator
77 template <typename CPath>
78 Path& operator=(const CPath& cpath) {
79 ::lemon::ignore_unused_variable_warning(cpath);
83 /// Length of the path, i.e. the number of arcs on the path.
84 int length() const { return 0;}
86 /// Returns whether the path is empty.
87 bool empty() const { return true;}
89 /// Resets the path to an empty path.
92 /// \brief LEMON style iterator for enumerating the arcs of a path.
94 /// LEMON style iterator class for enumerating the arcs of a path.
97 /// Default constructor
99 /// Invalid constructor
101 /// Sets the iterator to the first arc of the given path
102 ArcIt(const Path &) {}
104 /// Conversion to \c Arc
105 operator Arc() const { return INVALID; }
108 ArcIt& operator++() {return *this;}
110 /// Comparison operator
111 bool operator==(const ArcIt&) const {return true;}
112 /// Comparison operator
113 bool operator!=(const ArcIt&) const {return true;}
114 /// Comparison operator
115 bool operator<(const ArcIt&) const {return false;}
119 /// \brief Gets the collection of the arcs of the path.
121 /// This function can be used for iterating on the
122 /// arcs of the path. It returns a wrapped
123 /// ArcIt, which looks like an STL container
124 /// (by having begin() and end()) which you can use in range-based
125 /// for loops, STL algorithms, etc.
126 /// For example you can write:
128 /// for(auto a: p.arcs())
131 LemonRangeWrapper1<ArcIt, Path> arcs() const {
132 return LemonRangeWrapper1<ArcIt, Path>(*this);
136 template <typename _Path>
147 typename _Path::ArcIt id, ii(INVALID), i(p);
150 typename Digraph::Arc ed = i;
156 ::lemon::ignore_unused_variable_warning(l);
157 ::lemon::ignore_unused_variable_warning(pp);
158 ::lemon::ignore_unused_variable_warning(e);
159 ::lemon::ignore_unused_variable_warning(id);
160 ::lemon::ignore_unused_variable_warning(ii);
161 ::lemon::ignore_unused_variable_warning(ed);
167 namespace _path_bits {
169 template <typename _Digraph, typename _Path, typename RevPathTag = void>
170 struct PathDumperConstraints {
175 typename _Path::ArcIt id, i(p);
178 typename _Digraph::Arc ed = i;
183 ::lemon::ignore_unused_variable_warning(l);
184 ::lemon::ignore_unused_variable_warning(e);
185 ::lemon::ignore_unused_variable_warning(id);
186 ::lemon::ignore_unused_variable_warning(ed);
189 PathDumperConstraints() {}
192 template <typename _Digraph, typename _Path>
193 struct PathDumperConstraints<
195 typename enable_if<typename _Path::RevPathTag, void>::type
201 typename _Path::RevArcIt id, i(p);
204 typename _Digraph::Arc ed = i;
209 ::lemon::ignore_unused_variable_warning(l);
210 ::lemon::ignore_unused_variable_warning(e);
211 ::lemon::ignore_unused_variable_warning(id);
212 ::lemon::ignore_unused_variable_warning(ed);
215 PathDumperConstraints() {}
221 /// \brief A skeleton structure for path dumpers.
223 /// A skeleton structure for path dumpers. The path dumpers are
224 /// the generalization of the paths, they can enumerate the arcs
225 /// of the path either in forward or in backward order.
226 /// These classes are typically not used directly, they are rather
227 /// used to be assigned to a real path type.
229 /// The main purpose of this concept is that the shortest path
230 /// algorithms can enumerate the arcs easily in reverse order.
231 /// In LEMON, such algorithms give back a (reverse) path dumper that
232 /// can be assigned to a real path. The dumpers can be implemented as
233 /// an adaptor class to the predecessor map.
235 /// \tparam GR The digraph type in which the path is.
236 template <typename GR>
240 /// Type of the underlying digraph.
242 /// Arc type of the underlying digraph.
243 typedef typename Digraph::Arc Arc;
245 /// Length of the path, i.e. the number of arcs on the path.
246 int length() const { return 0;}
248 /// Returns whether the path is empty.
249 bool empty() const { return true;}
251 /// \brief Forward or reverse dumping
253 /// If this tag is defined to be \c True, then reverse dumping
254 /// is provided in the path dumper. In this case, \c RevArcIt
255 /// iterator should be implemented instead of \c ArcIt iterator.
256 typedef False RevPathTag;
258 /// \brief LEMON style iterator for enumerating the arcs of a path.
260 /// LEMON style iterator class for enumerating the arcs of a path.
263 /// Default constructor
265 /// Invalid constructor
267 /// Sets the iterator to the first arc of the given path
268 ArcIt(const PathDumper&) {}
270 /// Conversion to \c Arc
271 operator Arc() const { return INVALID; }
274 ArcIt& operator++() {return *this;}
276 /// Comparison operator
277 bool operator==(const ArcIt&) const {return true;}
278 /// Comparison operator
279 bool operator!=(const ArcIt&) const {return true;}
280 /// Comparison operator
281 bool operator<(const ArcIt&) const {return false;}
285 /// \brief Gets the collection of the arcs of the path.
287 /// This function can be used for iterating on the
288 /// arcs of the path. It returns a wrapped
289 /// ArcIt, which looks like an STL container
290 /// (by having begin() and end()) which you can use in range-based
291 /// for loops, STL algorithms, etc.
292 /// For example you can write:
294 /// for(auto a: p.arcs())
297 LemonRangeWrapper1<ArcIt, PathDumper> arcs() const {
298 return LemonRangeWrapper1<ArcIt, PathDumper>(*this);
302 /// \brief LEMON style iterator for enumerating the arcs of a path
303 /// in reverse direction.
305 /// LEMON style iterator class for enumerating the arcs of a path
306 /// in reverse direction.
309 /// Default constructor
311 /// Invalid constructor
313 /// Sets the iterator to the last arc of the given path
314 RevArcIt(const PathDumper &) {}
316 /// Conversion to \c Arc
317 operator Arc() const { return INVALID; }
320 RevArcIt& operator++() {return *this;}
322 /// Comparison operator
323 bool operator==(const RevArcIt&) const {return true;}
324 /// Comparison operator
325 bool operator!=(const RevArcIt&) const {return true;}
326 /// Comparison operator
327 bool operator<(const RevArcIt&) const {return false;}
331 /// \brief Gets the collection of the arcs of the path
332 /// in reverse direction.
334 /// This function can be used for iterating on the
335 /// arcs of the path in reverse direction. It returns a wrapped
336 /// RevArcIt, which looks like an STL container
337 /// (by having begin() and end()) which you can use in range-based
338 /// for loops, STL algorithms, etc.
339 /// For example you can write:
341 /// for(auto a: p.revArcs())
344 LemonRangeWrapper1<RevArcIt, PathDumper> revArcs() const {
345 return LemonRangeWrapper1<RevArcIt, PathDumper>(*this);
349 template <typename _Path>
352 function_requires<_path_bits::
353 PathDumperConstraints<Digraph, _Path> >();