klao@959
|
1 |
/* -*- C++ -*-
|
klao@959
|
2 |
* src/lemon/concept/path.h - Part of LEMON, a generic C++ optimization library
|
klao@959
|
3 |
*
|
klao@959
|
4 |
* Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
klao@959
|
5 |
* (Egervary Combinatorial Optimization Research Group, EGRES).
|
klao@959
|
6 |
*
|
klao@959
|
7 |
* Permission to use, modify and distribute this software is granted
|
klao@959
|
8 |
* provided that this copyright notice appears in all copies. For
|
klao@959
|
9 |
* precise terms see the accompanying LICENSE file.
|
klao@959
|
10 |
*
|
klao@959
|
11 |
* This software is provided "AS IS" with no warranty of any kind,
|
klao@959
|
12 |
* express or implied, and with no claim as to its suitability for any
|
klao@959
|
13 |
* purpose.
|
klao@959
|
14 |
*
|
klao@959
|
15 |
*/
|
klao@959
|
16 |
|
klao@959
|
17 |
///\ingroup concept
|
klao@959
|
18 |
///\file
|
klao@959
|
19 |
///\brief Classes for representing paths in graphs.
|
alpar@1151
|
20 |
///
|
alpar@1151
|
21 |
///\todo Iterators have obsolete style
|
klao@959
|
22 |
|
klao@959
|
23 |
#ifndef LEMON_CONCEPT_PATH_H
|
klao@959
|
24 |
#define LEMON_CONCEPT_PATH_H
|
klao@959
|
25 |
|
klao@959
|
26 |
#include <lemon/invalid.h>
|
klao@959
|
27 |
|
klao@959
|
28 |
namespace lemon {
|
klao@959
|
29 |
namespace concept {
|
klao@959
|
30 |
/// \addtogroup concept
|
klao@959
|
31 |
/// @{
|
klao@959
|
32 |
|
klao@959
|
33 |
|
alpar@967
|
34 |
//! \brief A skeleton structure for representing directed paths in a graph.
|
klao@959
|
35 |
//!
|
klao@959
|
36 |
//! A skeleton structure for representing directed paths in a graph.
|
klao@959
|
37 |
//! \param GR The graph type in which the path is.
|
klao@959
|
38 |
//!
|
klao@959
|
39 |
//! In a sense, the path can be treated as a graph, for is has \c NodeIt
|
klao@959
|
40 |
//! and \c EdgeIt with the same usage. These types converts to the \c Node
|
klao@959
|
41 |
//! and \c Edge of the original graph.
|
klao@959
|
42 |
template<typename GR>
|
klao@959
|
43 |
class Path {
|
klao@959
|
44 |
public:
|
klao@959
|
45 |
|
klao@959
|
46 |
/// Type of the underlying graph.
|
klao@959
|
47 |
typedef /*typename*/ GR Graph;
|
klao@959
|
48 |
/// Edge type of the underlying graph.
|
klao@959
|
49 |
typedef typename Graph::Edge GraphEdge;
|
klao@959
|
50 |
/// Node type of the underlying graph.
|
klao@959
|
51 |
typedef typename Graph::Node GraphNode;
|
klao@959
|
52 |
class NodeIt;
|
klao@959
|
53 |
class EdgeIt;
|
klao@959
|
54 |
|
klao@959
|
55 |
/// \param _G The graph in which the path is.
|
klao@959
|
56 |
///
|
klao@959
|
57 |
Path(const Graph &_G) {}
|
klao@959
|
58 |
|
klao@959
|
59 |
/// Length of the path.
|
klao@959
|
60 |
size_t length() const {return 0;}
|
klao@959
|
61 |
/// Returns whether the path is empty.
|
klao@959
|
62 |
bool empty() const { return true;}
|
klao@959
|
63 |
|
klao@959
|
64 |
/// Resets the path to an empty path.
|
klao@959
|
65 |
void clear() {}
|
klao@959
|
66 |
|
klao@959
|
67 |
/// \brief Starting point of the path.
|
klao@959
|
68 |
///
|
klao@959
|
69 |
/// Starting point of the path.
|
klao@959
|
70 |
/// Returns INVALID if the path is empty.
|
alpar@986
|
71 |
GraphNode/*It*/ target() const {return INVALID;}
|
klao@959
|
72 |
/// \brief End point of the path.
|
klao@959
|
73 |
///
|
klao@959
|
74 |
/// End point of the path.
|
klao@959
|
75 |
/// Returns INVALID if the path is empty.
|
alpar@986
|
76 |
GraphNode/*It*/ source() const {return INVALID;}
|
klao@959
|
77 |
|
klao@959
|
78 |
/// \brief First NodeIt/EdgeIt.
|
klao@959
|
79 |
///
|
klao@959
|
80 |
/// Initializes node or edge iterator to point to the first
|
klao@959
|
81 |
/// node or edge.
|
klao@959
|
82 |
template<typename It>
|
klao@959
|
83 |
It& first(It &i) const { return i=It(*this); }
|
klao@959
|
84 |
|
alpar@986
|
85 |
/// \brief The target of an edge.
|
klao@959
|
86 |
///
|
alpar@986
|
87 |
/// Returns node iterator pointing to the target node of the
|
klao@959
|
88 |
/// given edge iterator.
|
alpar@986
|
89 |
NodeIt target(const EdgeIt& e) const {return INVALID;}
|
klao@959
|
90 |
|
alpar@986
|
91 |
/// \brief The source of an edge.
|
klao@959
|
92 |
///
|
alpar@986
|
93 |
/// Returns node iterator pointing to the source node of the
|
klao@959
|
94 |
/// given edge iterator.
|
alpar@986
|
95 |
NodeIt source(const EdgeIt& e) const {return INVALID;}
|
klao@959
|
96 |
|
klao@959
|
97 |
|
klao@959
|
98 |
/* Iterator classes */
|
klao@959
|
99 |
|
klao@959
|
100 |
/**
|
klao@959
|
101 |
* \brief Iterator class to iterate on the edges of the paths
|
klao@959
|
102 |
*
|
klao@959
|
103 |
* This class is used to iterate on the edges of the paths
|
klao@959
|
104 |
*
|
klao@959
|
105 |
* Of course it converts to Graph::Edge
|
klao@959
|
106 |
*
|
klao@959
|
107 |
*/
|
klao@959
|
108 |
class EdgeIt {
|
klao@959
|
109 |
public:
|
klao@959
|
110 |
/// Default constructor
|
klao@959
|
111 |
EdgeIt() {}
|
klao@959
|
112 |
/// Invalid constructor
|
klao@959
|
113 |
EdgeIt(Invalid) {}
|
klao@959
|
114 |
/// Constructor with starting point
|
klao@959
|
115 |
EdgeIt(const Path &_p) {}
|
klao@959
|
116 |
|
klao@959
|
117 |
operator GraphEdge () const {}
|
klao@959
|
118 |
|
klao@959
|
119 |
/// Next edge
|
klao@959
|
120 |
EdgeIt& operator++() {return *this;}
|
klao@959
|
121 |
|
klao@959
|
122 |
/// Comparison operator
|
klao@959
|
123 |
bool operator==(const EdgeIt& e) const {return true;}
|
klao@959
|
124 |
/// Comparison operator
|
klao@959
|
125 |
bool operator!=(const EdgeIt& e) const {return true;}
|
klao@959
|
126 |
// /// Comparison operator
|
klao@959
|
127 |
// /// \todo It is not clear what is the "natural" ordering.
|
klao@959
|
128 |
// bool operator<(const EdgeIt& e) const {}
|
klao@959
|
129 |
|
klao@959
|
130 |
};
|
klao@959
|
131 |
|
klao@959
|
132 |
/**
|
klao@959
|
133 |
* \brief Iterator class to iterate on the nodes of the paths
|
klao@959
|
134 |
*
|
klao@959
|
135 |
* This class is used to iterate on the nodes of the paths
|
klao@959
|
136 |
*
|
klao@959
|
137 |
* Of course it converts to Graph::Node.
|
klao@959
|
138 |
*
|
klao@959
|
139 |
*/
|
klao@959
|
140 |
class NodeIt {
|
klao@959
|
141 |
public:
|
klao@959
|
142 |
/// Default constructor
|
klao@959
|
143 |
NodeIt() {}
|
klao@959
|
144 |
/// Invalid constructor
|
klao@959
|
145 |
NodeIt(Invalid) {}
|
klao@959
|
146 |
/// Constructor with starting point
|
klao@959
|
147 |
NodeIt(const Path &_p) {}
|
klao@959
|
148 |
|
klao@959
|
149 |
///Conversion to Graph::Node
|
klao@959
|
150 |
operator const GraphNode& () const {}
|
klao@959
|
151 |
/// Next node
|
klao@959
|
152 |
NodeIt& operator++() {return *this;}
|
klao@959
|
153 |
|
klao@959
|
154 |
/// Comparison operator
|
klao@959
|
155 |
bool operator==(const NodeIt& e) const {return true;}
|
klao@959
|
156 |
/// Comparison operator
|
klao@959
|
157 |
bool operator!=(const NodeIt& e) const {return true;}
|
klao@959
|
158 |
// /// Comparison operator
|
klao@959
|
159 |
// /// \todo It is not clear what is the "natural" ordering.
|
klao@959
|
160 |
// bool operator<(const NodeIt& e) const {}
|
klao@959
|
161 |
|
klao@959
|
162 |
};
|
klao@959
|
163 |
|
klao@959
|
164 |
friend class Builder;
|
klao@959
|
165 |
|
klao@959
|
166 |
/**
|
klao@959
|
167 |
* \brief Class to build paths
|
klao@959
|
168 |
*
|
klao@959
|
169 |
* This class is used to fill a path with edges.
|
klao@959
|
170 |
*
|
klao@959
|
171 |
* You can push new edges to the front and to the back of the path in
|
klao@959
|
172 |
* arbitrary order then you should commit these changes to the graph.
|
klao@959
|
173 |
*
|
klao@959
|
174 |
* While the builder is active (after the first modifying
|
klao@959
|
175 |
* operation and until the call of \ref commit())
|
klao@959
|
176 |
* the underlining Path is in a
|
klao@959
|
177 |
* "transitional" state (operations on it have undefined result).
|
klao@959
|
178 |
*/
|
klao@959
|
179 |
class Builder {
|
klao@959
|
180 |
public:
|
klao@959
|
181 |
|
klao@959
|
182 |
Path &P;
|
klao@959
|
183 |
|
klao@959
|
184 |
///\param _P the path you want to fill in.
|
klao@959
|
185 |
///
|
klao@959
|
186 |
Builder(Path &_P) : P(_P) {}
|
klao@959
|
187 |
|
klao@959
|
188 |
/// Sets the starting node of the path.
|
klao@959
|
189 |
|
klao@959
|
190 |
/// Sets the starting node of the path. Edge added to the path
|
klao@959
|
191 |
/// afterwards have to be incident to this node.
|
klao@959
|
192 |
/// You \em must start building an empry path with this functions.
|
klao@959
|
193 |
/// (And you \em must \em not use it later).
|
klao@959
|
194 |
/// \sa pushFront()
|
klao@959
|
195 |
/// \sa pushBack()
|
klao@959
|
196 |
void setStartNode(const GraphNode &) {}
|
klao@959
|
197 |
|
klao@959
|
198 |
///Push a new edge to the front of the path
|
klao@959
|
199 |
|
klao@959
|
200 |
///Push a new edge to the front of the path.
|
klao@959
|
201 |
///If the path is empty, you \em must call \ref setStartNode() before
|
klao@959
|
202 |
///the first use of \ref pushFront().
|
klao@959
|
203 |
void pushFront(const GraphEdge& e) {}
|
klao@959
|
204 |
|
klao@959
|
205 |
///Push a new edge to the back of the path
|
klao@959
|
206 |
|
klao@959
|
207 |
///Push a new edge to the back of the path.
|
klao@959
|
208 |
///If the path is empty, you \em must call \ref setStartNode() before
|
klao@959
|
209 |
///the first use of \ref pushBack().
|
klao@959
|
210 |
void pushBack(const GraphEdge& e) {}
|
klao@959
|
211 |
|
klao@959
|
212 |
///Commit the changes to the path.
|
klao@959
|
213 |
void commit() {}
|
klao@959
|
214 |
|
klao@959
|
215 |
///Reserve (front) storage for the builder in advance.
|
klao@959
|
216 |
|
klao@959
|
217 |
///If you know an reasonable upper bound of the number of the edges
|
klao@959
|
218 |
///to add to the front of the path,
|
klao@959
|
219 |
///using this function you may speed up the building.
|
klao@959
|
220 |
void reserveFront(size_t r) {}
|
klao@959
|
221 |
///Reserve (back) storage for the builder in advance.
|
klao@959
|
222 |
|
klao@959
|
223 |
///If you know an reasonable upper bound of the number of the edges
|
klao@959
|
224 |
///to add to the back of the path,
|
klao@959
|
225 |
///using this function you may speed up the building.
|
klao@959
|
226 |
void reserveBack(size_t r) {}
|
klao@959
|
227 |
};
|
klao@959
|
228 |
};
|
klao@959
|
229 |
|
klao@959
|
230 |
///@}
|
klao@959
|
231 |
}
|
klao@959
|
232 |
|
klao@959
|
233 |
} // namespace lemon
|
klao@959
|
234 |
|
klao@959
|
235 |
#endif // LEMON_CONCEPT_PATH_H
|