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