hegyi@815: #define SKELETON hegyi@815: // -*- c++ -*- // hegyi@815: hegyi@815: ///\ingroup skeletons hegyi@815: ///\file hegyi@815: ///\brief Classes for representing paths in graphs. hegyi@815: alpar@921: #ifndef LEMON_PATH_H alpar@921: #define LEMON_PATH_H hegyi@815: alpar@921: #include hegyi@815: alpar@921: namespace lemon { hegyi@815: namespace skeleton { hegyi@815: /// \addtogroup skeletons hegyi@815: /// @{ hegyi@815: hegyi@815: hegyi@815: //! \brief A skeletom structure for representing directed paths in a graph. hegyi@815: //! hegyi@815: //! A skeleton structure for representing directed paths in a graph. hegyi@815: //! \param GR The graph type in which the path is. hegyi@815: //! hegyi@815: //! In a sense, the path can be treated as a graph, for is has \c NodeIt hegyi@815: //! and \c EdgeIt with the same usage. These types converts to the \c Node hegyi@815: //! and \c Edge of the original graph. hegyi@815: template hegyi@815: class Path { hegyi@815: public: hegyi@815: hegyi@815: /// Type of the underlying graph. hegyi@815: typedef /*typename*/ GR Graph; hegyi@815: /// Edge type of the underlying graph. hegyi@815: typedef typename Graph::Edge GraphEdge; hegyi@815: /// Node type of the underlying graph. hegyi@815: typedef typename Graph::Node GraphNode; hegyi@815: class NodeIt; hegyi@815: class EdgeIt; hegyi@815: hegyi@815: /// \param _G The graph in which the path is. hegyi@815: /// hegyi@815: Path(const Graph &_G) {} hegyi@815: hegyi@815: /// Length of the path. hegyi@815: size_t length() const {} hegyi@815: /// Returns whether the path is empty. hegyi@815: bool empty() const {} hegyi@815: hegyi@815: /// Resets the path to an empty path. hegyi@815: void clear() {} hegyi@815: hegyi@815: /// \brief Starting point of the path. hegyi@815: /// hegyi@815: /// Starting point of the path. hegyi@815: /// Returns INVALID if the path is empty. hegyi@815: GraphNode head() const {} hegyi@815: /// \brief End point of the path. hegyi@815: /// hegyi@815: /// End point of the path. hegyi@815: /// Returns INVALID if the path is empty. hegyi@815: GraphNode tail() const {} hegyi@815: hegyi@815: /// \brief First NodeIt/EdgeIt. hegyi@815: /// hegyi@815: /// Initializes node or edge iterator to point to the first hegyi@815: /// node or edge. hegyi@815: template hegyi@815: It& first(It &i) const { return i=It(*this); } hegyi@815: hegyi@815: /// \brief The head of an edge. hegyi@815: /// hegyi@815: /// Returns node iterator pointing to the head node of the hegyi@815: /// given edge iterator. hegyi@815: NodeIt head(const EdgeIt& e) const {} hegyi@815: hegyi@815: /// \brief The tail of an edge. hegyi@815: /// hegyi@815: /// Returns node iterator pointing to the tail node of the hegyi@815: /// given edge iterator. hegyi@815: NodeIt tail(const EdgeIt& e) const {} hegyi@815: hegyi@815: hegyi@815: /* Iterator classes */ hegyi@815: hegyi@815: /** hegyi@815: * \brief Iterator class to iterate on the edges of the paths hegyi@815: * hegyi@815: * \ingroup skeletons hegyi@815: * This class is used to iterate on the edges of the paths hegyi@815: * hegyi@815: * Of course it converts to Graph::Edge hegyi@815: * hegyi@815: */ hegyi@815: class EdgeIt { hegyi@815: public: hegyi@815: /// Default constructor hegyi@815: EdgeIt() {} hegyi@815: /// Invalid constructor hegyi@815: EdgeIt(Invalid) {} hegyi@815: /// Constructor with starting point hegyi@815: EdgeIt(const Path &_p) {} hegyi@815: hegyi@815: operator GraphEdge () const {} hegyi@815: hegyi@815: /// Next edge hegyi@815: EdgeIt& operator++() {} hegyi@815: hegyi@815: /// Comparison operator hegyi@815: bool operator==(const EdgeIt& e) const {} hegyi@815: /// Comparison operator hegyi@815: bool operator!=(const EdgeIt& e) const {} hegyi@815: // /// Comparison operator hegyi@815: // /// \todo It is not clear what is the "natural" ordering. hegyi@815: // bool operator<(const EdgeIt& e) const {} hegyi@815: hegyi@815: }; hegyi@815: hegyi@815: /** hegyi@815: * \brief Iterator class to iterate on the nodes of the paths hegyi@815: * hegyi@815: * \ingroup skeletons hegyi@815: * This class is used to iterate on the nodes of the paths hegyi@815: * hegyi@815: * Of course it converts to Graph::Node. hegyi@815: * hegyi@815: */ hegyi@815: class NodeIt { hegyi@815: public: hegyi@815: /// Default constructor hegyi@815: NodeIt() {} hegyi@815: /// Invalid constructor hegyi@815: NodeIt(Invalid) {} hegyi@815: /// Constructor with starting point hegyi@815: NodeIt(const Path &_p) {} hegyi@815: hegyi@815: ///Conversion to Graph::Node hegyi@815: operator const GraphNode& () const {} hegyi@815: /// Next node hegyi@815: NodeIt& operator++() {} hegyi@815: hegyi@815: /// Comparison operator hegyi@815: bool operator==(const NodeIt& e) const {} hegyi@815: /// Comparison operator hegyi@815: bool operator!=(const NodeIt& e) const {} hegyi@815: // /// Comparison operator hegyi@815: // /// \todo It is not clear what is the "natural" ordering. hegyi@815: // bool operator<(const NodeIt& e) const {} hegyi@815: hegyi@815: }; hegyi@815: hegyi@815: friend class Builder; hegyi@815: hegyi@815: /** hegyi@815: * \brief Class to build paths hegyi@815: * hegyi@815: * \ingroup skeletons hegyi@815: * This class is used to fill a path with edges. hegyi@815: * hegyi@815: * You can push new edges to the front and to the back of the path in hegyi@815: * arbitrary order then you should commit these changes to the graph. hegyi@815: * hegyi@815: * While the builder is active (after the first modifying hegyi@815: * operation and until the call of \ref commit()) hegyi@815: * the underlining Path is in a hegyi@815: * "transitional" state (operations on it have undefined result). hegyi@815: */ hegyi@815: class Builder { hegyi@815: public: hegyi@815: hegyi@815: Path &P; hegyi@815: hegyi@815: ///\param _P the path you want to fill in. hegyi@815: /// hegyi@815: Builder(Path &_P) : P(_P) {} hegyi@815: hegyi@815: /// Sets the starting node of the path. hegyi@815: hegyi@815: /// Sets the starting node of the path. Edge added to the path hegyi@815: /// afterwards have to be incident to this node. hegyi@815: /// You \em must start building an empry path with this functions. hegyi@815: /// (And you \em must \em not use it later). hegyi@815: /// \sa pushFront() hegyi@815: /// \sa pushBack() hegyi@815: void setStartNode(const GraphNode &) {} hegyi@815: hegyi@815: ///Push a new edge to the front of the path hegyi@815: hegyi@815: ///Push a new edge to the front of the path. hegyi@815: ///If the path is empty, you \em must call \ref setStartNode() before hegyi@815: ///the first use of \ref pushFront(). hegyi@815: void pushFront(const GraphEdge& e) {} hegyi@815: hegyi@815: ///Push a new edge to the back of the path hegyi@815: hegyi@815: ///Push a new edge to the back of the path. hegyi@815: ///If the path is empty, you \em must call \ref setStartNode() before hegyi@815: ///the first use of \ref pushBack(). hegyi@815: void pushBack(const GraphEdge& e) {} hegyi@815: hegyi@815: ///Commit the changes to the path. hegyi@815: void commit() {} hegyi@815: hegyi@815: ///Reserve (front) storage for the builder in advance. hegyi@815: hegyi@815: ///If you know an reasonable upper bound of the number of the edges hegyi@815: ///to add to the front of the path, hegyi@815: ///using this function you may speed up the building. hegyi@815: void reserveFront(size_t r) {} hegyi@815: ///Reserve (back) storage for the builder in advance. hegyi@815: hegyi@815: ///If you know an reasonable upper bound of the number of the edges hegyi@815: ///to add to the back of the path, hegyi@815: ///using this function you may speed up the building. hegyi@815: void reserveBack(size_t r) {} hegyi@815: }; hegyi@815: }; hegyi@815: hegyi@815: ///@} hegyi@815: } hegyi@815: alpar@921: } // namespace lemon hegyi@815: alpar@921: #endif // LEMON_PATH_H