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