src/lemon/concept/path.h
author marci
Mon, 15 Nov 2004 16:39:55 +0000
changeset 997 665ffade9aca
parent 967 6563019430ba
child 1151 b217fc69f913
permissions -rw-r--r--
RevGraphWrapper modified according to the factory
klao@959
     1
/* -*- C++ -*-
klao@959
     2
 * src/lemon/concept/path.h - Part of LEMON, a generic C++ optimization library
klao@959
     3
 *
klao@959
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
klao@959
     5
 * (Egervary Combinatorial Optimization Research Group, 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.
klao@959
    20
klao@959
    21
#ifndef LEMON_CONCEPT_PATH_H
klao@959
    22
#define LEMON_CONCEPT_PATH_H
klao@959
    23
klao@959
    24
#include <lemon/invalid.h>
klao@959
    25
klao@959
    26
namespace lemon {
klao@959
    27
  namespace concept {
klao@959
    28
    /// \addtogroup concept
klao@959
    29
    /// @{
klao@959
    30
klao@959
    31
alpar@967
    32
    //! \brief A skeleton structure for representing directed paths in a graph.
klao@959
    33
    //!
klao@959
    34
    //! A skeleton structure for representing directed paths in a graph.
klao@959
    35
    //! \param GR The graph type in which the path is.
klao@959
    36
    //!
klao@959
    37
    //! In a sense, the path can be treated as a graph, for is has \c NodeIt
klao@959
    38
    //! and \c EdgeIt with the same usage. These types converts to the \c Node
klao@959
    39
    //! and \c Edge of the original graph.
klao@959
    40
    template<typename GR>
klao@959
    41
    class Path {
klao@959
    42
    public:
klao@959
    43
klao@959
    44
      /// Type of the underlying graph.
klao@959
    45
      typedef /*typename*/ GR Graph;
klao@959
    46
      /// Edge type of the underlying graph.
klao@959
    47
      typedef typename Graph::Edge GraphEdge;
klao@959
    48
      /// Node type of the underlying graph.
klao@959
    49
     typedef typename Graph::Node GraphNode;
klao@959
    50
      class NodeIt;
klao@959
    51
      class EdgeIt;
klao@959
    52
klao@959
    53
      /// \param _G The graph in which the path is.
klao@959
    54
      ///
klao@959
    55
      Path(const Graph &_G) {}
klao@959
    56
klao@959
    57
      /// Length of the path.
klao@959
    58
      size_t length() const {return 0;}
klao@959
    59
      /// Returns whether the path is empty.
klao@959
    60
      bool empty() const { return true;}
klao@959
    61
klao@959
    62
      /// Resets the path to an empty path.
klao@959
    63
      void clear() {}
klao@959
    64
klao@959
    65
      /// \brief Starting point of the path.
klao@959
    66
      ///
klao@959
    67
      /// Starting point of the path.
klao@959
    68
      /// Returns INVALID if the path is empty.
alpar@986
    69
      GraphNode/*It*/ target() const {return INVALID;}
klao@959
    70
      /// \brief End point of the path.
klao@959
    71
      ///
klao@959
    72
      /// End point of the path.
klao@959
    73
      /// Returns INVALID if the path is empty.
alpar@986
    74
      GraphNode/*It*/ source() const {return INVALID;}
klao@959
    75
klao@959
    76
      /// \brief First NodeIt/EdgeIt.
klao@959
    77
      ///
klao@959
    78
      /// Initializes node or edge iterator to point to the first
klao@959
    79
      /// node or edge.
klao@959
    80
      template<typename It>
klao@959
    81
      It& first(It &i) const { return i=It(*this); }
klao@959
    82
alpar@986
    83
      /// \brief The target of an edge.
klao@959
    84
      ///
alpar@986
    85
      /// Returns node iterator pointing to the target node of the
klao@959
    86
      /// given edge iterator.
alpar@986
    87
      NodeIt target(const EdgeIt& e) const {return INVALID;}
klao@959
    88
alpar@986
    89
      /// \brief The source of an edge.
klao@959
    90
      ///
alpar@986
    91
      /// Returns node iterator pointing to the source node of the
klao@959
    92
      /// given edge iterator.
alpar@986
    93
      NodeIt source(const EdgeIt& e) const {return INVALID;}
klao@959
    94
klao@959
    95
klao@959
    96
      /* Iterator classes */
klao@959
    97
klao@959
    98
      /**
klao@959
    99
       * \brief Iterator class to iterate on the edges of the paths
klao@959
   100
       *
klao@959
   101
       * \ingroup concept
klao@959
   102
       * This class is used to iterate on the edges of the paths
klao@959
   103
       *
klao@959
   104
       * Of course it converts to Graph::Edge
klao@959
   105
       *
klao@959
   106
       */
klao@959
   107
      class EdgeIt {
klao@959
   108
      public:
klao@959
   109
	/// Default constructor
klao@959
   110
	EdgeIt() {}
klao@959
   111
	/// Invalid constructor
klao@959
   112
	EdgeIt(Invalid) {}
klao@959
   113
	/// Constructor with starting point
klao@959
   114
	EdgeIt(const Path &_p) {}
klao@959
   115
klao@959
   116
	operator GraphEdge () const {}
klao@959
   117
klao@959
   118
	/// Next edge
klao@959
   119
	EdgeIt& operator++() {return *this;}
klao@959
   120
klao@959
   121
	/// Comparison operator
klao@959
   122
	bool operator==(const EdgeIt& e) const {return true;}
klao@959
   123
	/// Comparison operator
klao@959
   124
	bool operator!=(const EdgeIt& e) const {return true;}
klao@959
   125
// 	/// Comparison operator
klao@959
   126
//      /// \todo It is not clear what is the "natural" ordering.
klao@959
   127
// 	bool operator<(const EdgeIt& e) const {}
klao@959
   128
klao@959
   129
      };
klao@959
   130
klao@959
   131
      /**
klao@959
   132
       * \brief Iterator class to iterate on the nodes of the paths
klao@959
   133
       *
klao@959
   134
       * \ingroup concept
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
klao@959
   147
	NodeIt(const Path &_p) {}
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
klao@959
   155
	bool operator==(const NodeIt& e) const {return true;}
klao@959
   156
	/// Comparison operator
klao@959
   157
	bool operator!=(const NodeIt& e) 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
       * \ingroup concept
klao@959
   170
       * This class is used to fill a path with edges.
klao@959
   171
       *
klao@959
   172
       * You can push new edges to the front and to the back of the path in
klao@959
   173
       * arbitrary order then you should commit these changes to the graph.
klao@959
   174
       *
klao@959
   175
       * While the builder is active (after the first modifying
klao@959
   176
       * operation and until the call of \ref commit())
klao@959
   177
       * the underlining Path is in a
klao@959
   178
       * "transitional" state (operations on it have undefined result).
klao@959
   179
       */
klao@959
   180
      class Builder {
klao@959
   181
      public:
klao@959
   182
klao@959
   183
        Path &P;
klao@959
   184
klao@959
   185
	///\param _P the path you want to fill in.
klao@959
   186
	///
klao@959
   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.
klao@959
   193
	/// You \em must start building an empry path with this 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().
klao@959
   204
	void pushFront(const GraphEdge& e) {}
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().
klao@959
   211
	void pushBack(const GraphEdge& e) {}
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
klao@959
   218
	///If you know an reasonable upper bound of 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.
klao@959
   221
	void reserveFront(size_t r) {}
klao@959
   222
	///Reserve (back) storage for the builder in advance.
klao@959
   223
klao@959
   224
	///If you know an reasonable upper bound of 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.
klao@959
   227
	void reserveBack(size_t r) {}
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