COIN-OR::LEMON - Graph Library

source: lemon-0.x/lemon/path_utils.h @ 2350:eb371753e814

Last change on this file since 2350:eb371753e814 was 2350:eb371753e814, checked in by Alpar Juttner, 17 years ago

Several doc improvements.

File size: 3.9 KB
Line 
1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
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.
12 *
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
15 * purpose.
16 *
17 */
18
19
20///\ingroup paths
21///\file
22///\brief Classes for representing paths in graphs.
23///
24
25#ifndef LEMON_PATH_UTILS_H
26#define LEMON_PATH_UTILS_H
27
28#include <lemon/concepts/path.h>
29
30namespace lemon {
31
32  namespace _path_bits {
33
34    template <typename Path, typename Enable = void>
35    struct RevTagIndicator {
36      static const bool value = false;
37    };
38
39    template <typename Graph>
40    struct RevTagIndicator<
41      Graph,
42      typename enable_if<typename Graph::RevTag, void>::type
43    > {
44      static const bool value = true;
45    };
46
47    template <typename Target, typename Source,
48              typename BuildEnable = void, typename RevEnable = void>
49    struct PathCopySelector {
50      static void copy(Target& target, const Source& source) {
51        source.clear();
52        for (typename Source::EdgeIt it(source); it != INVALID; ++it) {
53          target.addBack(it);
54        }
55      }
56    };
57
58    template <typename Target, typename Source, typename BuildEnable>
59    struct PathCopySelector<
60      Target, Source, BuildEnable,
61      typename enable_if<typename Source::RevPathTag, void>::type> {
62      static void copy(Target& target, const Source& source) {
63        source.clear();
64        for (typename Source::RevIt it(source); it != INVALID; ++it) {
65          target.addFront(it);
66        }
67      }
68    };
69
70    template <typename Target, typename Source, typename RevEnable>
71    struct PathCopySelector<
72      Target, Source,
73      typename enable_if<typename Target::BuildTag, void>::type, RevEnable> {
74      static void copy(Target& target, const Source& source) {
75        target.clear();
76        target.build(source);
77      }
78    };
79
80    template <typename Target, typename Source>
81    struct PathCopySelector<
82      Target, Source,
83      typename enable_if<typename Target::BuildTag, void>::type,
84      typename enable_if<typename Source::RevPathTag, void>::type> {
85      static void copy(Target& target, const Source& source) {
86        target.clear();
87        target.buildRev(source);
88      }
89    };
90
91  }
92
93
94  /// \brief Make of copy of a path.
95  ///
96  ///  Make of copy of a path.
97  template <typename Target, typename Source>
98  void copyPath(Target& target, const Source& source) {
99    checkConcept<concepts::PathDumper<typename Source::Graph>, Source>();
100    _path_bits::PathCopySelector<Target, Source>::copy(target, source);
101  }
102
103  /// \brief Checks the path's consistency.
104  ///
105  /// Checks that each edge's target is the next's source.
106  ///
107  template <typename Graph, typename Path>
108  bool checkPath(const Graph& graph, const Path& path) {
109    typename Path::EdgeIt it(path);
110    if (it == INVALID) return true;
111    typename Graph::Node node = graph.target(it);
112    ++it;
113    while (it != INVALID) {
114      if (graph.source(it) != node) return false;
115      node = graph.target(it);
116      ++it;
117    }
118    return true;
119  }
120
121  /// \brief Gives back the source of the path
122  ///
123  /// Gives back the source of the path.
124  template <typename Graph, typename Path>
125  typename Graph::Node pathSource(const Graph& graph, const Path& path) {
126    return graph.source(path.front());
127  }
128
129  /// \brief Gives back the target of the path
130  ///
131  /// Gives back the target of the path.
132  template <typename Graph, typename Path>
133  typename Graph::Node pathTarget(const Graph& graph, const Path& path) {
134    return graph.target(path.back());
135  }
136}
137
138#endif
Note: See TracBrowser for help on using the repository browser.