lemon/concepts/graph.h
author Peter Kovacs <kpeter@inf.elte.hu>
Sun, 24 May 2015 17:30:50 +0200
changeset 1153 233ad6942a26
parent 1093 fb1c7da561ce
child 1210 da87dbdf3daf
permissions -rw-r--r--
Minor fixes in bibtex entry + unify formatting (#597)
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@57
    19
///\ingroup graph_concepts
deba@57
    20
///\file
kpeter@734
    21
///\brief The concept of undirected graphs.
deba@57
    22
deba@529
    23
#ifndef LEMON_CONCEPTS_GRAPH_H
deba@529
    24
#define LEMON_CONCEPTS_GRAPH_H
deba@57
    25
deba@57
    26
#include <lemon/concepts/graph_components.h>
kpeter@734
    27
#include <lemon/concepts/maps.h>
kpeter@734
    28
#include <lemon/concept_check.h>
deba@220
    29
#include <lemon/core.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
    ///
kpeter@734
    37
    /// \brief Class describing the concept of undirected graphs.
deba@57
    38
    ///
kpeter@734
    39
    /// This class describes the common interface of all undirected
kpeter@734
    40
    /// graphs.
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
    /// undirected graphs should compile with this class, but it will not
deba@57
    45
    /// run properly, of course.
kpeter@734
    46
    /// An actual graph implementation like \ref ListGraph or
alpar@877
    47
    /// \ref SmartGraph may have additional functionality.
deba@57
    48
    ///
kpeter@734
    49
    /// The undirected graphs also fulfill the concept of \ref Digraph
kpeter@734
    50
    /// "directed graphs", since each edge can also be regarded as two
kpeter@734
    51
    /// oppositely directed arcs.
kpeter@734
    52
    /// Undirected graphs provide an Edge type for the undirected edges and
kpeter@734
    53
    /// an Arc type for the directed arcs. The Arc type is convertible to
kpeter@734
    54
    /// Edge or inherited from it, i.e. the corresponding edge can be
kpeter@734
    55
    /// obtained from an arc.
kpeter@734
    56
    /// EdgeIt and EdgeMap classes can be used for the edges, while ArcIt
kpeter@734
    57
    /// and ArcMap classes can be used for the arcs (just like in digraphs).
kpeter@734
    58
    /// Both InArcIt and OutArcIt iterates on the same edges but with
kpeter@734
    59
    /// opposite direction. IncEdgeIt also iterates on the same edges
kpeter@734
    60
    /// as OutArcIt and InArcIt, but it is not convertible to Arc,
kpeter@734
    61
    /// only to Edge.
deba@57
    62
    ///
kpeter@734
    63
    /// In LEMON, each undirected edge has an inherent orientation.
kpeter@734
    64
    /// Thus it can defined if an arc is forward or backward oriented in
kpeter@734
    65
    /// an undirected graph with respect to this default oriantation of
kpeter@734
    66
    /// the represented edge.
kpeter@734
    67
    /// With the direction() and direct() functions the direction
kpeter@734
    68
    /// of an arc can be obtained and set, respectively.
deba@57
    69
    ///
kpeter@734
    70
    /// Only nodes and edges can be added to or removed from an undirected
kpeter@734
    71
    /// graph and the corresponding arcs are added or removed automatically.
kpeter@734
    72
    ///
kpeter@734
    73
    /// \sa Digraph
deba@57
    74
    class Graph {
kpeter@734
    75
    private:
deba@1018
    76
      /// Graphs are \e not copy constructible. Use GraphCopy instead.
kpeter@734
    77
      Graph(const Graph&) {}
kpeter@734
    78
      /// \brief Assignment of a graph to another one is \e not allowed.
deba@1018
    79
      /// Use GraphCopy instead.
kpeter@734
    80
      void operator=(const Graph&) {}
kpeter@734
    81
deba@57
    82
    public:
kpeter@734
    83
      /// Default constructor.
kpeter@734
    84
      Graph() {}
kpeter@734
    85
kpeter@734
    86
      /// \brief Undirected graphs should be tagged with \c UndirectedTag.
deba@57
    87
      ///
kpeter@734
    88
      /// Undirected graphs should be tagged with \c UndirectedTag.
alpar@877
    89
      ///
kpeter@734
    90
      /// This tag helps the \c enable_if technics to make compile time
alpar@209
    91
      /// specializations for undirected graphs.
deba@57
    92
      typedef True UndirectedTag;
deba@57
    93
kpeter@734
    94
      /// The node type of the graph
kpeter@734
    95
kpeter@734
    96
      /// This class identifies a node of the graph. It also serves
kpeter@734
    97
      /// as a base class of the node iterators,
kpeter@734
    98
      /// thus they convert to this type.
deba@57
    99
      class Node {
deba@57
   100
      public:
deba@57
   101
        /// Default constructor
deba@57
   102
kpeter@734
   103
        /// Default constructor.
kpeter@734
   104
        /// \warning It sets the object to an undefined value.
deba@57
   105
        Node() { }
deba@57
   106
        /// Copy constructor.
deba@57
   107
deba@57
   108
        /// Copy constructor.
deba@57
   109
        ///
deba@57
   110
        Node(const Node&) { }
deba@57
   111
kpeter@734
   112
        /// %Invalid constructor \& conversion.
deba@57
   113
kpeter@734
   114
        /// Initializes the object to be invalid.
deba@57
   115
        /// \sa Invalid for more details.
deba@57
   116
        Node(Invalid) { }
deba@57
   117
        /// Equality operator
deba@57
   118
kpeter@734
   119
        /// Equality operator.
kpeter@734
   120
        ///
deba@57
   121
        /// Two iterators are equal if and only if they point to the
kpeter@734
   122
        /// same object or both are \c INVALID.
deba@57
   123
        bool operator==(Node) const { return true; }
deba@57
   124
deba@57
   125
        /// Inequality operator
alpar@209
   126
kpeter@734
   127
        /// Inequality operator.
deba@57
   128
        bool operator!=(Node) const { return true; }
deba@57
   129
alpar@209
   130
        /// Artificial ordering operator.
alpar@209
   131
kpeter@734
   132
        /// Artificial ordering operator.
alpar@209
   133
        ///
kpeter@734
   134
        /// \note This operator only has to define some strict ordering of
alpar@209
   135
        /// the items; this order has nothing to do with the iteration
alpar@209
   136
        /// ordering of the items.
alpar@209
   137
        bool operator<(Node) const { return false; }
deba@57
   138
deba@57
   139
      };
alpar@209
   140
kpeter@734
   141
      /// Iterator class for the nodes.
deba@57
   142
kpeter@734
   143
      /// This iterator goes through each node of the graph.
kpeter@786
   144
      /// Its usage is quite simple, for example, you can count the number
kpeter@734
   145
      /// of nodes in a graph \c g of type \c %Graph like this:
deba@57
   146
      ///\code
deba@57
   147
      /// int count=0;
deba@57
   148
      /// for (Graph::NodeIt n(g); n!=INVALID; ++n) ++count;
deba@57
   149
      ///\endcode
deba@57
   150
      class NodeIt : public Node {
deba@57
   151
      public:
deba@57
   152
        /// Default constructor
deba@57
   153
kpeter@734
   154
        /// Default constructor.
kpeter@734
   155
        /// \warning It sets the iterator to an undefined value.
deba@57
   156
        NodeIt() { }
deba@57
   157
        /// Copy constructor.
alpar@209
   158
deba@57
   159
        /// Copy constructor.
deba@57
   160
        ///
deba@57
   161
        NodeIt(const NodeIt& n) : Node(n) { }
kpeter@734
   162
        /// %Invalid constructor \& conversion.
deba@57
   163
kpeter@734
   164
        /// Initializes the iterator to be invalid.
deba@57
   165
        /// \sa Invalid for more details.
deba@57
   166
        NodeIt(Invalid) { }
deba@57
   167
        /// Sets the iterator to the first node.
deba@57
   168
kpeter@734
   169
        /// Sets the iterator to the first node of the given digraph.
deba@57
   170
        ///
kpeter@734
   171
        explicit NodeIt(const Graph&) { }
kpeter@734
   172
        /// Sets the iterator to the given node.
deba@57
   173
kpeter@734
   174
        /// Sets the iterator to the given node of the given digraph.
kpeter@734
   175
        ///
deba@57
   176
        NodeIt(const Graph&, const Node&) { }
deba@57
   177
        /// Next node.
deba@57
   178
deba@57
   179
        /// Assign the iterator to the next node.
deba@57
   180
        ///
deba@57
   181
        NodeIt& operator++() { return *this; }
deba@57
   182
      };
alpar@209
   183
ggab90@1130
   184
      /// \brief Gets the collection of the nodes of the graph.
ggab90@1130
   185
      ///
ggab90@1130
   186
      /// This function can be used for iterating on
ggab90@1130
   187
      /// the nodes of the graph. It returns a wrapped NodeIt, which looks
ggab90@1130
   188
      /// like an STL container (by having begin() and end())
ggab90@1130
   189
      /// which you can use in range-based for loops, STL algorithms, etc.
ggab90@1130
   190
      /// For example you can write:
ggab90@1130
   191
      ///\code
ggab90@1130
   192
      /// ListGraph g;
ggab90@1130
   193
      /// for(auto v: g.nodes())
ggab90@1130
   194
      ///   doSomething(v);
ggab90@1130
   195
      ///
ggab90@1130
   196
      /// //Using an STL algorithm:
ggab90@1130
   197
      /// copy(g.nodes().begin(), g.nodes().end(), vect.begin());
ggab90@1130
   198
      ///\endcode
ggab90@1130
   199
      LemonRangeWrapper1<NodeIt, Graph> nodes() const {
ggab90@1130
   200
        return LemonRangeWrapper1<NodeIt, Graph>(*this);
ggab90@1130
   201
      }
ggab90@1130
   202
alpar@209
   203
kpeter@734
   204
      /// The edge type of the graph
deba@57
   205
kpeter@734
   206
      /// This class identifies an edge of the graph. It also serves
kpeter@734
   207
      /// as a base class of the edge iterators,
kpeter@734
   208
      /// thus they will convert to this type.
deba@57
   209
      class Edge {
deba@57
   210
      public:
deba@57
   211
        /// Default constructor
deba@57
   212
kpeter@734
   213
        /// Default constructor.
kpeter@734
   214
        /// \warning It sets the object to an undefined value.
deba@57
   215
        Edge() { }
deba@57
   216
        /// Copy constructor.
deba@57
   217
deba@57
   218
        /// Copy constructor.
deba@57
   219
        ///
deba@57
   220
        Edge(const Edge&) { }
kpeter@734
   221
        /// %Invalid constructor \& conversion.
deba@57
   222
kpeter@734
   223
        /// Initializes the object to be invalid.
kpeter@734
   224
        /// \sa Invalid for more details.
deba@57
   225
        Edge(Invalid) { }
deba@57
   226
        /// Equality operator
deba@57
   227
kpeter@734
   228
        /// Equality operator.
kpeter@734
   229
        ///
deba@57
   230
        /// Two iterators are equal if and only if they point to the
kpeter@734
   231
        /// same object or both are \c INVALID.
deba@57
   232
        bool operator==(Edge) const { return true; }
deba@57
   233
        /// Inequality operator
deba@57
   234
kpeter@734
   235
        /// Inequality operator.
deba@57
   236
        bool operator!=(Edge) const { return true; }
deba@57
   237
alpar@209
   238
        /// Artificial ordering operator.
alpar@209
   239
kpeter@734
   240
        /// Artificial ordering operator.
alpar@209
   241
        ///
kpeter@734
   242
        /// \note This operator only has to define some strict ordering of
kpeter@734
   243
        /// the edges; this order has nothing to do with the iteration
kpeter@734
   244
        /// ordering of the edges.
alpar@209
   245
        bool operator<(Edge) const { return false; }
deba@57
   246
      };
deba@57
   247
kpeter@734
   248
      /// Iterator class for the edges.
deba@57
   249
kpeter@734
   250
      /// This iterator goes through each edge of the graph.
kpeter@786
   251
      /// Its usage is quite simple, for example, you can count the number
kpeter@734
   252
      /// of edges in a graph \c g of type \c %Graph as follows:
deba@57
   253
      ///\code
deba@57
   254
      /// int count=0;
deba@57
   255
      /// for(Graph::EdgeIt e(g); e!=INVALID; ++e) ++count;
deba@57
   256
      ///\endcode
deba@57
   257
      class EdgeIt : public Edge {
deba@57
   258
      public:
deba@57
   259
        /// Default constructor
deba@57
   260
kpeter@734
   261
        /// Default constructor.
kpeter@734
   262
        /// \warning It sets the iterator to an undefined value.
deba@57
   263
        EdgeIt() { }
deba@57
   264
        /// Copy constructor.
deba@57
   265
deba@57
   266
        /// Copy constructor.
deba@57
   267
        ///
deba@57
   268
        EdgeIt(const EdgeIt& e) : Edge(e) { }
kpeter@734
   269
        /// %Invalid constructor \& conversion.
deba@57
   270
kpeter@734
   271
        /// Initializes the iterator to be invalid.
kpeter@734
   272
        /// \sa Invalid for more details.
kpeter@734
   273
        EdgeIt(Invalid) { }
kpeter@734
   274
        /// Sets the iterator to the first edge.
kpeter@734
   275
kpeter@734
   276
        /// Sets the iterator to the first edge of the given graph.
deba@57
   277
        ///
kpeter@734
   278
        explicit EdgeIt(const Graph&) { }
kpeter@734
   279
        /// Sets the iterator to the given edge.
alpar@209
   280
kpeter@734
   281
        /// Sets the iterator to the given edge of the given graph.
kpeter@734
   282
        ///
alpar@209
   283
        EdgeIt(const Graph&, const Edge&) { }
deba@57
   284
        /// Next edge
alpar@209
   285
deba@57
   286
        /// Assign the iterator to the next edge.
kpeter@734
   287
        ///
deba@57
   288
        EdgeIt& operator++() { return *this; }
deba@57
   289
      };
deba@57
   290
ggab90@1130
   291
      /// \brief Gets the collection of the edges of the graph.
ggab90@1130
   292
      ///
ggab90@1130
   293
      /// This function can be used for iterating on the
ggab90@1130
   294
      /// edges of the graph. It returns a wrapped
ggab90@1130
   295
      /// EdgeIt, which looks like an STL container
ggab90@1130
   296
      /// (by having begin() and end()) which you can use in range-based
ggab90@1130
   297
      /// for loops, STL algorithms, etc.
ggab90@1130
   298
      /// For example you can write:
ggab90@1130
   299
      ///\code
ggab90@1130
   300
      /// ListGraph g;
ggab90@1130
   301
      /// for(auto e: g.edges())
ggab90@1130
   302
      ///   doSomething(e);
ggab90@1130
   303
      ///
ggab90@1130
   304
      /// //Using an STL algorithm:
ggab90@1130
   305
      /// copy(g.edges().begin(), g.edges().end(), vect.begin());
ggab90@1130
   306
      ///\endcode
ggab90@1130
   307
      LemonRangeWrapper1<EdgeIt, Graph> edges() const {
ggab90@1130
   308
        return LemonRangeWrapper1<EdgeIt, Graph>(*this);
ggab90@1130
   309
      }
ggab90@1130
   310
ggab90@1130
   311
kpeter@734
   312
      /// Iterator class for the incident edges of a node.
kpeter@734
   313
kpeter@734
   314
      /// This iterator goes trough the incident undirected edges
kpeter@734
   315
      /// of a certain node of a graph.
kpeter@786
   316
      /// Its usage is quite simple, for example, you can compute the
kpeter@734
   317
      /// degree (i.e. the number of incident edges) of a node \c n
kpeter@734
   318
      /// in a graph \c g of type \c %Graph as follows.
deba@57
   319
      ///
deba@57
   320
      ///\code
deba@57
   321
      /// int count=0;
deba@78
   322
      /// for(Graph::IncEdgeIt e(g, n); e!=INVALID; ++e) ++count;
deba@57
   323
      ///\endcode
kpeter@734
   324
      ///
kpeter@734
   325
      /// \warning Loop edges will be iterated twice.
deba@78
   326
      class IncEdgeIt : public Edge {
deba@57
   327
      public:
deba@57
   328
        /// Default constructor
deba@57
   329
kpeter@734
   330
        /// Default constructor.
kpeter@734
   331
        /// \warning It sets the iterator to an undefined value.
deba@78
   332
        IncEdgeIt() { }
deba@57
   333
        /// Copy constructor.
deba@57
   334
deba@57
   335
        /// Copy constructor.
deba@57
   336
        ///
deba@78
   337
        IncEdgeIt(const IncEdgeIt& e) : Edge(e) { }
kpeter@734
   338
        /// %Invalid constructor \& conversion.
deba@57
   339
kpeter@734
   340
        /// Initializes the iterator to be invalid.
kpeter@734
   341
        /// \sa Invalid for more details.
kpeter@734
   342
        IncEdgeIt(Invalid) { }
kpeter@734
   343
        /// Sets the iterator to the first incident edge.
kpeter@734
   344
kpeter@734
   345
        /// Sets the iterator to the first incident edge of the given node.
deba@57
   346
        ///
kpeter@734
   347
        IncEdgeIt(const Graph&, const Node&) { }
kpeter@734
   348
        /// Sets the iterator to the given edge.
alpar@209
   349
kpeter@734
   350
        /// Sets the iterator to the given edge of the given graph.
kpeter@734
   351
        ///
kpeter@734
   352
        IncEdgeIt(const Graph&, const Edge&) { }
kpeter@734
   353
        /// Next incident edge
deba@57
   354
kpeter@734
   355
        /// Assign the iterator to the next incident edge
alpar@209
   356
        /// of the corresponding node.
deba@78
   357
        IncEdgeIt& operator++() { return *this; }
deba@57
   358
      };
deba@57
   359
ggab90@1130
   360
      /// \brief Gets the collection of the incident undirected edges
ggab90@1130
   361
      ///  of a certain node of the graph.
ggab90@1130
   362
      ///
ggab90@1130
   363
      /// This function can be used for iterating on the
ggab90@1130
   364
      /// incident undirected edges of a certain node of the graph.
ggab90@1130
   365
      /// It returns a wrapped
ggab90@1130
   366
      /// IncEdgeIt, which looks like an STL container
ggab90@1130
   367
      /// (by having begin() and end()) which you can use in range-based
ggab90@1130
   368
      /// for loops, STL algorithms, etc.
ggab90@1130
   369
      /// For example if g is a Graph and u is a Node, you can write:
ggab90@1130
   370
      ///\code
ggab90@1130
   371
      /// for(auto e: g.incEdges(u))
ggab90@1130
   372
      ///   doSomething(e);
ggab90@1130
   373
      ///
ggab90@1130
   374
      /// //Using an STL algorithm:
ggab90@1130
   375
      /// copy(g.incEdges(u).begin(), g.incEdges(u).end(), vect.begin());
ggab90@1130
   376
      ///\endcode
ggab90@1130
   377
      LemonRangeWrapper2<IncEdgeIt, Graph, Node> incEdges(const Node& u) const {
ggab90@1130
   378
        return LemonRangeWrapper2<IncEdgeIt, Graph, Node>(*this, u);
ggab90@1130
   379
      }
ggab90@1130
   380
ggab90@1130
   381
kpeter@734
   382
      /// The arc type of the graph
deba@57
   383
kpeter@734
   384
      /// This class identifies a directed arc of the graph. It also serves
kpeter@734
   385
      /// as a base class of the arc iterators,
kpeter@734
   386
      /// thus they will convert to this type.
kpeter@657
   387
      class Arc {
deba@57
   388
      public:
deba@57
   389
        /// Default constructor
deba@57
   390
kpeter@734
   391
        /// Default constructor.
kpeter@734
   392
        /// \warning It sets the object to an undefined value.
deba@57
   393
        Arc() { }
deba@57
   394
        /// Copy constructor.
deba@57
   395
deba@57
   396
        /// Copy constructor.
deba@57
   397
        ///
kpeter@657
   398
        Arc(const Arc&) { }
kpeter@734
   399
        /// %Invalid constructor \& conversion.
deba@57
   400
kpeter@734
   401
        /// Initializes the object to be invalid.
kpeter@734
   402
        /// \sa Invalid for more details.
deba@57
   403
        Arc(Invalid) { }
deba@57
   404
        /// Equality operator
deba@57
   405
kpeter@734
   406
        /// Equality operator.
kpeter@734
   407
        ///
deba@57
   408
        /// Two iterators are equal if and only if they point to the
kpeter@734
   409
        /// same object or both are \c INVALID.
deba@57
   410
        bool operator==(Arc) const { return true; }
deba@57
   411
        /// Inequality operator
deba@57
   412
kpeter@734
   413
        /// Inequality operator.
deba@57
   414
        bool operator!=(Arc) const { return true; }
deba@57
   415
alpar@209
   416
        /// Artificial ordering operator.
alpar@209
   417
kpeter@734
   418
        /// Artificial ordering operator.
alpar@209
   419
        ///
kpeter@734
   420
        /// \note This operator only has to define some strict ordering of
kpeter@734
   421
        /// the arcs; this order has nothing to do with the iteration
kpeter@734
   422
        /// ordering of the arcs.
alpar@209
   423
        bool operator<(Arc) const { return false; }
alpar@209
   424
kpeter@734
   425
        /// Converison to \c Edge
alpar@877
   426
kpeter@734
   427
        /// Converison to \c Edge.
kpeter@734
   428
        ///
kpeter@657
   429
        operator Edge() const { return Edge(); }
alpar@209
   430
      };
deba@57
   431
kpeter@734
   432
      /// Iterator class for the arcs.
kpeter@734
   433
kpeter@734
   434
      /// This iterator goes through each directed arc of the graph.
kpeter@786
   435
      /// Its usage is quite simple, for example, you can count the number
kpeter@734
   436
      /// of arcs in a graph \c g of type \c %Graph as follows:
deba@57
   437
      ///\code
deba@57
   438
      /// int count=0;
kpeter@734
   439
      /// for(Graph::ArcIt a(g); a!=INVALID; ++a) ++count;
deba@57
   440
      ///\endcode
deba@57
   441
      class ArcIt : public Arc {
deba@57
   442
      public:
deba@57
   443
        /// Default constructor
deba@57
   444
kpeter@734
   445
        /// Default constructor.
kpeter@734
   446
        /// \warning It sets the iterator to an undefined value.
deba@57
   447
        ArcIt() { }
deba@57
   448
        /// Copy constructor.
deba@57
   449
deba@57
   450
        /// Copy constructor.
deba@57
   451
        ///
deba@57
   452
        ArcIt(const ArcIt& e) : Arc(e) { }
kpeter@734
   453
        /// %Invalid constructor \& conversion.
deba@57
   454
kpeter@734
   455
        /// Initializes the iterator to be invalid.
kpeter@734
   456
        /// \sa Invalid for more details.
kpeter@734
   457
        ArcIt(Invalid) { }
kpeter@734
   458
        /// Sets the iterator to the first arc.
kpeter@734
   459
kpeter@734
   460
        /// Sets the iterator to the first arc of the given graph.
deba@57
   461
        ///
alpar@1093
   462
        explicit ArcIt(const Graph &g) {
alpar@1093
   463
          ::lemon::ignore_unused_variable_warning(g);
alpar@1093
   464
        }
kpeter@734
   465
        /// Sets the iterator to the given arc.
alpar@209
   466
kpeter@734
   467
        /// Sets the iterator to the given arc of the given graph.
kpeter@734
   468
        ///
alpar@209
   469
        ArcIt(const Graph&, const Arc&) { }
kpeter@734
   470
        /// Next arc
alpar@209
   471
deba@57
   472
        /// Assign the iterator to the next arc.
kpeter@734
   473
        ///
deba@57
   474
        ArcIt& operator++() { return *this; }
deba@57
   475
      };
alpar@209
   476
ggab90@1130
   477
      /// \brief Gets the collection of the directed arcs of the graph.
ggab90@1130
   478
      ///
ggab90@1130
   479
      /// This function can be used for iterating on the
ggab90@1130
   480
      /// arcs of the graph. It returns a wrapped
ggab90@1130
   481
      /// ArcIt, which looks like an STL container
ggab90@1130
   482
      /// (by having begin() and end()) which you can use in range-based
ggab90@1130
   483
      /// for loops, STL algorithms, etc.
ggab90@1130
   484
      /// For example you can write:
ggab90@1130
   485
      ///\code
ggab90@1130
   486
      /// ListGraph g;
ggab90@1130
   487
      /// for(auto a: g.arcs())
ggab90@1130
   488
      ///   doSomething(a);
ggab90@1130
   489
      ///
ggab90@1130
   490
      /// //Using an STL algorithm:
ggab90@1130
   491
      /// copy(g.arcs().begin(), g.arcs().end(), vect.begin());
ggab90@1130
   492
      ///\endcode
ggab90@1130
   493
      LemonRangeWrapper1<ArcIt, Graph> arcs() const {
ggab90@1130
   494
        return LemonRangeWrapper1<ArcIt, Graph>(*this);
ggab90@1130
   495
      }
ggab90@1130
   496
ggab90@1130
   497
kpeter@734
   498
      /// Iterator class for the outgoing arcs of a node.
deba@57
   499
kpeter@734
   500
      /// This iterator goes trough the \e outgoing directed arcs of a
kpeter@734
   501
      /// certain node of a graph.
kpeter@786
   502
      /// Its usage is quite simple, for example, you can count the number
deba@57
   503
      /// of outgoing arcs of a node \c n
kpeter@734
   504
      /// in a graph \c g of type \c %Graph as follows.
deba@57
   505
      ///\code
deba@57
   506
      /// int count=0;
kpeter@734
   507
      /// for (Digraph::OutArcIt a(g, n); a!=INVALID; ++a) ++count;
deba@57
   508
      ///\endcode
deba@57
   509
      class OutArcIt : public Arc {
deba@57
   510
      public:
deba@57
   511
        /// Default constructor
deba@57
   512
kpeter@734
   513
        /// Default constructor.
kpeter@734
   514
        /// \warning It sets the iterator to an undefined value.
deba@57
   515
        OutArcIt() { }
deba@57
   516
        /// Copy constructor.
deba@57
   517
deba@57
   518
        /// Copy constructor.
deba@57
   519
        ///
deba@57
   520
        OutArcIt(const OutArcIt& e) : Arc(e) { }
kpeter@734
   521
        /// %Invalid constructor \& conversion.
deba@57
   522
kpeter@734
   523
        /// Initializes the iterator to be invalid.
kpeter@734
   524
        /// \sa Invalid for more details.
kpeter@734
   525
        OutArcIt(Invalid) { }
kpeter@734
   526
        /// Sets the iterator to the first outgoing arc.
kpeter@734
   527
kpeter@734
   528
        /// Sets the iterator to the first outgoing arc of the given node.
deba@57
   529
        ///
deba@57
   530
        OutArcIt(const Graph& n, const Node& g) {
alpar@1083
   531
          ::lemon::ignore_unused_variable_warning(n);
alpar@1083
   532
          ::lemon::ignore_unused_variable_warning(g);
alpar@209
   533
        }
kpeter@734
   534
        /// Sets the iterator to the given arc.
deba@57
   535
kpeter@734
   536
        /// Sets the iterator to the given arc of the given graph.
kpeter@734
   537
        ///
deba@57
   538
        OutArcIt(const Graph&, const Arc&) { }
kpeter@734
   539
        /// Next outgoing arc
alpar@209
   540
alpar@209
   541
        /// Assign the iterator to the next
deba@57
   542
        /// outgoing arc of the corresponding node.
deba@57
   543
        OutArcIt& operator++() { return *this; }
deba@57
   544
      };
deba@57
   545
ggab90@1130
   546
      /// \brief Gets the collection of the outgoing directed arcs of a
ggab90@1130
   547
      /// certain node of the graph.
ggab90@1130
   548
      ///
ggab90@1130
   549
      /// This function can be used for iterating on the
ggab90@1130
   550
      /// outgoing arcs of a certain node of the graph. It returns a wrapped
ggab90@1130
   551
      /// OutArcIt, which looks like an STL container
ggab90@1130
   552
      /// (by having begin() and end()) which you can use in range-based
ggab90@1130
   553
      /// for loops, STL algorithms, etc.
ggab90@1130
   554
      /// For example if g is a Graph and u is a Node, you can write:
ggab90@1130
   555
      ///\code
ggab90@1130
   556
      /// for(auto a: g.outArcs(u))
ggab90@1130
   557
      ///   doSomething(a);
ggab90@1130
   558
      ///
ggab90@1130
   559
      /// //Using an STL algorithm:
ggab90@1130
   560
      /// copy(g.outArcs(u).begin(), g.outArcs(u).end(), vect.begin());
ggab90@1130
   561
      ///\endcode
ggab90@1130
   562
      LemonRangeWrapper2<OutArcIt, Graph, Node> outArcs(const Node& u) const {
ggab90@1130
   563
        return LemonRangeWrapper2<OutArcIt, Graph, Node>(*this, u);
ggab90@1130
   564
      }
ggab90@1130
   565
ggab90@1130
   566
kpeter@734
   567
      /// Iterator class for the incoming arcs of a node.
deba@57
   568
kpeter@734
   569
      /// This iterator goes trough the \e incoming directed arcs of a
kpeter@734
   570
      /// certain node of a graph.
kpeter@786
   571
      /// Its usage is quite simple, for example, you can count the number
kpeter@734
   572
      /// of incoming arcs of a node \c n
kpeter@734
   573
      /// in a graph \c g of type \c %Graph as follows.
deba@57
   574
      ///\code
deba@57
   575
      /// int count=0;
kpeter@734
   576
      /// for (Digraph::InArcIt a(g, n); a!=INVALID; ++a) ++count;
deba@57
   577
      ///\endcode
deba@57
   578
      class InArcIt : public Arc {
deba@57
   579
      public:
deba@57
   580
        /// Default constructor
deba@57
   581
kpeter@734
   582
        /// Default constructor.
kpeter@734
   583
        /// \warning It sets the iterator to an undefined value.
deba@57
   584
        InArcIt() { }
deba@57
   585
        /// Copy constructor.
deba@57
   586
deba@57
   587
        /// Copy constructor.
deba@57
   588
        ///
deba@57
   589
        InArcIt(const InArcIt& e) : Arc(e) { }
kpeter@734
   590
        /// %Invalid constructor \& conversion.
deba@57
   591
kpeter@734
   592
        /// Initializes the iterator to be invalid.
kpeter@734
   593
        /// \sa Invalid for more details.
kpeter@734
   594
        InArcIt(Invalid) { }
kpeter@734
   595
        /// Sets the iterator to the first incoming arc.
kpeter@734
   596
kpeter@734
   597
        /// Sets the iterator to the first incoming arc of the given node.
deba@57
   598
        ///
alpar@209
   599
        InArcIt(const Graph& g, const Node& n) {
alpar@1083
   600
          ::lemon::ignore_unused_variable_warning(n);
alpar@1083
   601
          ::lemon::ignore_unused_variable_warning(g);
alpar@209
   602
        }
kpeter@734
   603
        /// Sets the iterator to the given arc.
deba@57
   604
kpeter@734
   605
        /// Sets the iterator to the given arc of the given graph.
kpeter@734
   606
        ///
deba@57
   607
        InArcIt(const Graph&, const Arc&) { }
deba@57
   608
        /// Next incoming arc
deba@57
   609
kpeter@734
   610
        /// Assign the iterator to the next
kpeter@734
   611
        /// incoming arc of the corresponding node.
deba@57
   612
        InArcIt& operator++() { return *this; }
deba@57
   613
      };
deba@57
   614
ggab90@1130
   615
      /// \brief Gets the collection of the incoming directed arcs of
ggab90@1130
   616
      /// a certain node of the graph.
ggab90@1130
   617
      ///
ggab90@1130
   618
      /// This function can be used for iterating on the
ggab90@1130
   619
      /// incoming directed arcs of a certain node of the graph. It returns
ggab90@1130
   620
      /// a wrapped InArcIt, which looks like an STL container
ggab90@1130
   621
      /// (by having begin() and end()) which you can use in range-based
ggab90@1130
   622
      /// for loops, STL algorithms, etc.
ggab90@1130
   623
      /// For example if g is a Graph and u is a Node, you can write:
ggab90@1130
   624
      ///\code
ggab90@1130
   625
      /// for(auto a: g.inArcs(u))
ggab90@1130
   626
      ///   doSomething(a);
ggab90@1130
   627
      ///
ggab90@1130
   628
      /// //Using an STL algorithm:
ggab90@1130
   629
      /// copy(g.inArcs(u).begin(), g.inArcs(u).end(), vect.begin());
ggab90@1130
   630
      ///\endcode
ggab90@1130
   631
      LemonRangeWrapper2<InArcIt, Graph, Node> inArcs(const Node& u) const {
ggab90@1130
   632
        return LemonRangeWrapper2<InArcIt, Graph, Node>(*this, u);
ggab90@1130
   633
      }
ggab90@1130
   634
kpeter@734
   635
      /// \brief Standard graph map type for the nodes.
alpar@209
   636
      ///
kpeter@734
   637
      /// Standard graph map type for the nodes.
kpeter@734
   638
      /// It conforms to the ReferenceMap concept.
alpar@209
   639
      template<class T>
kpeter@580
   640
      class NodeMap : public ReferenceMap<Node, T, T&, const T&>
deba@57
   641
      {
deba@57
   642
      public:
deba@57
   643
kpeter@734
   644
        /// Constructor
kpeter@734
   645
        explicit NodeMap(const Graph&) { }
kpeter@734
   646
        /// Constructor with given initial value
deba@57
   647
        NodeMap(const Graph&, T) { }
deba@57
   648
kpeter@263
   649
      private:
deba@57
   650
        ///Copy constructor
kpeter@580
   651
        NodeMap(const NodeMap& nm) :
kpeter@580
   652
          ReferenceMap<Node, T, T&, const T&>(nm) { }
deba@57
   653
        ///Assignment operator
deba@57
   654
        template <typename CMap>
alpar@209
   655
        NodeMap& operator=(const CMap&) {
deba@57
   656
          checkConcept<ReadMap<Node, T>, CMap>();
alpar@209
   657
          return *this;
deba@57
   658
        }
deba@57
   659
      };
deba@57
   660
kpeter@734
   661
      /// \brief Standard graph map type for the arcs.
deba@57
   662
      ///
kpeter@734
   663
      /// Standard graph map type for the arcs.
kpeter@734
   664
      /// It conforms to the ReferenceMap concept.
alpar@209
   665
      template<class T>
kpeter@580
   666
      class ArcMap : public ReferenceMap<Arc, T, T&, const T&>
deba@57
   667
      {
deba@57
   668
      public:
deba@57
   669
kpeter@734
   670
        /// Constructor
kpeter@734
   671
        explicit ArcMap(const Graph&) { }
kpeter@734
   672
        /// Constructor with given initial value
deba@57
   673
        ArcMap(const Graph&, T) { }
kpeter@734
   674
kpeter@263
   675
      private:
deba@57
   676
        ///Copy constructor
kpeter@580
   677
        ArcMap(const ArcMap& em) :
kpeter@580
   678
          ReferenceMap<Arc, T, T&, const T&>(em) { }
deba@57
   679
        ///Assignment operator
deba@57
   680
        template <typename CMap>
alpar@209
   681
        ArcMap& operator=(const CMap&) {
deba@57
   682
          checkConcept<ReadMap<Arc, T>, CMap>();
alpar@209
   683
          return *this;
deba@57
   684
        }
deba@57
   685
      };
deba@57
   686
kpeter@734
   687
      /// \brief Standard graph map type for the edges.
kpeter@734
   688
      ///
kpeter@734
   689
      /// Standard graph map type for the edges.
kpeter@734
   690
      /// It conforms to the ReferenceMap concept.
alpar@209
   691
      template<class T>
kpeter@580
   692
      class EdgeMap : public ReferenceMap<Edge, T, T&, const T&>
deba@57
   693
      {
deba@57
   694
      public:
deba@57
   695
kpeter@734
   696
        /// Constructor
kpeter@734
   697
        explicit EdgeMap(const Graph&) { }
kpeter@734
   698
        /// Constructor with given initial value
deba@57
   699
        EdgeMap(const Graph&, T) { }
kpeter@734
   700
kpeter@263
   701
      private:
deba@57
   702
        ///Copy constructor
kpeter@580
   703
        EdgeMap(const EdgeMap& em) :
kpeter@580
   704
          ReferenceMap<Edge, T, T&, const T&>(em) {}
deba@57
   705
        ///Assignment operator
deba@57
   706
        template <typename CMap>
alpar@209
   707
        EdgeMap& operator=(const CMap&) {
deba@57
   708
          checkConcept<ReadMap<Edge, T>, CMap>();
alpar@209
   709
          return *this;
deba@57
   710
        }
deba@57
   711
      };
deba@57
   712
kpeter@734
   713
      /// \brief The first node of the edge.
deba@57
   714
      ///
kpeter@734
   715
      /// Returns the first node of the given edge.
deba@57
   716
      ///
kpeter@786
   717
      /// Edges don't have source and target nodes, however, methods
kpeter@734
   718
      /// u() and v() are used to query the two end-nodes of an edge.
kpeter@734
   719
      /// The orientation of an edge that arises this way is called
kpeter@734
   720
      /// the inherent direction, it is used to define the default
kpeter@734
   721
      /// direction for the corresponding arcs.
kpeter@559
   722
      /// \sa v()
kpeter@559
   723
      /// \sa direction()
deba@57
   724
      Node u(Edge) const { return INVALID; }
deba@57
   725
kpeter@734
   726
      /// \brief The second node of the edge.
kpeter@559
   727
      ///
kpeter@734
   728
      /// Returns the second node of the given edge.
kpeter@559
   729
      ///
kpeter@786
   730
      /// Edges don't have source and target nodes, however, methods
kpeter@734
   731
      /// u() and v() are used to query the two end-nodes of an edge.
kpeter@734
   732
      /// The orientation of an edge that arises this way is called
kpeter@734
   733
      /// the inherent direction, it is used to define the default
kpeter@734
   734
      /// direction for the corresponding arcs.
kpeter@559
   735
      /// \sa u()
kpeter@559
   736
      /// \sa direction()
deba@57
   737
      Node v(Edge) const { return INVALID; }
deba@57
   738
kpeter@734
   739
      /// \brief The source node of the arc.
kpeter@734
   740
      ///
kpeter@734
   741
      /// Returns the source node of the given arc.
deba@57
   742
      Node source(Arc) const { return INVALID; }
deba@57
   743
kpeter@734
   744
      /// \brief The target node of the arc.
kpeter@734
   745
      ///
kpeter@734
   746
      /// Returns the target node of the given arc.
deba@57
   747
      Node target(Arc) const { return INVALID; }
deba@57
   748
kpeter@734
   749
      /// \brief The ID of the node.
kpeter@734
   750
      ///
kpeter@734
   751
      /// Returns the ID of the given node.
alpar@209
   752
      int id(Node) const { return -1; }
deba@61
   753
kpeter@734
   754
      /// \brief The ID of the edge.
kpeter@734
   755
      ///
kpeter@734
   756
      /// Returns the ID of the given edge.
alpar@209
   757
      int id(Edge) const { return -1; }
deba@61
   758
kpeter@734
   759
      /// \brief The ID of the arc.
kpeter@734
   760
      ///
kpeter@734
   761
      /// Returns the ID of the given arc.
alpar@209
   762
      int id(Arc) const { return -1; }
deba@61
   763
kpeter@734
   764
      /// \brief The node with the given ID.
deba@61
   765
      ///
kpeter@734
   766
      /// Returns the node with the given ID.
kpeter@734
   767
      /// \pre The argument should be a valid node ID in the graph.
alpar@209
   768
      Node nodeFromId(int) const { return INVALID; }
deba@61
   769
kpeter@734
   770
      /// \brief The edge with the given ID.
deba@61
   771
      ///
kpeter@734
   772
      /// Returns the edge with the given ID.
kpeter@734
   773
      /// \pre The argument should be a valid edge ID in the graph.
alpar@209
   774
      Edge edgeFromId(int) const { return INVALID; }
deba@61
   775
kpeter@734
   776
      /// \brief The arc with the given ID.
deba@61
   777
      ///
kpeter@734
   778
      /// Returns the arc with the given ID.
kpeter@734
   779
      /// \pre The argument should be a valid arc ID in the graph.
alpar@209
   780
      Arc arcFromId(int) const { return INVALID; }
deba@61
   781
kpeter@734
   782
      /// \brief An upper bound on the node IDs.
kpeter@734
   783
      ///
kpeter@734
   784
      /// Returns an upper bound on the node IDs.
alpar@209
   785
      int maxNodeId() const { return -1; }
deba@61
   786
kpeter@734
   787
      /// \brief An upper bound on the edge IDs.
kpeter@734
   788
      ///
kpeter@734
   789
      /// Returns an upper bound on the edge IDs.
alpar@209
   790
      int maxEdgeId() const { return -1; }
deba@61
   791
kpeter@734
   792
      /// \brief An upper bound on the arc IDs.
kpeter@734
   793
      ///
kpeter@734
   794
      /// Returns an upper bound on the arc IDs.
alpar@209
   795
      int maxArcId() const { return -1; }
deba@61
   796
kpeter@734
   797
      /// \brief The direction of the arc.
kpeter@734
   798
      ///
kpeter@734
   799
      /// Returns \c true if the direction of the given arc is the same as
kpeter@734
   800
      /// the inherent orientation of the represented edge.
kpeter@734
   801
      bool direction(Arc) const { return true; }
kpeter@734
   802
kpeter@734
   803
      /// \brief Direct the edge.
kpeter@734
   804
      ///
kpeter@734
   805
      /// Direct the given edge. The returned arc
kpeter@734
   806
      /// represents the given edge and its direction comes
kpeter@734
   807
      /// from the bool parameter. If it is \c true, then the direction
kpeter@734
   808
      /// of the arc is the same as the inherent orientation of the edge.
kpeter@734
   809
      Arc direct(Edge, bool) const {
kpeter@734
   810
        return INVALID;
kpeter@734
   811
      }
kpeter@734
   812
kpeter@734
   813
      /// \brief Direct the edge.
kpeter@734
   814
      ///
kpeter@734
   815
      /// Direct the given edge. The returned arc represents the given
kpeter@734
   816
      /// edge and its source node is the given node.
kpeter@734
   817
      Arc direct(Edge, Node) const {
kpeter@734
   818
        return INVALID;
kpeter@734
   819
      }
kpeter@734
   820
kpeter@734
   821
      /// \brief The oppositely directed arc.
kpeter@734
   822
      ///
kpeter@734
   823
      /// Returns the oppositely directed arc representing the same edge.
kpeter@734
   824
      Arc oppositeArc(Arc) const { return INVALID; }
kpeter@734
   825
kpeter@734
   826
      /// \brief The opposite node on the edge.
kpeter@734
   827
      ///
kpeter@734
   828
      /// Returns the opposite node on the given edge.
kpeter@734
   829
      Node oppositeNode(Node, Edge) const { return INVALID; }
kpeter@734
   830
deba@57
   831
      void first(Node&) const {}
deba@57
   832
      void next(Node&) const {}
deba@57
   833
deba@57
   834
      void first(Edge&) const {}
deba@57
   835
      void next(Edge&) const {}
deba@57
   836
deba@57
   837
      void first(Arc&) const {}
deba@57
   838
      void next(Arc&) const {}
deba@57
   839
deba@57
   840
      void firstOut(Arc&, Node) const {}
deba@57
   841
      void nextOut(Arc&) const {}
deba@57
   842
deba@57
   843
      void firstIn(Arc&, Node) const {}
deba@57
   844
      void nextIn(Arc&) const {}
deba@57
   845
deba@57
   846
      void firstInc(Edge &, bool &, const Node &) const {}
deba@57
   847
      void nextInc(Edge &, bool &) const {}
deba@57
   848
deba@61
   849
      // The second parameter is dummy.
deba@61
   850
      Node fromId(int, Node) const { return INVALID; }
deba@61
   851
      // The second parameter is dummy.
deba@61
   852
      Edge fromId(int, Edge) const { return INVALID; }
deba@61
   853
      // The second parameter is dummy.
deba@61
   854
      Arc fromId(int, Arc) const { return INVALID; }
deba@61
   855
deba@61
   856
      // Dummy parameter.
alpar@209
   857
      int maxId(Node) const { return -1; }
deba@61
   858
      // Dummy parameter.
alpar@209
   859
      int maxId(Edge) const { return -1; }
deba@61
   860
      // Dummy parameter.
alpar@209
   861
      int maxId(Arc) const { return -1; }
deba@61
   862
kpeter@734
   863
      /// \brief The base node of the iterator.
deba@57
   864
      ///
kpeter@734
   865
      /// Returns the base node of the given incident edge iterator.
kpeter@734
   866
      Node baseNode(IncEdgeIt) const { return INVALID; }
kpeter@734
   867
kpeter@734
   868
      /// \brief The running node of the iterator.
deba@57
   869
      ///
kpeter@734
   870
      /// Returns the running node of the given incident edge iterator.
kpeter@734
   871
      Node runningNode(IncEdgeIt) const { return INVALID; }
deba@57
   872
kpeter@734
   873
      /// \brief The base node of the iterator.
deba@57
   874
      ///
kpeter@734
   875
      /// Returns the base node of the given outgoing arc iterator
kpeter@734
   876
      /// (i.e. the source node of the corresponding arc).
kpeter@734
   877
      Node baseNode(OutArcIt) const { return INVALID; }
kpeter@734
   878
kpeter@734
   879
      /// \brief The running node of the iterator.
deba@57
   880
      ///
kpeter@734
   881
      /// Returns the running node of the given outgoing arc iterator
kpeter@734
   882
      /// (i.e. the target node of the corresponding arc).
kpeter@734
   883
      Node runningNode(OutArcIt) const { return INVALID; }
deba@57
   884
kpeter@734
   885
      /// \brief The base node of the iterator.
deba@57
   886
      ///
kpeter@1049
   887
      /// Returns the base node of the given incoming arc iterator
kpeter@734
   888
      /// (i.e. the target node of the corresponding arc).
kpeter@734
   889
      Node baseNode(InArcIt) const { return INVALID; }
alpar@209
   890
kpeter@734
   891
      /// \brief The running node of the iterator.
deba@57
   892
      ///
kpeter@1049
   893
      /// Returns the running node of the given incoming arc iterator
kpeter@734
   894
      /// (i.e. the source node of the corresponding arc).
kpeter@734
   895
      Node runningNode(InArcIt) const { return INVALID; }
deba@57
   896
deba@125
   897
      template <typename _Graph>
deba@57
   898
      struct Constraints {
alpar@209
   899
        void constraints() {
kpeter@580
   900
          checkConcept<BaseGraphComponent, _Graph>();
alpar@209
   901
          checkConcept<IterableGraphComponent<>, _Graph>();
alpar@209
   902
          checkConcept<IDableGraphComponent<>, _Graph>();
alpar@209
   903
          checkConcept<MappableGraphComponent<>, _Graph>();
alpar@209
   904
        }
deba@57
   905
      };
deba@57
   906
deba@57
   907
    };
deba@57
   908
deba@57
   909
  }
deba@57
   910
deba@57
   911
}
deba@57
   912
deba@57
   913
#endif