lemon/concepts/digraph.h
author Akos Ladanyi <ladanyi@tmit.bme.hu>
Wed, 23 Jan 2008 16:26:41 +0100
changeset 60 6ec5dbed8f18
child 61 d718974f1290
permissions -rw-r--r--
Reworked documentation generation and installation.
Details:
- Remove configure flag used to disable the automatic generation of the
documentation when istalling.
- Now 'make html' generates the documentation.
- Now 'make install' does not install the documentation, 'make install-html'
does that. The latter two changes follow newer automake conventions.
- This also fixes the bug that caused the documentation missing from the
tarball.
deba@57
     1
/* -*- C++ -*-
deba@57
     2
 *
deba@57
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@57
     4
 *
deba@57
     5
 * Copyright (C) 2003-2007
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
#ifndef LEMON_CONCEPT_DIGRAPH_H
deba@57
    20
#define LEMON_CONCEPT_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@57
    26
#include <lemon/bits/invalid.h>
deba@57
    27
#include <lemon/bits/utility.h>
deba@57
    28
#include <lemon/concepts/maps.h>
deba@57
    29
#include <lemon/concept_check.h>
deba@57
    30
#include <lemon/concepts/graph_components.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
    ///
deba@57
    39
    /// This class describes the \ref concept "concept" of the
deba@57
    40
    /// immutable directed digraphs.
deba@57
    41
    ///
deba@57
    42
    /// Note that actual digraph implementation like @ref ListDigraph or
deba@57
    43
    /// @ref SmartDigraph may have several additional functionality.
deba@57
    44
    ///
deba@57
    45
    /// \sa concept
deba@57
    46
    class Digraph {
deba@57
    47
    private:
deba@57
    48
      ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
deba@57
    49
      
deba@57
    50
      ///Digraphs are \e not copy constructible. Use DigraphCopy() instead.
deba@57
    51
      ///
deba@57
    52
      Digraph(const Digraph &) {};
deba@57
    53
      ///\brief Assignment of \ref Digraph "Digraph"s to another ones are
deba@57
    54
      ///\e not allowed. Use DigraphCopy() instead.
deba@57
    55
      
deba@57
    56
      ///Assignment of \ref Digraph "Digraph"s to another ones are
deba@57
    57
      ///\e not allowed.  Use DigraphCopy() instead.
deba@57
    58
deba@57
    59
      void operator=(const Digraph &) {}
deba@57
    60
    public:
deba@57
    61
      ///\e
deba@57
    62
deba@57
    63
      /// Defalult constructor.
deba@57
    64
deba@57
    65
      /// Defalult constructor.
deba@57
    66
      ///
deba@57
    67
      Digraph() { }
deba@57
    68
      /// Class for identifying a node of the digraph
deba@57
    69
deba@57
    70
      /// This class identifies a node of the digraph. It also serves
deba@57
    71
      /// as a base class of the node iterators,
deba@57
    72
      /// thus they will convert to this type.
deba@57
    73
      class Node {
deba@57
    74
      public:
deba@57
    75
        /// Default constructor
deba@57
    76
deba@57
    77
        /// @warning The default constructor sets the iterator
deba@57
    78
        /// to an undefined value.
deba@57
    79
        Node() { }
deba@57
    80
        /// Copy constructor.
deba@57
    81
deba@57
    82
        /// Copy constructor.
deba@57
    83
        ///
deba@57
    84
        Node(const Node&) { }
deba@57
    85
deba@57
    86
        /// Invalid constructor \& conversion.
deba@57
    87
deba@57
    88
        /// This constructor initializes the iterator to be invalid.
deba@57
    89
        /// \sa Invalid for more details.
deba@57
    90
        Node(Invalid) { }
deba@57
    91
        /// Equality operator
deba@57
    92
deba@57
    93
        /// Two iterators are equal if and only if they point to the
deba@57
    94
        /// same object or both are invalid.
deba@57
    95
        bool operator==(Node) const { return true; }
deba@57
    96
deba@57
    97
        /// Inequality operator
deba@57
    98
        
deba@57
    99
        /// \sa operator==(Node n)
deba@57
   100
        ///
deba@57
   101
        bool operator!=(Node) const { return true; }
deba@57
   102
deba@57
   103
	/// Artificial ordering operator.
deba@57
   104
	
deba@57
   105
	/// To allow the use of digraph descriptors as key type in std::map or
deba@57
   106
	/// similar associative container we require this.
deba@57
   107
	///
deba@57
   108
	/// \note This operator only have to define some strict ordering of
deba@57
   109
	/// the items; this order has nothing to do with the iteration
deba@57
   110
	/// ordering of the items.
deba@57
   111
	bool operator<(Node) const { return false; }
deba@57
   112
deba@57
   113
      };
deba@57
   114
    
deba@57
   115
      /// This iterator goes through each node.
deba@57
   116
deba@57
   117
      /// This iterator goes through each node.
deba@57
   118
      /// Its usage is quite simple, for example you can count the number
deba@57
   119
      /// of nodes in digraph \c g of type \c Digraph like this:
deba@57
   120
      ///\code
deba@57
   121
      /// int count=0;
deba@57
   122
      /// for (Digraph::NodeIt n(g); n!=INVALID; ++n) ++count;
deba@57
   123
      ///\endcode
deba@57
   124
      class NodeIt : public Node {
deba@57
   125
      public:
deba@57
   126
        /// Default constructor
deba@57
   127
deba@57
   128
        /// @warning The default constructor sets the iterator
deba@57
   129
        /// to an undefined value.
deba@57
   130
        NodeIt() { }
deba@57
   131
        /// Copy constructor.
deba@57
   132
        
deba@57
   133
        /// Copy constructor.
deba@57
   134
        ///
deba@57
   135
        NodeIt(const NodeIt& n) : Node(n) { }
deba@57
   136
        /// Invalid constructor \& conversion.
deba@57
   137
deba@57
   138
        /// Initialize the iterator to be invalid.
deba@57
   139
        /// \sa Invalid for more details.
deba@57
   140
        NodeIt(Invalid) { }
deba@57
   141
        /// Sets the iterator to the first node.
deba@57
   142
deba@57
   143
        /// Sets the iterator to the first node of \c g.
deba@57
   144
        ///
deba@57
   145
        NodeIt(const Digraph&) { }
deba@57
   146
        /// Node -> NodeIt conversion.
deba@57
   147
deba@57
   148
        /// Sets the iterator to the node of \c the digraph pointed by 
deba@57
   149
	/// the trivial iterator.
deba@57
   150
        /// This feature necessitates that each time we 
deba@57
   151
        /// iterate the arc-set, the iteration order is the same.
deba@57
   152
        NodeIt(const Digraph&, const Node&) { }
deba@57
   153
        /// Next node.
deba@57
   154
deba@57
   155
        /// Assign the iterator to the next node.
deba@57
   156
        ///
deba@57
   157
        NodeIt& operator++() { return *this; }
deba@57
   158
      };
deba@57
   159
    
deba@57
   160
    
deba@57
   161
      /// Class for identifying an arc of the digraph
deba@57
   162
deba@57
   163
      /// This class identifies an arc of the digraph. It also serves
deba@57
   164
      /// as a base class of the arc iterators,
deba@57
   165
      /// thus they will convert to this type.
deba@57
   166
      class Arc {
deba@57
   167
      public:
deba@57
   168
        /// Default constructor
deba@57
   169
deba@57
   170
        /// @warning The default constructor sets the iterator
deba@57
   171
        /// to an undefined value.
deba@57
   172
        Arc() { }
deba@57
   173
        /// Copy constructor.
deba@57
   174
deba@57
   175
        /// Copy constructor.
deba@57
   176
        ///
deba@57
   177
        Arc(const Arc&) { }
deba@57
   178
        /// Initialize the iterator to be invalid.
deba@57
   179
deba@57
   180
        /// Initialize the iterator to be invalid.
deba@57
   181
        ///
deba@57
   182
        Arc(Invalid) { }
deba@57
   183
        /// Equality operator
deba@57
   184
deba@57
   185
        /// Two iterators are equal if and only if they point to the
deba@57
   186
        /// same object or both are invalid.
deba@57
   187
        bool operator==(Arc) const { return true; }
deba@57
   188
        /// Inequality operator
deba@57
   189
deba@57
   190
        /// \sa operator==(Arc n)
deba@57
   191
        ///
deba@57
   192
        bool operator!=(Arc) const { return true; }
deba@57
   193
deba@57
   194
	/// Artificial ordering operator.
deba@57
   195
	
deba@57
   196
	/// To allow the use of digraph descriptors as key type in std::map or
deba@57
   197
	/// similar associative container we require this.
deba@57
   198
	///
deba@57
   199
	/// \note This operator only have to define some strict ordering of
deba@57
   200
	/// the items; this order has nothing to do with the iteration
deba@57
   201
	/// ordering of the items.
deba@57
   202
	bool operator<(Arc) const { return false; }
deba@57
   203
      };
deba@57
   204
    
deba@57
   205
      /// This iterator goes trough the outgoing arcs of a node.
deba@57
   206
deba@57
   207
      /// This iterator goes trough the \e outgoing arcs of a certain node
deba@57
   208
      /// of a digraph.
deba@57
   209
      /// Its usage is quite simple, for example you can count the number
deba@57
   210
      /// of outgoing arcs of a node \c n
deba@57
   211
      /// in digraph \c g of type \c Digraph as follows.
deba@57
   212
      ///\code
deba@57
   213
      /// int count=0;
deba@57
   214
      /// for (Digraph::OutArcIt e(g, n); e!=INVALID; ++e) ++count;
deba@57
   215
      ///\endcode
deba@57
   216
    
deba@57
   217
      class OutArcIt : public Arc {
deba@57
   218
      public:
deba@57
   219
        /// Default constructor
deba@57
   220
deba@57
   221
        /// @warning The default constructor sets the iterator
deba@57
   222
        /// to an undefined value.
deba@57
   223
        OutArcIt() { }
deba@57
   224
        /// Copy constructor.
deba@57
   225
deba@57
   226
        /// Copy constructor.
deba@57
   227
        ///
deba@57
   228
        OutArcIt(const OutArcIt& e) : Arc(e) { }
deba@57
   229
        /// Initialize the iterator to be invalid.
deba@57
   230
deba@57
   231
        /// Initialize the iterator to be invalid.
deba@57
   232
        ///
deba@57
   233
        OutArcIt(Invalid) { }
deba@57
   234
        /// This constructor sets the iterator to the first outgoing arc.
deba@57
   235
    
deba@57
   236
        /// This constructor sets the iterator to the first outgoing arc of
deba@57
   237
        /// the node.
deba@57
   238
        OutArcIt(const Digraph&, const Node&) { }
deba@57
   239
        /// Arc -> OutArcIt conversion
deba@57
   240
deba@57
   241
        /// Sets the iterator to the value of the trivial iterator.
deba@57
   242
	/// This feature necessitates that each time we 
deba@57
   243
        /// iterate the arc-set, the iteration order is the same.
deba@57
   244
        OutArcIt(const Digraph&, const Arc&) { }
deba@57
   245
        ///Next outgoing arc
deba@57
   246
        
deba@57
   247
        /// Assign the iterator to the next 
deba@57
   248
        /// outgoing arc of the corresponding node.
deba@57
   249
        OutArcIt& operator++() { return *this; }
deba@57
   250
      };
deba@57
   251
deba@57
   252
      /// This iterator goes trough the incoming arcs of a node.
deba@57
   253
deba@57
   254
      /// This iterator goes trough the \e incoming arcs of a certain node
deba@57
   255
      /// of a digraph.
deba@57
   256
      /// Its usage is quite simple, for example you can count the number
deba@57
   257
      /// of outgoing arcs of a node \c n
deba@57
   258
      /// in digraph \c g of type \c Digraph as follows.
deba@57
   259
      ///\code
deba@57
   260
      /// int count=0;
deba@57
   261
      /// for(Digraph::InArcIt e(g, n); e!=INVALID; ++e) ++count;
deba@57
   262
      ///\endcode
deba@57
   263
deba@57
   264
      class InArcIt : public Arc {
deba@57
   265
      public:
deba@57
   266
        /// Default constructor
deba@57
   267
deba@57
   268
        /// @warning The default constructor sets the iterator
deba@57
   269
        /// to an undefined value.
deba@57
   270
        InArcIt() { }
deba@57
   271
        /// Copy constructor.
deba@57
   272
deba@57
   273
        /// Copy constructor.
deba@57
   274
        ///
deba@57
   275
        InArcIt(const InArcIt& e) : Arc(e) { }
deba@57
   276
        /// Initialize the iterator to be invalid.
deba@57
   277
deba@57
   278
        /// Initialize the iterator to be invalid.
deba@57
   279
        ///
deba@57
   280
        InArcIt(Invalid) { }
deba@57
   281
        /// This constructor sets the iterator to first incoming arc.
deba@57
   282
    
deba@57
   283
        /// This constructor set the iterator to the first incoming arc of
deba@57
   284
        /// the node.
deba@57
   285
        InArcIt(const Digraph&, const Node&) { }
deba@57
   286
        /// Arc -> InArcIt conversion
deba@57
   287
deba@57
   288
        /// Sets the iterator to the value of the trivial iterator \c e.
deba@57
   289
        /// This feature necessitates that each time we 
deba@57
   290
        /// iterate the arc-set, the iteration order is the same.
deba@57
   291
        InArcIt(const Digraph&, const Arc&) { }
deba@57
   292
        /// Next incoming arc
deba@57
   293
deba@57
   294
        /// Assign the iterator to the next inarc of the corresponding node.
deba@57
   295
        ///
deba@57
   296
        InArcIt& operator++() { return *this; }
deba@57
   297
      };
deba@57
   298
      /// This iterator goes through each arc.
deba@57
   299
deba@57
   300
      /// This iterator goes through each arc of a digraph.
deba@57
   301
      /// Its usage is quite simple, for example you can count the number
deba@57
   302
      /// of arcs in a digraph \c g of type \c Digraph as follows:
deba@57
   303
      ///\code
deba@57
   304
      /// int count=0;
deba@57
   305
      /// for(Digraph::ArcIt e(g); e!=INVALID; ++e) ++count;
deba@57
   306
      ///\endcode
deba@57
   307
      class ArcIt : public Arc {
deba@57
   308
      public:
deba@57
   309
        /// Default constructor
deba@57
   310
deba@57
   311
        /// @warning The default constructor sets the iterator
deba@57
   312
        /// to an undefined value.
deba@57
   313
        ArcIt() { }
deba@57
   314
        /// Copy constructor.
deba@57
   315
deba@57
   316
        /// Copy constructor.
deba@57
   317
        ///
deba@57
   318
        ArcIt(const ArcIt& e) : Arc(e) { }
deba@57
   319
        /// Initialize the iterator to be invalid.
deba@57
   320
deba@57
   321
        /// Initialize the iterator to be invalid.
deba@57
   322
        ///
deba@57
   323
        ArcIt(Invalid) { }
deba@57
   324
        /// This constructor sets the iterator to the first arc.
deba@57
   325
    
deba@57
   326
        /// This constructor sets the iterator to the first arc of \c g.
deba@57
   327
        ///@param g the digraph
deba@57
   328
        ArcIt(const Digraph& g) { ignore_unused_variable_warning(g); }
deba@57
   329
        /// Arc -> ArcIt conversion
deba@57
   330
deba@57
   331
        /// Sets the iterator to the value of the trivial iterator \c e.
deba@57
   332
        /// This feature necessitates that each time we 
deba@57
   333
        /// iterate the arc-set, the iteration order is the same.
deba@57
   334
        ArcIt(const Digraph&, const Arc&) { } 
deba@57
   335
        ///Next arc
deba@57
   336
        
deba@57
   337
        /// Assign the iterator to the next arc.
deba@57
   338
        ArcIt& operator++() { return *this; }
deba@57
   339
      };
deba@57
   340
      ///Gives back the target node of an arc.
deba@57
   341
deba@57
   342
      ///Gives back the target node of an arc.
deba@57
   343
      ///
deba@57
   344
      Node target(Arc) const { return INVALID; }
deba@57
   345
      ///Gives back the source node of an arc.
deba@57
   346
deba@57
   347
      ///Gives back the source node of an arc.
deba@57
   348
      ///
deba@57
   349
      Node source(Arc) const { return INVALID; }
deba@57
   350
deba@57
   351
      void first(Node&) const {}
deba@57
   352
      void next(Node&) const {}
deba@57
   353
deba@57
   354
      void first(Arc&) const {}
deba@57
   355
      void next(Arc&) const {}
deba@57
   356
deba@57
   357
deba@57
   358
      void firstIn(Arc&, const Node&) const {}
deba@57
   359
      void nextIn(Arc&) const {}
deba@57
   360
deba@57
   361
      void firstOut(Arc&, const Node&) const {}
deba@57
   362
      void nextOut(Arc&) const {}
deba@57
   363
deba@57
   364
      /// \brief The base node of the iterator.
deba@57
   365
      ///
deba@57
   366
      /// Gives back the base node of the iterator.
deba@57
   367
      /// It is always the target of the pointed arc.
deba@57
   368
      Node baseNode(const InArcIt&) const { return INVALID; }
deba@57
   369
deba@57
   370
      /// \brief The running node of the iterator.
deba@57
   371
      ///
deba@57
   372
      /// Gives back the running node of the iterator.
deba@57
   373
      /// It is always the source of the pointed arc.
deba@57
   374
      Node runningNode(const InArcIt&) const { return INVALID; }
deba@57
   375
deba@57
   376
      /// \brief The base node of the iterator.
deba@57
   377
      ///
deba@57
   378
      /// Gives back the base node of the iterator.
deba@57
   379
      /// It is always the source of the pointed arc.
deba@57
   380
      Node baseNode(const OutArcIt&) const { return INVALID; }
deba@57
   381
deba@57
   382
      /// \brief The running node of the iterator.
deba@57
   383
      ///
deba@57
   384
      /// Gives back the running node of the iterator.
deba@57
   385
      /// It is always the target of the pointed arc.
deba@57
   386
      Node runningNode(const OutArcIt&) const { return INVALID; }
deba@57
   387
deba@57
   388
      /// \brief The opposite node on the given arc.
deba@57
   389
      ///
deba@57
   390
      /// Gives back the opposite node on the given arc.
deba@57
   391
      Node oppositeNode(const Node&, const Arc&) const { return INVALID; }
deba@57
   392
deba@57
   393
      /// \brief Read write map of the nodes to type \c T.
deba@57
   394
      /// 
deba@57
   395
      /// ReadWrite map of the nodes to type \c T.
deba@57
   396
      /// \sa Reference
deba@57
   397
      template<class T> 
deba@57
   398
      class NodeMap : public ReadWriteMap< Node, T > {
deba@57
   399
      public:
deba@57
   400
deba@57
   401
        ///\e
deba@57
   402
        NodeMap(const Digraph&) { }
deba@57
   403
        ///\e
deba@57
   404
        NodeMap(const Digraph&, T) { }
deba@57
   405
deba@57
   406
        ///Copy constructor
deba@57
   407
        NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
deba@57
   408
        ///Assignment operator
deba@57
   409
        template <typename CMap>
deba@57
   410
        NodeMap& operator=(const CMap&) { 
deba@57
   411
          checkConcept<ReadMap<Node, T>, CMap>();
deba@57
   412
          return *this; 
deba@57
   413
        }
deba@57
   414
      };
deba@57
   415
deba@57
   416
      /// \brief Read write map of the arcs to type \c T.
deba@57
   417
      ///
deba@57
   418
      /// Reference map of the arcs to type \c T.
deba@57
   419
      /// \sa Reference
deba@57
   420
      template<class T> 
deba@57
   421
      class ArcMap : public ReadWriteMap<Arc,T> {
deba@57
   422
      public:
deba@57
   423
deba@57
   424
        ///\e
deba@57
   425
        ArcMap(const Digraph&) { }
deba@57
   426
        ///\e
deba@57
   427
        ArcMap(const Digraph&, T) { }
deba@57
   428
        ///Copy constructor
deba@57
   429
        ArcMap(const ArcMap& em) : ReadWriteMap<Arc,T>(em) { }
deba@57
   430
        ///Assignment operator
deba@57
   431
        template <typename CMap>
deba@57
   432
        ArcMap& operator=(const CMap&) { 
deba@57
   433
          checkConcept<ReadMap<Arc, T>, CMap>();
deba@57
   434
          return *this; 
deba@57
   435
        }
deba@57
   436
      };
deba@57
   437
deba@57
   438
      template <typename RDigraph>
deba@57
   439
      struct Constraints {
deba@57
   440
        void constraints() {
deba@57
   441
          checkConcept<IterableDigraphComponent<>, Digraph>();
deba@57
   442
          checkConcept<MappableDigraphComponent<>, Digraph>();
deba@57
   443
        }
deba@57
   444
      };
deba@57
   445
deba@57
   446
    };
deba@57
   447
    
deba@57
   448
  } //namespace concepts  
deba@57
   449
} //namespace lemon
deba@57
   450
deba@57
   451
deba@57
   452
deba@57
   453
#endif // LEMON_CONCEPT_DIGRAPH_H