1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
 
     3  * This file is a part of LEMON, a generic C++ optimization library.
 
     5  * Copyright (C) 2003-2008
 
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
 
     9  * Permission to use, modify and distribute this software is granted
 
    10  * provided that this copyright notice appears in all copies. For
 
    11  * precise terms see the accompanying LICENSE file.
 
    13  * This software is provided "AS IS" with no warranty of any kind,
 
    14  * express or implied, and with no claim as to its suitability for any
 
    21 ///\brief Classes for representing paths in digraphs.
 
    23 ///\todo Iterators have obsolete style
 
    25 #ifndef LEMON_CONCEPT_PATH_H
 
    26 #define LEMON_CONCEPT_PATH_H
 
    28 #include <lemon/core.h>
 
    29 #include <lemon/concept_check.h>
 
    34     /// \addtogroup concept
 
    37     /// \brief A skeleton structure for representing directed paths in
 
    40     /// A skeleton structure for representing directed paths in a
 
    42     /// \tparam _Digraph The digraph type in which the path is.
 
    44     /// In a sense, the path can be treated as a list of arcs. The
 
    45     /// lemon path type stores just this list. As a consequence it
 
    46     /// cannot enumerate the nodes in the path and the zero length
 
    47     /// paths cannot store the source.
 
    49     template <typename _Digraph>
 
    53       /// Type of the underlying digraph.
 
    54       typedef _Digraph Digraph;
 
    55       /// Arc type of the underlying digraph.
 
    56       typedef typename Digraph::Arc Arc;
 
    60       /// \brief Default constructor
 
    63       /// \brief Template constructor
 
    64       template <typename CPath>
 
    65       Path(const CPath& cpath) {}
 
    67       /// \brief Template assigment
 
    68       template <typename CPath>
 
    69       Path& operator=(const CPath& cpath) {}
 
    71       /// Length of the path ie. the number of arcs in the path.
 
    72       int length() const { return 0;}
 
    74       /// Returns whether the path is empty.
 
    75       bool empty() const { return true;}
 
    77       /// Resets the path to an empty path.
 
    80       /// \brief Lemon style iterator for path arcs
 
    82       /// This class is used to iterate on the arcs of the paths.
 
    85         /// Default constructor
 
    87         /// Invalid constructor
 
    89         /// Constructor for first arc
 
    90         ArcIt(const Path &) {}
 
    93         operator Arc() const { return INVALID; }
 
    96         ArcIt& operator++() {return *this;}
 
    98         /// Comparison operator
 
    99         bool operator==(const ArcIt&) const {return true;}
 
   100         /// Comparison operator
 
   101         bool operator!=(const ArcIt&) const {return true;}
 
   102         /// Comparison operator
 
   103         bool operator<(const ArcIt&) const {return false;}
 
   107       template <typename _Path>
 
   118           typename _Path::ArcIt id, ii(INVALID), i(p);
 
   121           typename Digraph::Arc ed = i;
 
   127           ignore_unused_variable_warning(l);
 
   128           ignore_unused_variable_warning(pp);
 
   129           ignore_unused_variable_warning(e);
 
   130           ignore_unused_variable_warning(id);
 
   131           ignore_unused_variable_warning(ii);
 
   132           ignore_unused_variable_warning(ed);
 
   138     namespace _path_bits {
 
   140       template <typename _Digraph, typename _Path, typename RevPathTag = void>
 
   141       struct PathDumperConstraints {
 
   146           typename _Path::ArcIt id, i(p);
 
   149           typename _Digraph::Arc ed = i;
 
   154           ignore_unused_variable_warning(l);
 
   155           ignore_unused_variable_warning(e);
 
   156           ignore_unused_variable_warning(id);
 
   157           ignore_unused_variable_warning(ed);
 
   162       template <typename _Digraph, typename _Path>
 
   163       struct PathDumperConstraints<
 
   165         typename enable_if<typename _Path::RevPathTag, void>::type
 
   171           typename _Path::RevArcIt id, i(p);
 
   174           typename _Digraph::Arc ed = i;
 
   179           ignore_unused_variable_warning(l);
 
   180           ignore_unused_variable_warning(e);
 
   181           ignore_unused_variable_warning(id);
 
   182           ignore_unused_variable_warning(ed);
 
   190     /// \brief A skeleton structure for path dumpers.
 
   192     /// A skeleton structure for path dumpers. The path dumpers are
 
   193     /// the generalization of the paths. The path dumpers can
 
   194     /// enumerate the arcs of the path wheter in forward or in
 
   195     /// backward order.  In most time these classes are not used
 
   196     /// directly rather it used to assign a dumped class to a real
 
   199     /// The main purpose of this concept is that the shortest path
 
   200     /// algorithms can enumerate easily the arcs in reverse order.
 
   201     /// If we would like to give back a real path from these
 
   202     /// algorithms then we should create a temporarly path object. In
 
   203     /// Lemon such algorithms gives back a path dumper what can
 
   204     /// assigned to a real path and the dumpers can be implemented as
 
   205     /// an adaptor class to the predecessor map.
 
   207     /// \tparam _Digraph  The digraph type in which the path is.
 
   209     /// The paths can be constructed from any path type by a
 
   210     /// template constructor or a template assignment operator.
 
   212     template <typename _Digraph>
 
   216       /// Type of the underlying digraph.
 
   217       typedef _Digraph Digraph;
 
   218       /// Arc type of the underlying digraph.
 
   219       typedef typename Digraph::Arc Arc;
 
   221       /// Length of the path ie. the number of arcs in the path.
 
   222       int length() const { return 0;}
 
   224       /// Returns whether the path is empty.
 
   225       bool empty() const { return true;}
 
   227       /// \brief Forward or reverse dumping
 
   229       /// If the RevPathTag is defined and true then reverse dumping
 
   230       /// is provided in the path dumper. In this case instead of the
 
   231       /// ArcIt the RevArcIt iterator should be implemented in the
 
   233       typedef False RevPathTag;
 
   235       /// \brief Lemon style iterator for path arcs
 
   237       /// This class is used to iterate on the arcs of the paths.
 
   240         /// Default constructor
 
   242         /// Invalid constructor
 
   244         /// Constructor for first arc
 
   245         ArcIt(const PathDumper&) {}
 
   247         /// Conversion to Arc
 
   248         operator Arc() const { return INVALID; }
 
   251         ArcIt& operator++() {return *this;}
 
   253         /// Comparison operator
 
   254         bool operator==(const ArcIt&) const {return true;}
 
   255         /// Comparison operator
 
   256         bool operator!=(const ArcIt&) const {return true;}
 
   257         /// Comparison operator
 
   258         bool operator<(const ArcIt&) const {return false;}
 
   262       /// \brief Lemon style iterator for path arcs
 
   264       /// This class is used to iterate on the arcs of the paths in
 
   265       /// reverse direction.
 
   268         /// Default constructor
 
   270         /// Invalid constructor
 
   272         /// Constructor for first arc
 
   273         RevArcIt(const PathDumper &) {}
 
   275         /// Conversion to Arc
 
   276         operator Arc() const { return INVALID; }
 
   279         RevArcIt& operator++() {return *this;}
 
   281         /// Comparison operator
 
   282         bool operator==(const RevArcIt&) const {return true;}
 
   283         /// Comparison operator
 
   284         bool operator!=(const RevArcIt&) const {return true;}
 
   285         /// Comparison operator
 
   286         bool operator<(const RevArcIt&) const {return false;}
 
   290       template <typename _Path>
 
   293           function_requires<_path_bits::
 
   294             PathDumperConstraints<Digraph, _Path> >();
 
   306 #endif // LEMON_CONCEPT_PATH_H