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