alpar@209: /* -*- mode: C++; indent-tabs-mode: nil; -*- alpar@96: * alpar@209: * This file is a part of LEMON, a generic C++ optimization library. alpar@96: * alpar@96: * Copyright (C) 2003-2008 alpar@96: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@96: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@96: * alpar@96: * Permission to use, modify and distribute this software is granted alpar@96: * provided that this copyright notice appears in all copies. For alpar@96: * precise terms see the accompanying LICENSE file. alpar@96: * alpar@96: * This software is provided "AS IS" with no warranty of any kind, alpar@96: * express or implied, and with no claim as to its suitability for any alpar@96: * purpose. alpar@96: * alpar@96: */ alpar@96: alpar@96: ///\ingroup concept alpar@96: ///\file alpar@96: ///\brief Classes for representing paths in digraphs. alpar@96: /// alpar@96: ///\todo Iterators have obsolete style alpar@96: alpar@96: #ifndef LEMON_CONCEPT_PATH_H alpar@96: #define LEMON_CONCEPT_PATH_H alpar@96: deba@220: #include alpar@96: #include alpar@96: alpar@96: namespace lemon { alpar@96: namespace concepts { alpar@96: alpar@96: /// \addtogroup concept alpar@96: /// @{ alpar@96: alpar@96: /// \brief A skeleton structure for representing directed paths in alpar@96: /// a digraph. alpar@96: /// alpar@96: /// A skeleton structure for representing directed paths in a alpar@209: /// digraph. kpeter@157: /// \tparam _Digraph The digraph type in which the path is. alpar@96: /// alpar@96: /// In a sense, the path can be treated as a list of arcs. The alpar@96: /// lemon path type stores just this list. As a consequence it alpar@96: /// cannot enumerate the nodes in the path and the zero length alpar@96: /// paths cannot store the source. alpar@96: /// alpar@96: template alpar@96: class Path { alpar@96: public: alpar@96: alpar@96: /// Type of the underlying digraph. alpar@96: typedef _Digraph Digraph; alpar@96: /// Arc type of the underlying digraph. alpar@96: typedef typename Digraph::Arc Arc; alpar@96: alpar@96: class ArcIt; alpar@96: alpar@96: /// \brief Default constructor alpar@96: Path() {} alpar@96: alpar@96: /// \brief Template constructor alpar@96: template alpar@96: Path(const CPath& cpath) {} alpar@96: alpar@96: /// \brief Template assigment alpar@96: template alpar@96: Path& operator=(const CPath& cpath) {} alpar@96: alpar@96: /// Length of the path ie. the number of arcs in the path. alpar@96: int length() const { return 0;} alpar@96: alpar@96: /// Returns whether the path is empty. alpar@96: bool empty() const { return true;} alpar@96: alpar@96: /// Resets the path to an empty path. alpar@96: void clear() {} alpar@96: ladanyi@236: /// \brief LEMON style iterator for path arcs alpar@96: /// alpar@96: /// This class is used to iterate on the arcs of the paths. alpar@96: class ArcIt { alpar@96: public: alpar@209: /// Default constructor alpar@209: ArcIt() {} alpar@209: /// Invalid constructor alpar@209: ArcIt(Invalid) {} alpar@209: /// Constructor for first arc alpar@209: ArcIt(const Path &) {} alpar@96: alpar@96: /// Conversion to Arc alpar@209: operator Arc() const { return INVALID; } alpar@96: alpar@209: /// Next arc alpar@209: ArcIt& operator++() {return *this;} alpar@96: alpar@209: /// Comparison operator alpar@209: bool operator==(const ArcIt&) const {return true;} alpar@209: /// Comparison operator alpar@209: bool operator!=(const ArcIt&) const {return true;} kpeter@212: /// Comparison operator kpeter@212: bool operator<(const ArcIt&) const {return false;} alpar@96: alpar@96: }; alpar@96: alpar@96: template alpar@96: struct Constraints { alpar@96: void constraints() { alpar@96: Path pc; alpar@96: _Path p, pp(pc); alpar@96: int l = p.length(); alpar@96: int e = p.empty(); alpar@96: p.clear(); alpar@96: alpar@96: p = pc; alpar@96: alpar@96: typename _Path::ArcIt id, ii(INVALID), i(p); alpar@96: alpar@96: ++i; alpar@96: typename Digraph::Arc ed = i; alpar@96: alpar@96: e = (i == ii); alpar@96: e = (i != ii); alpar@96: e = (i < ii); alpar@96: alpar@96: ignore_unused_variable_warning(l); alpar@96: ignore_unused_variable_warning(pp); alpar@96: ignore_unused_variable_warning(e); alpar@96: ignore_unused_variable_warning(id); alpar@96: ignore_unused_variable_warning(ii); alpar@96: ignore_unused_variable_warning(ed); alpar@96: } alpar@96: }; alpar@96: alpar@96: }; alpar@96: alpar@96: namespace _path_bits { alpar@209: alpar@96: template alpar@96: struct PathDumperConstraints { alpar@96: void constraints() { alpar@96: int l = p.length(); alpar@96: int e = p.empty(); alpar@96: alpar@96: typename _Path::ArcIt id, i(p); alpar@96: alpar@96: ++i; alpar@96: typename _Digraph::Arc ed = i; alpar@96: alpar@96: e = (i == INVALID); alpar@96: e = (i != INVALID); alpar@96: alpar@96: ignore_unused_variable_warning(l); alpar@96: ignore_unused_variable_warning(e); alpar@96: ignore_unused_variable_warning(id); alpar@96: ignore_unused_variable_warning(ed); alpar@96: } alpar@96: _Path& p; alpar@96: }; alpar@96: alpar@96: template alpar@96: struct PathDumperConstraints< alpar@209: _Digraph, _Path, alpar@96: typename enable_if::type alpar@96: > { alpar@96: void constraints() { alpar@96: int l = p.length(); alpar@96: int e = p.empty(); alpar@96: alpar@96: typename _Path::RevArcIt id, i(p); alpar@96: alpar@96: ++i; alpar@96: typename _Digraph::Arc ed = i; alpar@96: alpar@96: e = (i == INVALID); alpar@96: e = (i != INVALID); alpar@96: alpar@96: ignore_unused_variable_warning(l); alpar@96: ignore_unused_variable_warning(e); alpar@96: ignore_unused_variable_warning(id); alpar@96: ignore_unused_variable_warning(ed); alpar@96: } alpar@96: _Path& p; alpar@96: }; alpar@209: alpar@96: } alpar@96: alpar@96: alpar@96: /// \brief A skeleton structure for path dumpers. alpar@96: /// alpar@96: /// A skeleton structure for path dumpers. The path dumpers are alpar@96: /// the generalization of the paths. The path dumpers can alpar@96: /// enumerate the arcs of the path wheter in forward or in alpar@96: /// backward order. In most time these classes are not used alpar@96: /// directly rather it used to assign a dumped class to a real alpar@96: /// path type. alpar@96: /// alpar@96: /// The main purpose of this concept is that the shortest path alpar@96: /// algorithms can enumerate easily the arcs in reverse order. alpar@96: /// If we would like to give back a real path from these alpar@96: /// algorithms then we should create a temporarly path object. In ladanyi@236: /// LEMON such algorithms gives back a path dumper what can alpar@96: /// assigned to a real path and the dumpers can be implemented as alpar@96: /// an adaptor class to the predecessor map. alpar@96: kpeter@157: /// \tparam _Digraph The digraph type in which the path is. alpar@96: /// alpar@96: /// The paths can be constructed from any path type by a alpar@96: /// template constructor or a template assignment operator. alpar@209: /// alpar@96: template alpar@96: class PathDumper { alpar@96: public: alpar@96: alpar@96: /// Type of the underlying digraph. alpar@96: typedef _Digraph Digraph; alpar@96: /// Arc type of the underlying digraph. alpar@96: typedef typename Digraph::Arc Arc; alpar@96: alpar@96: /// Length of the path ie. the number of arcs in the path. alpar@96: int length() const { return 0;} alpar@96: alpar@96: /// Returns whether the path is empty. alpar@96: bool empty() const { return true;} alpar@96: alpar@96: /// \brief Forward or reverse dumping alpar@96: /// alpar@96: /// If the RevPathTag is defined and true then reverse dumping alpar@96: /// is provided in the path dumper. In this case instead of the alpar@96: /// ArcIt the RevArcIt iterator should be implemented in the alpar@96: /// dumper. alpar@96: typedef False RevPathTag; alpar@96: ladanyi@236: /// \brief LEMON style iterator for path arcs alpar@96: /// alpar@96: /// This class is used to iterate on the arcs of the paths. alpar@96: class ArcIt { alpar@96: public: alpar@209: /// Default constructor alpar@209: ArcIt() {} alpar@209: /// Invalid constructor alpar@209: ArcIt(Invalid) {} alpar@209: /// Constructor for first arc alpar@209: ArcIt(const PathDumper&) {} alpar@96: alpar@96: /// Conversion to Arc alpar@209: operator Arc() const { return INVALID; } alpar@96: alpar@209: /// Next arc alpar@209: ArcIt& operator++() {return *this;} alpar@96: alpar@209: /// Comparison operator alpar@209: bool operator==(const ArcIt&) const {return true;} alpar@209: /// Comparison operator alpar@209: bool operator!=(const ArcIt&) const {return true;} kpeter@212: /// Comparison operator kpeter@212: bool operator<(const ArcIt&) const {return false;} alpar@96: alpar@96: }; alpar@96: ladanyi@236: /// \brief LEMON style iterator for path arcs alpar@96: /// alpar@96: /// This class is used to iterate on the arcs of the paths in alpar@96: /// reverse direction. alpar@96: class RevArcIt { alpar@96: public: alpar@209: /// Default constructor alpar@209: RevArcIt() {} alpar@209: /// Invalid constructor alpar@209: RevArcIt(Invalid) {} alpar@209: /// Constructor for first arc alpar@209: RevArcIt(const PathDumper &) {} alpar@96: alpar@96: /// Conversion to Arc alpar@209: operator Arc() const { return INVALID; } alpar@96: alpar@209: /// Next arc alpar@209: RevArcIt& operator++() {return *this;} alpar@96: alpar@209: /// Comparison operator alpar@209: bool operator==(const RevArcIt&) const {return true;} alpar@209: /// Comparison operator alpar@209: bool operator!=(const RevArcIt&) const {return true;} kpeter@212: /// Comparison operator kpeter@212: bool operator<(const RevArcIt&) const {return false;} alpar@96: alpar@96: }; alpar@96: alpar@96: template alpar@96: struct Constraints { alpar@96: void constraints() { alpar@96: function_requires<_path_bits:: alpar@96: PathDumperConstraints >(); alpar@96: } alpar@96: }; alpar@96: alpar@96: }; alpar@96: alpar@96: alpar@96: ///@} alpar@96: } alpar@96: alpar@96: } // namespace lemon alpar@96: alpar@96: #endif // LEMON_CONCEPT_PATH_H