alpar@209
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
deba@57
|
2 |
*
|
alpar@209
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
deba@57
|
4 |
*
|
alpar@1092
|
5 |
* Copyright (C) 2003-2013
|
deba@57
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@57
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@57
|
8 |
*
|
deba@57
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@57
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@57
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@57
|
12 |
*
|
deba@57
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@57
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@57
|
15 |
* purpose.
|
deba@57
|
16 |
*
|
deba@57
|
17 |
*/
|
deba@57
|
18 |
|
deba@529
|
19 |
#ifndef LEMON_CONCEPTS_DIGRAPH_H
|
deba@529
|
20 |
#define LEMON_CONCEPTS_DIGRAPH_H
|
deba@57
|
21 |
|
deba@57
|
22 |
///\ingroup graph_concepts
|
deba@57
|
23 |
///\file
|
deba@57
|
24 |
///\brief The concept of directed graphs.
|
deba@57
|
25 |
|
deba@220
|
26 |
#include <lemon/core.h>
|
deba@57
|
27 |
#include <lemon/concepts/maps.h>
|
deba@57
|
28 |
#include <lemon/concept_check.h>
|
deba@57
|
29 |
#include <lemon/concepts/graph_components.h>
|
ggab90@1130
|
30 |
#include <lemon/bits/stl_iterators.h>
|
deba@57
|
31 |
|
deba@57
|
32 |
namespace lemon {
|
deba@57
|
33 |
namespace concepts {
|
deba@57
|
34 |
|
deba@57
|
35 |
/// \ingroup graph_concepts
|
deba@57
|
36 |
///
|
deba@57
|
37 |
/// \brief Class describing the concept of directed graphs.
|
deba@57
|
38 |
///
|
kpeter@734
|
39 |
/// This class describes the common interface of all directed
|
kpeter@734
|
40 |
/// graphs (digraphs).
|
deba@57
|
41 |
///
|
kpeter@734
|
42 |
/// Like all concept classes, it only provides an interface
|
kpeter@734
|
43 |
/// without any sensible implementation. So any general algorithm for
|
kpeter@734
|
44 |
/// directed graphs should compile with this class, but it will not
|
kpeter@734
|
45 |
/// run properly, of course.
|
kpeter@734
|
46 |
/// An actual digraph implementation like \ref ListDigraph or
|
kpeter@734
|
47 |
/// \ref SmartDigraph may have additional functionality.
|
deba@57
|
48 |
///
|
kpeter@734
|
49 |
/// \sa Graph
|
deba@57
|
50 |
class Digraph {
|
deba@57
|
51 |
private:
|
kpeter@734
|
52 |
/// Diraphs are \e not copy constructible. Use DigraphCopy instead.
|
kpeter@734
|
53 |
Digraph(const Digraph &) {}
|
kpeter@734
|
54 |
/// \brief Assignment of a digraph to another one is \e not allowed.
|
kpeter@734
|
55 |
/// Use DigraphCopy instead.
|
kpeter@734
|
56 |
void operator=(const Digraph &) {}
|
alpar@209
|
57 |
|
kpeter@734
|
58 |
public:
|
kpeter@734
|
59 |
/// Default constructor.
|
kpeter@734
|
60 |
Digraph() { }
|
alpar@209
|
61 |
|
kpeter@734
|
62 |
/// The node type of the digraph
|
deba@57
|
63 |
|
deba@57
|
64 |
/// This class identifies a node of the digraph. It also serves
|
deba@57
|
65 |
/// as a base class of the node iterators,
|
kpeter@734
|
66 |
/// thus they convert to this type.
|
deba@57
|
67 |
class Node {
|
deba@57
|
68 |
public:
|
deba@57
|
69 |
/// Default constructor
|
deba@57
|
70 |
|
kpeter@734
|
71 |
/// Default constructor.
|
kpeter@734
|
72 |
/// \warning It sets the object to an undefined value.
|
deba@57
|
73 |
Node() { }
|
deba@57
|
74 |
/// Copy constructor.
|
deba@57
|
75 |
|
deba@57
|
76 |
/// Copy constructor.
|
deba@57
|
77 |
///
|
deba@57
|
78 |
Node(const Node&) { }
|
deba@57
|
79 |
|
kpeter@734
|
80 |
/// %Invalid constructor \& conversion.
|
deba@57
|
81 |
|
kpeter@734
|
82 |
/// Initializes the object to be invalid.
|
deba@57
|
83 |
/// \sa Invalid for more details.
|
deba@57
|
84 |
Node(Invalid) { }
|
deba@57
|
85 |
/// Equality operator
|
deba@57
|
86 |
|
kpeter@734
|
87 |
/// Equality operator.
|
kpeter@734
|
88 |
///
|
deba@57
|
89 |
/// Two iterators are equal if and only if they point to the
|
kpeter@734
|
90 |
/// same object or both are \c INVALID.
|
deba@57
|
91 |
bool operator==(Node) const { return true; }
|
deba@57
|
92 |
|
deba@57
|
93 |
/// Inequality operator
|
alpar@209
|
94 |
|
kpeter@734
|
95 |
/// Inequality operator.
|
deba@57
|
96 |
bool operator!=(Node) const { return true; }
|
deba@57
|
97 |
|
alpar@209
|
98 |
/// Artificial ordering operator.
|
alpar@209
|
99 |
|
kpeter@734
|
100 |
/// Artificial ordering operator.
|
alpar@209
|
101 |
///
|
kpeter@734
|
102 |
/// \note This operator only has to define some strict ordering of
|
kpeter@734
|
103 |
/// the nodes; this order has nothing to do with the iteration
|
kpeter@734
|
104 |
/// ordering of the nodes.
|
alpar@209
|
105 |
bool operator<(Node) const { return false; }
|
deba@57
|
106 |
};
|
alpar@209
|
107 |
|
kpeter@734
|
108 |
/// Iterator class for the nodes.
|
deba@57
|
109 |
|
kpeter@734
|
110 |
/// This iterator goes through each node of the digraph.
|
kpeter@786
|
111 |
/// Its usage is quite simple, for example, you can count the number
|
kpeter@734
|
112 |
/// of nodes in a digraph \c g of type \c %Digraph like this:
|
deba@57
|
113 |
///\code
|
deba@57
|
114 |
/// int count=0;
|
deba@57
|
115 |
/// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count;
|
deba@57
|
116 |
///\endcode
|
deba@57
|
117 |
class NodeIt : public Node {
|
deba@57
|
118 |
public:
|
deba@57
|
119 |
/// Default constructor
|
deba@57
|
120 |
|
kpeter@734
|
121 |
/// Default constructor.
|
kpeter@734
|
122 |
/// \warning It sets the iterator to an undefined value.
|
deba@57
|
123 |
NodeIt() { }
|
deba@57
|
124 |
/// Copy constructor.
|
alpar@209
|
125 |
|
deba@57
|
126 |
/// Copy constructor.
|
deba@57
|
127 |
///
|
deba@57
|
128 |
NodeIt(const NodeIt& n) : Node(n) { }
|
kpeter@734
|
129 |
/// %Invalid constructor \& conversion.
|
deba@57
|
130 |
|
kpeter@734
|
131 |
/// Initializes the iterator to be invalid.
|
deba@57
|
132 |
/// \sa Invalid for more details.
|
deba@57
|
133 |
NodeIt(Invalid) { }
|
deba@57
|
134 |
/// Sets the iterator to the first node.
|
deba@57
|
135 |
|
kpeter@734
|
136 |
/// Sets the iterator to the first node of the given digraph.
|
deba@57
|
137 |
///
|
kpeter@734
|
138 |
explicit NodeIt(const Digraph&) { }
|
kpeter@734
|
139 |
/// Sets the iterator to the given node.
|
deba@57
|
140 |
|
kpeter@734
|
141 |
/// Sets the iterator to the given node of the given digraph.
|
kpeter@734
|
142 |
///
|
deba@57
|
143 |
NodeIt(const Digraph&, const Node&) { }
|
deba@57
|
144 |
/// Next node.
|
deba@57
|
145 |
|
deba@57
|
146 |
/// Assign the iterator to the next node.
|
deba@57
|
147 |
///
|
deba@57
|
148 |
NodeIt& operator++() { return *this; }
|
deba@57
|
149 |
};
|
alpar@209
|
150 |
|
ggab90@1130
|
151 |
/// \brief Gets the collection of the nodes of the digraph.
|
ggab90@1130
|
152 |
///
|
ggab90@1130
|
153 |
/// This function can be used for iterating on
|
ggab90@1130
|
154 |
/// the nodes of the digraph. It returns a wrapped NodeIt, which looks
|
ggab90@1130
|
155 |
/// like an STL container (by having begin() and end())
|
ggab90@1130
|
156 |
/// which you can use in range-based for loops, STL algorithms, etc.
|
ggab90@1130
|
157 |
/// For example you can write:
|
ggab90@1130
|
158 |
///\code
|
ggab90@1130
|
159 |
/// ListDigraph g;
|
ggab90@1130
|
160 |
/// for(auto v: g.nodes())
|
ggab90@1130
|
161 |
/// doSomething(v);
|
ggab90@1130
|
162 |
///
|
ggab90@1130
|
163 |
/// //Using an STL algorithm:
|
ggab90@1130
|
164 |
/// copy(g.nodes().begin(), g.nodes().end(), vect.begin());
|
ggab90@1130
|
165 |
///\endcode
|
ggab90@1130
|
166 |
LemonRangeWrapper1<NodeIt, Digraph> nodes() const {
|
ggab90@1130
|
167 |
return LemonRangeWrapper1<NodeIt, Digraph>(*this);
|
ggab90@1130
|
168 |
}
|
ggab90@1130
|
169 |
|
alpar@209
|
170 |
|
kpeter@734
|
171 |
/// The arc type of the digraph
|
deba@57
|
172 |
|
deba@57
|
173 |
/// This class identifies an arc of the digraph. It also serves
|
deba@57
|
174 |
/// as a base class of the arc iterators,
|
deba@57
|
175 |
/// thus they will convert to this type.
|
deba@57
|
176 |
class Arc {
|
deba@57
|
177 |
public:
|
deba@57
|
178 |
/// Default constructor
|
deba@57
|
179 |
|
kpeter@734
|
180 |
/// Default constructor.
|
kpeter@734
|
181 |
/// \warning It sets the object to an undefined value.
|
deba@57
|
182 |
Arc() { }
|
deba@57
|
183 |
/// Copy constructor.
|
deba@57
|
184 |
|
deba@57
|
185 |
/// Copy constructor.
|
deba@57
|
186 |
///
|
deba@57
|
187 |
Arc(const Arc&) { }
|
kpeter@734
|
188 |
/// %Invalid constructor \& conversion.
|
deba@57
|
189 |
|
kpeter@734
|
190 |
/// Initializes the object to be invalid.
|
kpeter@734
|
191 |
/// \sa Invalid for more details.
|
deba@57
|
192 |
Arc(Invalid) { }
|
deba@57
|
193 |
/// Equality operator
|
deba@57
|
194 |
|
kpeter@734
|
195 |
/// Equality operator.
|
kpeter@734
|
196 |
///
|
deba@57
|
197 |
/// Two iterators are equal if and only if they point to the
|
kpeter@734
|
198 |
/// same object or both are \c INVALID.
|
deba@57
|
199 |
bool operator==(Arc) const { return true; }
|
deba@57
|
200 |
/// Inequality operator
|
deba@57
|
201 |
|
kpeter@734
|
202 |
/// Inequality operator.
|
deba@57
|
203 |
bool operator!=(Arc) const { return true; }
|
deba@57
|
204 |
|
alpar@209
|
205 |
/// Artificial ordering operator.
|
alpar@209
|
206 |
|
kpeter@734
|
207 |
/// Artificial ordering operator.
|
alpar@209
|
208 |
///
|
kpeter@734
|
209 |
/// \note This operator only has to define some strict ordering of
|
kpeter@734
|
210 |
/// the arcs; this order has nothing to do with the iteration
|
kpeter@734
|
211 |
/// ordering of the arcs.
|
alpar@209
|
212 |
bool operator<(Arc) const { return false; }
|
deba@57
|
213 |
};
|
alpar@209
|
214 |
|
kpeter@734
|
215 |
/// Iterator class for the outgoing arcs of a node.
|
deba@57
|
216 |
|
deba@57
|
217 |
/// This iterator goes trough the \e outgoing arcs of a certain node
|
deba@57
|
218 |
/// of a digraph.
|
kpeter@786
|
219 |
/// Its usage is quite simple, for example, you can count the number
|
deba@57
|
220 |
/// of outgoing arcs of a node \c n
|
kpeter@734
|
221 |
/// in a digraph \c g of type \c %Digraph as follows.
|
deba@57
|
222 |
///\code
|
deba@57
|
223 |
/// int count=0;
|
kpeter@734
|
224 |
/// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
|
deba@57
|
225 |
///\endcode
|
deba@57
|
226 |
class OutArcIt : public Arc {
|
deba@57
|
227 |
public:
|
deba@57
|
228 |
/// Default constructor
|
deba@57
|
229 |
|
kpeter@734
|
230 |
/// Default constructor.
|
kpeter@734
|
231 |
/// \warning It sets the iterator to an undefined value.
|
deba@57
|
232 |
OutArcIt() { }
|
deba@57
|
233 |
/// Copy constructor.
|
deba@57
|
234 |
|
deba@57
|
235 |
/// Copy constructor.
|
deba@57
|
236 |
///
|
deba@57
|
237 |
OutArcIt(const OutArcIt& e) : Arc(e) { }
|
kpeter@734
|
238 |
/// %Invalid constructor \& conversion.
|
deba@57
|
239 |
|
kpeter@734
|
240 |
/// Initializes the iterator to be invalid.
|
kpeter@734
|
241 |
/// \sa Invalid for more details.
|
kpeter@734
|
242 |
OutArcIt(Invalid) { }
|
kpeter@734
|
243 |
/// Sets the iterator to the first outgoing arc.
|
kpeter@734
|
244 |
|
kpeter@734
|
245 |
/// Sets the iterator to the first outgoing arc of the given node.
|
deba@57
|
246 |
///
|
kpeter@734
|
247 |
OutArcIt(const Digraph&, const Node&) { }
|
kpeter@734
|
248 |
/// Sets the iterator to the given arc.
|
alpar@209
|
249 |
|
kpeter@734
|
250 |
/// Sets the iterator to the given arc of the given digraph.
|
kpeter@734
|
251 |
///
|
deba@57
|
252 |
OutArcIt(const Digraph&, const Arc&) { }
|
kpeter@734
|
253 |
/// Next outgoing arc
|
alpar@209
|
254 |
|
alpar@209
|
255 |
/// Assign the iterator to the next
|
deba@57
|
256 |
/// outgoing arc of the corresponding node.
|
deba@57
|
257 |
OutArcIt& operator++() { return *this; }
|
deba@57
|
258 |
};
|
deba@57
|
259 |
|
ggab90@1130
|
260 |
/// \brief Gets the collection of the outgoing arcs of a certain node
|
ggab90@1130
|
261 |
/// of the digraph.
|
ggab90@1130
|
262 |
///
|
ggab90@1130
|
263 |
/// This function can be used for iterating on the
|
ggab90@1130
|
264 |
/// outgoing arcs of a certain node of the digraph. It returns a wrapped
|
ggab90@1130
|
265 |
/// OutArcIt, which looks like an STL container
|
ggab90@1130
|
266 |
/// (by having begin() and end()) which you can use in range-based
|
ggab90@1130
|
267 |
/// for loops, STL algorithms, etc.
|
ggab90@1130
|
268 |
/// For example if g is a Digraph and u is a node, you can write:
|
ggab90@1130
|
269 |
///\code
|
ggab90@1130
|
270 |
/// for(auto a: g.outArcs(u))
|
ggab90@1130
|
271 |
/// doSomething(a);
|
ggab90@1130
|
272 |
///
|
ggab90@1130
|
273 |
/// //Using an STL algorithm:
|
ggab90@1130
|
274 |
/// copy(g.outArcs(u).begin(), g.outArcs(u).end(), vect.begin());
|
ggab90@1130
|
275 |
///\endcode
|
ggab90@1130
|
276 |
LemonRangeWrapper2<OutArcIt, Digraph, Node> outArcs(const Node& u) const {
|
ggab90@1130
|
277 |
return LemonRangeWrapper2<OutArcIt, Digraph, Node>(*this, u);
|
ggab90@1130
|
278 |
}
|
ggab90@1130
|
279 |
|
ggab90@1130
|
280 |
|
kpeter@734
|
281 |
/// Iterator class for the incoming arcs of a node.
|
deba@57
|
282 |
|
deba@57
|
283 |
/// This iterator goes trough the \e incoming arcs of a certain node
|
deba@57
|
284 |
/// of a digraph.
|
kpeter@786
|
285 |
/// Its usage is quite simple, for example, you can count the number
|
kpeter@734
|
286 |
/// of incoming arcs of a node \c n
|
kpeter@734
|
287 |
/// in a digraph \c g of type \c %Digraph as follows.
|
deba@57
|
288 |
///\code
|
deba@57
|
289 |
/// int count=0;
|
kpeter@734
|
290 |
/// for(Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
|
deba@57
|
291 |
///\endcode
|
deba@57
|
292 |
class InArcIt : public Arc {
|
deba@57
|
293 |
public:
|
deba@57
|
294 |
/// Default constructor
|
deba@57
|
295 |
|
kpeter@734
|
296 |
/// Default constructor.
|
kpeter@734
|
297 |
/// \warning It sets the iterator to an undefined value.
|
deba@57
|
298 |
InArcIt() { }
|
deba@57
|
299 |
/// Copy constructor.
|
deba@57
|
300 |
|
deba@57
|
301 |
/// Copy constructor.
|
deba@57
|
302 |
///
|
deba@57
|
303 |
InArcIt(const InArcIt& e) : Arc(e) { }
|
kpeter@734
|
304 |
/// %Invalid constructor \& conversion.
|
deba@57
|
305 |
|
kpeter@734
|
306 |
/// Initializes the iterator to be invalid.
|
kpeter@734
|
307 |
/// \sa Invalid for more details.
|
kpeter@734
|
308 |
InArcIt(Invalid) { }
|
kpeter@734
|
309 |
/// Sets the iterator to the first incoming arc.
|
kpeter@734
|
310 |
|
kpeter@734
|
311 |
/// Sets the iterator to the first incoming arc of the given node.
|
deba@57
|
312 |
///
|
kpeter@734
|
313 |
InArcIt(const Digraph&, const Node&) { }
|
kpeter@734
|
314 |
/// Sets the iterator to the given arc.
|
alpar@209
|
315 |
|
kpeter@734
|
316 |
/// Sets the iterator to the given arc of the given digraph.
|
kpeter@734
|
317 |
///
|
deba@57
|
318 |
InArcIt(const Digraph&, const Arc&) { }
|
deba@57
|
319 |
/// Next incoming arc
|
deba@57
|
320 |
|
kpeter@734
|
321 |
/// Assign the iterator to the next
|
kpeter@734
|
322 |
/// incoming arc of the corresponding node.
|
deba@57
|
323 |
InArcIt& operator++() { return *this; }
|
deba@57
|
324 |
};
|
deba@57
|
325 |
|
ggab90@1130
|
326 |
/// \brief Gets the collection of the incoming arcs of a certain node
|
ggab90@1130
|
327 |
/// of the digraph.
|
ggab90@1130
|
328 |
///
|
ggab90@1130
|
329 |
/// This function can be used for iterating on the
|
ggab90@1130
|
330 |
/// incoming arcs of a certain node of the digraph. It returns a wrapped
|
ggab90@1130
|
331 |
/// InArcIt, which looks like an STL container
|
ggab90@1130
|
332 |
/// (by having begin() and end()) which you can use in range-based
|
ggab90@1130
|
333 |
/// for loops, STL algorithms, etc.
|
ggab90@1130
|
334 |
/// For example if g is a Digraph and u is a node, you can write:
|
ggab90@1130
|
335 |
///\code
|
ggab90@1130
|
336 |
/// for(auto a: g.inArcs(u))
|
ggab90@1130
|
337 |
/// doSomething(a);
|
ggab90@1130
|
338 |
///
|
ggab90@1130
|
339 |
/// //Using an STL algorithm:
|
ggab90@1130
|
340 |
/// copy(g.inArcs(u).begin(), g.inArcs(u).end(), vect.begin());
|
ggab90@1130
|
341 |
///\endcode
|
ggab90@1130
|
342 |
LemonRangeWrapper2<InArcIt, Digraph, Node> inArcs(const Node& u) const {
|
ggab90@1130
|
343 |
return LemonRangeWrapper2<InArcIt, Digraph, Node>(*this, u);
|
ggab90@1130
|
344 |
}
|
ggab90@1130
|
345 |
|
ggab90@1130
|
346 |
|
kpeter@734
|
347 |
/// Iterator class for the arcs.
|
kpeter@734
|
348 |
|
kpeter@734
|
349 |
/// This iterator goes through each arc of the digraph.
|
kpeter@786
|
350 |
/// Its usage is quite simple, for example, you can count the number
|
kpeter@734
|
351 |
/// of arcs in a digraph \c g of type \c %Digraph as follows:
|
deba@57
|
352 |
///\code
|
deba@57
|
353 |
/// int count=0;
|
kpeter@734
|
354 |
/// for(Digraph::ArcIt a(g); a!=INVALID; ++a) ++count;
|
deba@57
|
355 |
///\endcode
|
deba@57
|
356 |
class ArcIt : public Arc {
|
deba@57
|
357 |
public:
|
deba@57
|
358 |
/// Default constructor
|
deba@57
|
359 |
|
kpeter@734
|
360 |
/// Default constructor.
|
kpeter@734
|
361 |
/// \warning It sets the iterator to an undefined value.
|
deba@57
|
362 |
ArcIt() { }
|
deba@57
|
363 |
/// Copy constructor.
|
deba@57
|
364 |
|
deba@57
|
365 |
/// Copy constructor.
|
deba@57
|
366 |
///
|
deba@57
|
367 |
ArcIt(const ArcIt& e) : Arc(e) { }
|
kpeter@734
|
368 |
/// %Invalid constructor \& conversion.
|
deba@57
|
369 |
|
kpeter@734
|
370 |
/// Initializes the iterator to be invalid.
|
kpeter@734
|
371 |
/// \sa Invalid for more details.
|
kpeter@734
|
372 |
ArcIt(Invalid) { }
|
kpeter@734
|
373 |
/// Sets the iterator to the first arc.
|
kpeter@734
|
374 |
|
kpeter@734
|
375 |
/// Sets the iterator to the first arc of the given digraph.
|
deba@57
|
376 |
///
|
alpar@1093
|
377 |
explicit ArcIt(const Digraph& g) {
|
alpar@1093
|
378 |
::lemon::ignore_unused_variable_warning(g);
|
alpar@1093
|
379 |
}
|
kpeter@734
|
380 |
/// Sets the iterator to the given arc.
|
alpar@209
|
381 |
|
kpeter@734
|
382 |
/// Sets the iterator to the given arc of the given digraph.
|
kpeter@734
|
383 |
///
|
alpar@209
|
384 |
ArcIt(const Digraph&, const Arc&) { }
|
kpeter@734
|
385 |
/// Next arc
|
alpar@209
|
386 |
|
deba@57
|
387 |
/// Assign the iterator to the next arc.
|
kpeter@734
|
388 |
///
|
deba@57
|
389 |
ArcIt& operator++() { return *this; }
|
deba@57
|
390 |
};
|
deba@57
|
391 |
|
ggab90@1130
|
392 |
/// \brief Gets the collection of the arcs of the digraph.
|
ggab90@1130
|
393 |
///
|
ggab90@1130
|
394 |
/// This function can be used for iterating on the
|
ggab90@1130
|
395 |
/// arcs of the digraph. It returns a wrapped
|
ggab90@1130
|
396 |
/// ArcIt, which looks like an STL container
|
ggab90@1130
|
397 |
/// (by having begin() and end()) which you can use in range-based
|
ggab90@1130
|
398 |
/// for loops, STL algorithms, etc.
|
ggab90@1130
|
399 |
/// For example you can write:
|
ggab90@1130
|
400 |
///\code
|
ggab90@1130
|
401 |
/// ListDigraph g;
|
ggab90@1130
|
402 |
/// for(auto a: g.arcs())
|
ggab90@1130
|
403 |
/// doSomething(a);
|
ggab90@1130
|
404 |
///
|
ggab90@1130
|
405 |
/// //Using an STL algorithm:
|
ggab90@1130
|
406 |
/// copy(g.arcs().begin(), g.arcs().end(), vect.begin());
|
ggab90@1130
|
407 |
///\endcode
|
ggab90@1130
|
408 |
LemonRangeWrapper1<ArcIt, Digraph> arcs() const {
|
ggab90@1130
|
409 |
return LemonRangeWrapper1<ArcIt, Digraph>(*this);
|
ggab90@1130
|
410 |
}
|
ggab90@1130
|
411 |
|
ggab90@1130
|
412 |
|
kpeter@734
|
413 |
/// \brief The source node of the arc.
|
deba@57
|
414 |
///
|
kpeter@734
|
415 |
/// Returns the source node of the given arc.
|
deba@57
|
416 |
Node source(Arc) const { return INVALID; }
|
deba@57
|
417 |
|
kpeter@734
|
418 |
/// \brief The target node of the arc.
|
kpeter@734
|
419 |
///
|
kpeter@734
|
420 |
/// Returns the target node of the given arc.
|
kpeter@734
|
421 |
Node target(Arc) const { return INVALID; }
|
kpeter@734
|
422 |
|
kpeter@734
|
423 |
/// \brief The ID of the node.
|
kpeter@734
|
424 |
///
|
kpeter@734
|
425 |
/// Returns the ID of the given node.
|
alpar@209
|
426 |
int id(Node) const { return -1; }
|
deba@61
|
427 |
|
kpeter@734
|
428 |
/// \brief The ID of the arc.
|
kpeter@734
|
429 |
///
|
kpeter@734
|
430 |
/// Returns the ID of the given arc.
|
alpar@209
|
431 |
int id(Arc) const { return -1; }
|
deba@61
|
432 |
|
kpeter@734
|
433 |
/// \brief The node with the given ID.
|
deba@61
|
434 |
///
|
kpeter@734
|
435 |
/// Returns the node with the given ID.
|
kpeter@734
|
436 |
/// \pre The argument should be a valid node ID in the digraph.
|
alpar@209
|
437 |
Node nodeFromId(int) const { return INVALID; }
|
deba@61
|
438 |
|
kpeter@734
|
439 |
/// \brief The arc with the given ID.
|
deba@61
|
440 |
///
|
kpeter@734
|
441 |
/// Returns the arc with the given ID.
|
kpeter@734
|
442 |
/// \pre The argument should be a valid arc ID in the digraph.
|
alpar@209
|
443 |
Arc arcFromId(int) const { return INVALID; }
|
deba@61
|
444 |
|
kpeter@734
|
445 |
/// \brief An upper bound on the node IDs.
|
kpeter@734
|
446 |
///
|
kpeter@734
|
447 |
/// Returns an upper bound on the node IDs.
|
alpar@209
|
448 |
int maxNodeId() const { return -1; }
|
deba@61
|
449 |
|
kpeter@734
|
450 |
/// \brief An upper bound on the arc IDs.
|
kpeter@734
|
451 |
///
|
kpeter@734
|
452 |
/// Returns an upper bound on the arc IDs.
|
alpar@209
|
453 |
int maxArcId() const { return -1; }
|
deba@61
|
454 |
|
deba@57
|
455 |
void first(Node&) const {}
|
deba@57
|
456 |
void next(Node&) const {}
|
deba@57
|
457 |
|
deba@57
|
458 |
void first(Arc&) const {}
|
deba@57
|
459 |
void next(Arc&) const {}
|
deba@57
|
460 |
|
deba@57
|
461 |
|
deba@57
|
462 |
void firstIn(Arc&, const Node&) const {}
|
deba@57
|
463 |
void nextIn(Arc&) const {}
|
deba@57
|
464 |
|
deba@57
|
465 |
void firstOut(Arc&, const Node&) const {}
|
deba@57
|
466 |
void nextOut(Arc&) const {}
|
deba@57
|
467 |
|
deba@61
|
468 |
// The second parameter is dummy.
|
deba@61
|
469 |
Node fromId(int, Node) const { return INVALID; }
|
deba@61
|
470 |
// The second parameter is dummy.
|
deba@61
|
471 |
Arc fromId(int, Arc) const { return INVALID; }
|
deba@61
|
472 |
|
deba@61
|
473 |
// Dummy parameter.
|
alpar@209
|
474 |
int maxId(Node) const { return -1; }
|
deba@61
|
475 |
// Dummy parameter.
|
alpar@209
|
476 |
int maxId(Arc) const { return -1; }
|
deba@61
|
477 |
|
kpeter@734
|
478 |
/// \brief The opposite node on the arc.
|
kpeter@734
|
479 |
///
|
kpeter@734
|
480 |
/// Returns the opposite node on the given arc.
|
kpeter@734
|
481 |
Node oppositeNode(Node, Arc) const { return INVALID; }
|
kpeter@734
|
482 |
|
deba@57
|
483 |
/// \brief The base node of the iterator.
|
deba@57
|
484 |
///
|
kpeter@734
|
485 |
/// Returns the base node of the given outgoing arc iterator
|
kpeter@734
|
486 |
/// (i.e. the source node of the corresponding arc).
|
kpeter@734
|
487 |
Node baseNode(OutArcIt) const { return INVALID; }
|
deba@57
|
488 |
|
deba@57
|
489 |
/// \brief The running node of the iterator.
|
deba@57
|
490 |
///
|
kpeter@734
|
491 |
/// Returns the running node of the given outgoing arc iterator
|
kpeter@734
|
492 |
/// (i.e. the target node of the corresponding arc).
|
kpeter@734
|
493 |
Node runningNode(OutArcIt) const { return INVALID; }
|
deba@57
|
494 |
|
deba@57
|
495 |
/// \brief The base node of the iterator.
|
deba@57
|
496 |
///
|
kpeter@1049
|
497 |
/// Returns the base node of the given incoming arc iterator
|
kpeter@734
|
498 |
/// (i.e. the target node of the corresponding arc).
|
kpeter@734
|
499 |
Node baseNode(InArcIt) const { return INVALID; }
|
deba@57
|
500 |
|
deba@57
|
501 |
/// \brief The running node of the iterator.
|
deba@57
|
502 |
///
|
kpeter@1049
|
503 |
/// Returns the running node of the given incoming arc iterator
|
kpeter@734
|
504 |
/// (i.e. the source node of the corresponding arc).
|
kpeter@734
|
505 |
Node runningNode(InArcIt) const { return INVALID; }
|
deba@57
|
506 |
|
kpeter@734
|
507 |
/// \brief Standard graph map type for the nodes.
|
deba@57
|
508 |
///
|
kpeter@734
|
509 |
/// Standard graph map type for the nodes.
|
kpeter@734
|
510 |
/// It conforms to the ReferenceMap concept.
|
alpar@209
|
511 |
template<class T>
|
kpeter@580
|
512 |
class NodeMap : public ReferenceMap<Node, T, T&, const T&> {
|
deba@57
|
513 |
public:
|
deba@57
|
514 |
|
kpeter@734
|
515 |
/// Constructor
|
kpeter@734
|
516 |
explicit NodeMap(const Digraph&) { }
|
kpeter@734
|
517 |
/// Constructor with given initial value
|
deba@57
|
518 |
NodeMap(const Digraph&, T) { }
|
deba@57
|
519 |
|
kpeter@263
|
520 |
private:
|
deba@57
|
521 |
///Copy constructor
|
alpar@877
|
522 |
NodeMap(const NodeMap& nm) :
|
kpeter@580
|
523 |
ReferenceMap<Node, T, T&, const T&>(nm) { }
|
deba@57
|
524 |
///Assignment operator
|
deba@57
|
525 |
template <typename CMap>
|
alpar@209
|
526 |
NodeMap& operator=(const CMap&) {
|
deba@57
|
527 |
checkConcept<ReadMap<Node, T>, CMap>();
|
alpar@209
|
528 |
return *this;
|
deba@57
|
529 |
}
|
deba@57
|
530 |
};
|
deba@57
|
531 |
|
kpeter@734
|
532 |
/// \brief Standard graph map type for the arcs.
|
deba@57
|
533 |
///
|
kpeter@734
|
534 |
/// Standard graph map type for the arcs.
|
kpeter@734
|
535 |
/// It conforms to the ReferenceMap concept.
|
alpar@209
|
536 |
template<class T>
|
kpeter@580
|
537 |
class ArcMap : public ReferenceMap<Arc, T, T&, const T&> {
|
deba@57
|
538 |
public:
|
deba@57
|
539 |
|
kpeter@734
|
540 |
/// Constructor
|
kpeter@734
|
541 |
explicit ArcMap(const Digraph&) { }
|
kpeter@734
|
542 |
/// Constructor with given initial value
|
deba@57
|
543 |
ArcMap(const Digraph&, T) { }
|
kpeter@734
|
544 |
|
kpeter@263
|
545 |
private:
|
deba@57
|
546 |
///Copy constructor
|
kpeter@580
|
547 |
ArcMap(const ArcMap& em) :
|
kpeter@580
|
548 |
ReferenceMap<Arc, T, T&, const T&>(em) { }
|
deba@57
|
549 |
///Assignment operator
|
deba@57
|
550 |
template <typename CMap>
|
alpar@209
|
551 |
ArcMap& operator=(const CMap&) {
|
deba@57
|
552 |
checkConcept<ReadMap<Arc, T>, CMap>();
|
alpar@209
|
553 |
return *this;
|
deba@57
|
554 |
}
|
deba@57
|
555 |
};
|
deba@57
|
556 |
|
deba@125
|
557 |
template <typename _Digraph>
|
deba@57
|
558 |
struct Constraints {
|
deba@57
|
559 |
void constraints() {
|
kpeter@580
|
560 |
checkConcept<BaseDigraphComponent, _Digraph>();
|
deba@125
|
561 |
checkConcept<IterableDigraphComponent<>, _Digraph>();
|
alpar@209
|
562 |
checkConcept<IDableDigraphComponent<>, _Digraph>();
|
deba@125
|
563 |
checkConcept<MappableDigraphComponent<>, _Digraph>();
|
deba@57
|
564 |
}
|
deba@57
|
565 |
};
|
deba@57
|
566 |
|
deba@57
|
567 |
};
|
alpar@209
|
568 |
|
alpar@209
|
569 |
} //namespace concepts
|
deba@57
|
570 |
} //namespace lemon
|
deba@57
|
571 |
|
deba@57
|
572 |
|
deba@57
|
573 |
|
deba@529
|
574 |
#endif
|