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