Bug fix in Bfs class.
Patch from Peter Kovacs
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2007
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 graphs.
24 #ifndef LEMON_PATH_UTILS_H
25 #define LEMON_PATH_UTILS_H
27 #include <lemon/concepts/path.h>
31 namespace _path_bits {
33 template <typename Path, typename Enable = void>
34 struct RevTagIndicator {
35 static const bool value = false;
38 template <typename Graph>
39 struct RevTagIndicator<
41 typename enable_if<typename Graph::RevTag, void>::type
43 static const bool value = true;
46 template <typename Target, typename Source,
47 typename BuildEnable = void, typename RevEnable = void>
48 struct PathCopySelector {
49 static void copy(Target& target, const Source& source) {
51 for (typename Source::EdgeIt it(source); it != INVALID; ++it) {
57 template <typename Target, typename Source, typename BuildEnable>
58 struct PathCopySelector<
59 Target, Source, BuildEnable,
60 typename enable_if<typename Source::RevPathTag, void>::type> {
61 static void copy(Target& target, const Source& source) {
63 for (typename Source::RevEdgeIt it(source); it != INVALID; ++it) {
69 template <typename Target, typename Source, typename RevEnable>
70 struct PathCopySelector<
72 typename enable_if<typename Target::BuildTag, void>::type, RevEnable> {
73 static void copy(Target& target, const Source& source) {
79 template <typename Target, typename Source>
80 struct PathCopySelector<
82 typename enable_if<typename Target::BuildTag, void>::type,
83 typename enable_if<typename Source::RevPathTag, void>::type> {
84 static void copy(Target& target, const Source& source) {
86 target.buildRev(source);
93 /// \brief Make of copy of a path.
95 /// Make of copy of a path.
96 template <typename Target, typename Source>
97 void copyPath(Target& target, const Source& source) {
98 checkConcept<concepts::PathDumper<typename Source::Graph>, Source>();
99 _path_bits::PathCopySelector<Target, Source>::copy(target, source);
102 /// \brief Checks the path's consistency.
104 /// Checks that each edge's target is the next's source.
106 template <typename Graph, typename Path>
107 bool checkPath(const Graph& graph, const Path& path) {
108 typename Path::EdgeIt it(path);
109 if (it == INVALID) return true;
110 typename Graph::Node node = graph.target(it);
112 while (it != INVALID) {
113 if (graph.source(it) != node) return false;
114 node = graph.target(it);
120 /// \brief Gives back the source of the path
122 /// Gives back the source of the path.
123 template <typename Graph, typename Path>
124 typename Graph::Node pathSource(const Graph& graph, const Path& path) {
125 return graph.source(path.front());
128 /// \brief Gives back the target of the path
130 /// Gives back the target of the path.
131 template <typename Graph, typename Path>
132 typename Graph::Node pathTarget(const Graph& graph, const Path& path) {
133 return graph.target(path.back());