Location: LEMON/LEMON-main/lemon/concepts/digraph.h

Load file history
gravatar
kpeter (Peter Kovacs)
Standard graph maps are required to be reference maps (#190)
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/* -*- mode: C++; indent-tabs-mode: nil; -*-
*
* This file is a part of LEMON, a generic C++ optimization library.
*
* Copyright (C) 2003-2009
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
*
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
*
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
* purpose.
*
*/
#ifndef LEMON_CONCEPTS_DIGRAPH_H
#define LEMON_CONCEPTS_DIGRAPH_H
///\ingroup graph_concepts
///\file
///\brief The concept of directed graphs.
#include <lemon/core.h>
#include <lemon/concepts/maps.h>
#include <lemon/concept_check.h>
#include <lemon/concepts/graph_components.h>
namespace lemon {
namespace concepts {
/// \ingroup graph_concepts
///
/// \brief Class describing the concept of directed graphs.
///
/// This class describes the \ref concept "concept" of the
/// immutable directed digraphs.
///
/// Note that actual digraph implementation like @ref ListDigraph or
/// @ref SmartDigraph may have several additional functionality.
///
/// \sa concept
class Digraph {
private:
///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
///
Digraph(const Digraph &) {};
///\brief Assignment of \ref Digraph "Digraph"s to another ones are
///\e not allowed. Use DigraphCopy() instead.
///Assignment of \ref Digraph "Digraph"s to another ones are
///\e not allowed. Use DigraphCopy() instead.
void operator=(const Digraph &) {}
public:
///\e
/// Defalult constructor.
/// Defalult constructor.
///
Digraph() { }
/// Class for identifying a node of the digraph
/// This class identifies a node of the digraph. It also serves
/// as a base class of the node iterators,
/// thus they will convert to this type.
class Node {
public:
/// Default constructor
/// @warning The default constructor sets the iterator
/// to an undefined value.
Node() { }
/// Copy constructor.
/// Copy constructor.
///
Node(const Node&) { }
/// Invalid constructor \& conversion.
/// This constructor initializes the iterator to be invalid.
/// \sa Invalid for more details.
Node(Invalid) { }
/// Equality operator
/// Two iterators are equal if and only if they point to the
/// same object or both are invalid.
bool operator==(Node) const { return true; }
/// Inequality operator
/// \sa operator==(Node n)
///
bool operator!=(Node) const { return true; }
/// Artificial ordering operator.
/// To allow the use of digraph descriptors as key type in std::map or
/// similar associative container we require this.
///
/// \note This operator only have to define some strict ordering of
/// the items; this order has nothing to do with the iteration
/// ordering of the items.
bool operator<(Node) const { return false; }
};
/// This iterator goes through each node.
/// This iterator goes through each node.
/// Its usage is quite simple, for example you can count the number
/// of nodes in digraph \c g of type \c Digraph like this:
///\code
/// int count=0;
/// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count;
///\endcode
class NodeIt : public Node {
public:
/// Default constructor
/// @warning The default constructor sets the iterator
/// to an undefined value.
NodeIt() { }
/// Copy constructor.
/// Copy constructor.
///
NodeIt(const NodeIt& n) : Node(n) { }
/// Invalid constructor \& conversion.
/// Initialize the iterator to be invalid.
/// \sa Invalid for more details.
NodeIt(Invalid) { }
/// Sets the iterator to the first node.
/// Sets the iterator to the first node of \c g.
///
NodeIt(const Digraph&) { }
/// Node -> NodeIt conversion.
/// Sets the iterator to the node of \c the digraph pointed by
/// the trivial iterator.
/// This feature necessitates that each time we
/// iterate the arc-set, the iteration order is the same.
NodeIt(const Digraph&, const Node&) { }
/// Next node.
/// Assign the iterator to the next node.
///
NodeIt& operator++() { return *this; }
};
/// Class for identifying an arc of the digraph
/// This class identifies an arc of the digraph. It also serves
/// as a base class of the arc iterators,
/// thus they will convert to this type.
class Arc {
public:
/// Default constructor
/// @warning The default constructor sets the iterator
/// to an undefined value.
Arc() { }
/// Copy constructor.
/// Copy constructor.
///
Arc(const Arc&) { }
/// Initialize the iterator to be invalid.
/// Initialize the iterator to be invalid.
///
Arc(Invalid) { }
/// Equality operator
/// Two iterators are equal if and only if they point to the
/// same object or both are invalid.
bool operator==(Arc) const { return true; }
/// Inequality operator
/// \sa operator==(Arc n)
///
bool operator!=(Arc) const { return true; }
/// Artificial ordering operator.
/// To allow the use of digraph descriptors as key type in std::map or
/// similar associative container we require this.
///
/// \note This operator only have to define some strict ordering of
/// the items; this order has nothing to do with the iteration
/// ordering of the items.
bool operator<(Arc) const { return false; }
};
/// This iterator goes trough the outgoing arcs of a node.
/// This iterator goes trough the \e outgoing arcs of a certain node
/// of a digraph.
/// Its usage is quite simple, for example you can count the number
/// of outgoing arcs of a node \c n
/// in digraph \c g of type \c Digraph as follows.
///\code
/// int count=0;
/// for (Digraph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
///\endcode
class OutArcIt : public Arc {
public:
/// Default constructor
/// @warning The default constructor sets the iterator
/// to an undefined value.
OutArcIt() { }
/// Copy constructor.
/// Copy constructor.
///
OutArcIt(const OutArcIt& e) : Arc(e) { }
/// Initialize the iterator to be invalid.
/// Initialize the iterator to be invalid.
///
OutArcIt(Invalid) { }
/// This constructor sets the iterator to the first outgoing arc.
/// This constructor sets the iterator to the first outgoing arc of
/// the node.
OutArcIt(const Digraph&, const Node&) { }
/// Arc -> OutArcIt conversion
/// Sets the iterator to the value of the trivial iterator.
/// This feature necessitates that each time we
/// iterate the arc-set, the iteration order is the same.
OutArcIt(const Digraph&, const Arc&) { }
///Next outgoing arc
/// Assign the iterator to the next
/// outgoing arc of the corresponding node.
OutArcIt& operator++() { return *this; }
};
/// This iterator goes trough the incoming arcs of a node.
/// This iterator goes trough the \e incoming arcs of a certain node
/// of a digraph.
/// Its usage is quite simple, for example you can count the number
/// of outgoing arcs of a node \c n
/// in digraph \c g of type \c Digraph as follows.
///\code
/// int count=0;
/// for(Digraph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
///\endcode
class InArcIt : public Arc {
public:
/// Default constructor
/// @warning The default constructor sets the iterator
/// to an undefined value.
InArcIt() { }
/// Copy constructor.
/// Copy constructor.
///
InArcIt(const InArcIt& e) : Arc(e) { }
/// Initialize the iterator to be invalid.
/// Initialize the iterator to be invalid.
///
InArcIt(Invalid) { }
/// This constructor sets the iterator to first incoming arc.
/// This constructor set the iterator to the first incoming arc of
/// the node.
InArcIt(const Digraph&, const Node&) { }
/// Arc -> InArcIt conversion
/// Sets the iterator to the value of the trivial iterator \c e.
/// This feature necessitates that each time we
/// iterate the arc-set, the iteration order is the same.
InArcIt(const Digraph&, const Arc&) { }
/// Next incoming arc
/// Assign the iterator to the next inarc of the corresponding node.
///
InArcIt& operator++() { return *this; }
};
/// This iterator goes through each arc.
/// This iterator goes through each arc of a digraph.
/// Its usage is quite simple, for example you can count the number
/// of arcs in a digraph \c g of type \c Digraph as follows:
///\code
/// int count=0;
/// for(Digraph::ArcIt e(g); e!=INVALID; ++e) ++count;
///\endcode
class ArcIt : public Arc {
public:
/// Default constructor
/// @warning The default constructor sets the iterator
/// to an undefined value.
ArcIt() { }
/// Copy constructor.
/// Copy constructor.
///
ArcIt(const ArcIt& e) : Arc(e) { }
/// Initialize the iterator to be invalid.
/// Initialize the iterator to be invalid.
///
ArcIt(Invalid) { }
/// This constructor sets the iterator to the first arc.
/// This constructor sets the iterator to the first arc of \c g.
///@param g the digraph
ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
/// Arc -> ArcIt conversion
/// Sets the iterator to the value of the trivial iterator \c e.
/// This feature necessitates that each time we
/// iterate the arc-set, the iteration order is the same.
ArcIt(const Digraph&, const Arc&) { }
///Next arc
/// Assign the iterator to the next arc.
ArcIt& operator++() { return *this; }
};
///Gives back the target node of an arc.
///Gives back the target node of an arc.
///
Node target(Arc) const { return INVALID; }
///Gives back the source node of an arc.
///Gives back the source node of an arc.
///
Node source(Arc) const { return INVALID; }
/// \brief Returns the ID of the node.
int id(Node) const { return -1; }
/// \brief Returns the ID of the arc.
int id(Arc) const { return -1; }
/// \brief Returns the node with the given ID.
///
/// \pre The argument should be a valid node ID in the graph.
Node nodeFromId(int) const { return INVALID; }
/// \brief Returns the arc with the given ID.
///
/// \pre The argument should be a valid arc ID in the graph.
Arc arcFromId(int) const { return INVALID; }
/// \brief Returns an upper bound on the node IDs.
int maxNodeId() const { return -1; }
/// \brief Returns an upper bound on the arc IDs.
int maxArcId() const { return -1; }
void first(Node&) const {}
void next(Node&) const {}
void first(Arc&) const {}
void next(Arc&) const {}
void firstIn(Arc&, const Node&) const {}
void nextIn(Arc&) const {}
void firstOut(Arc&, const Node&) const {}
void nextOut(Arc&) const {}
// The second parameter is dummy.
Node fromId(int, Node) const { return INVALID; }
// The second parameter is dummy.
Arc fromId(int, Arc) const { return INVALID; }
// Dummy parameter.
int maxId(Node) const { return -1; }
// Dummy parameter.
int maxId(Arc) const { return -1; }
/// \brief The base node of the iterator.
///
/// Gives back the base node of the iterator.
/// It is always the target of the pointed arc.
Node baseNode(const InArcIt&) const { return INVALID; }
/// \brief The running node of the iterator.
///
/// Gives back the running node of the iterator.
/// It is always the source of the pointed arc.
Node runningNode(const InArcIt&) const { return INVALID; }
/// \brief The base node of the iterator.
///
/// Gives back the base node of the iterator.
/// It is always the source of the pointed arc.
Node baseNode(const OutArcIt&) const { return INVALID; }
/// \brief The running node of the iterator.
///
/// Gives back the running node of the iterator.
/// It is always the target of the pointed arc.
Node runningNode(const OutArcIt&) const { return INVALID; }
/// \brief The opposite node on the given arc.
///
/// Gives back the opposite node on the given arc.
Node oppositeNode(const Node&, const Arc&) const { return INVALID; }
/// \brief Reference map of the nodes to type \c T.
///
/// Reference map of the nodes to type \c T.
template<class T>
class NodeMap : public ReferenceMap<Node, T, T&, const T&> {
public:
///\e
NodeMap(const Digraph&) { }
///\e
NodeMap(const Digraph&, T) { }
private:
///Copy constructor
NodeMap(const NodeMap& nm) :
ReferenceMap<Node, T, T&, const T&>(nm) { }
///Assignment operator
template <typename CMap>
NodeMap& operator=(const CMap&) {
checkConcept<ReadMap<Node, T>, CMap>();
return *this;
}
};
/// \brief Reference map of the arcs to type \c T.
///
/// Reference map of the arcs to type \c T.
template<class T>
class ArcMap : public ReferenceMap<Arc, T, T&, const T&> {
public:
///\e
ArcMap(const Digraph&) { }
///\e
ArcMap(const Digraph&, T) { }
private:
///Copy constructor
ArcMap(const ArcMap& em) :
ReferenceMap<Arc, T, T&, const T&>(em) { }
///Assignment operator
template <typename CMap>
ArcMap& operator=(const CMap&) {
checkConcept<ReadMap<Arc, T>, CMap>();
return *this;
}
};
template <typename _Digraph>
struct Constraints {
void constraints() {
checkConcept<BaseDigraphComponent, _Digraph>();
checkConcept<IterableDigraphComponent<>, _Digraph>();
checkConcept<IDableDigraphComponent<>, _Digraph>();
checkConcept<MappableDigraphComponent<>, _Digraph>();
}
};
};
} //namespace concepts
} //namespace lemon
#endif