4 * This file is a part of LEMON, a generic C++ optimization library
6 * Copyright (C) 2003-2006
7 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
8 * (Egervary Research Group on Combinatorial Optimization, EGRES).
10 * Permission to use, modify and distribute this software is granted
11 * provided that this copyright notice appears in all copies. For
12 * precise terms see the accompanying LICENSE file.
14 * This software is provided "AS IS" with no warranty of any kind,
15 * express or implied, and with no claim as to its suitability for any
20 #ifndef LEMON_BITS_PRED_MAP_PATH_H
21 #define LEMON_BITS_PRED_MAP_PATH_H
25 template <typename _Graph, typename _PredMap>
28 typedef True RevPathTag;
31 typedef typename Graph::Edge Edge;
32 typedef _PredMap PredMap;
34 PredMapPath(const Graph& _graph, const PredMap& _predMap,
35 typename Graph::Node _target)
36 : graph(_graph), predMap(_predMap), target(_target) {}
40 typename Graph::Node node = target;
41 typename Graph::Edge edge;
42 while ((edge = predMap[node]) != INVALID) {
43 node = graph.source(edge);
50 return predMap[target] != INVALID;
56 RevEdgeIt(Invalid) : path(0), current(INVALID) {}
57 RevEdgeIt(const PredMapPath& _path)
58 : path(&_path), current(_path.target) {}
60 operator const typename Graph::Edge() const {
61 return path->predMap[current];
64 RevEdgeIt& operator++() {
65 current = path->graph.source(path->predMap[current]);
66 if (path->predMap[current] == INVALID) current = INVALID;
70 bool operator==(const RevEdgeIt& e) const {
71 return current == e.current;
74 bool operator!=(const RevEdgeIt& e) const {
75 return current != e.current;
78 bool operator<(const RevEdgeIt& e) const {
79 return current < e.current;
83 const PredMapPath* path;
84 typename Graph::Node current;
89 const PredMap& predMap;
90 typename Graph::Node target;
94 template <typename _Graph, typename _PredMatrixMap>
95 class PredMatrixMapPath {
97 typedef True RevPathTag;
100 typedef typename Graph::Edge Edge;
101 typedef _PredMatrixMap PredMatrixMap;
103 PredMatrixMapPath(const Graph& _graph,
104 const PredMatrixMap& _predMatrixMap,
105 typename Graph::Node _source,
106 typename Graph::Node _target)
107 : graph(_graph), predMatrixMap(_predMatrixMap),
108 source(_source), target(_target) {}
112 typename Graph::Node node = target;
113 typename Graph::Edge edge;
114 while ((edge = predMatrixMap(source, node)) != INVALID) {
115 node = graph.source(edge);
122 return source != target;
128 RevEdgeIt(Invalid) : path(0), current(INVALID) {}
129 RevEdgeIt(const PredMatrixMapPath& _path)
130 : path(&_path), current(_path.target) {}
132 operator const typename Graph::Edge() const {
133 return path->predMatrixMap(path->source, current);
136 RevEdgeIt& operator++() {
138 path->graph.source(path->predMatrixMap(path->source, current));
139 if (path->predMatrixMap(path->source, current) == INVALID)
144 bool operator==(const RevEdgeIt& e) const {
145 return current == e.current;
148 bool operator!=(const RevEdgeIt& e) const {
149 return current != e.current;
152 bool operator<(const RevEdgeIt& e) const {
153 return current < e.current;
157 const PredMatrixMapPath* path;
158 typename Graph::Node current;
163 const PredMatrixMap& predMatrixMap;
164 typename Graph::Node source;
165 typename Graph::Node target;