deba@2335
|
1 |
/* -*- C++ -*-
|
deba@2335
|
2 |
*
|
deba@2335
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
deba@2335
|
4 |
*
|
alpar@2553
|
5 |
* Copyright (C) 2003-2008
|
deba@2335
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
deba@2335
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
deba@2335
|
8 |
*
|
deba@2335
|
9 |
* Permission to use, modify and distribute this software is granted
|
deba@2335
|
10 |
* provided that this copyright notice appears in all copies. For
|
deba@2335
|
11 |
* precise terms see the accompanying LICENSE file.
|
deba@2335
|
12 |
*
|
deba@2335
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
deba@2335
|
14 |
* express or implied, and with no claim as to its suitability for any
|
deba@2335
|
15 |
* purpose.
|
deba@2335
|
16 |
*
|
deba@2335
|
17 |
*/
|
deba@2335
|
18 |
|
deba@2335
|
19 |
#ifndef LEMON_BITS_PRED_MAP_PATH_H
|
deba@2335
|
20 |
#define LEMON_BITS_PRED_MAP_PATH_H
|
deba@2335
|
21 |
|
deba@2335
|
22 |
namespace lemon {
|
deba@2335
|
23 |
|
deba@2335
|
24 |
template <typename _Graph, typename _PredMap>
|
deba@2335
|
25 |
class PredMapPath {
|
deba@2335
|
26 |
public:
|
deba@2335
|
27 |
typedef True RevPathTag;
|
deba@2335
|
28 |
|
deba@2335
|
29 |
typedef _Graph Graph;
|
deba@2335
|
30 |
typedef typename Graph::Edge Edge;
|
deba@2335
|
31 |
typedef _PredMap PredMap;
|
deba@2335
|
32 |
|
deba@2335
|
33 |
PredMapPath(const Graph& _graph, const PredMap& _predMap,
|
deba@2335
|
34 |
typename Graph::Node _target)
|
deba@2335
|
35 |
: graph(_graph), predMap(_predMap), target(_target) {}
|
deba@2335
|
36 |
|
deba@2335
|
37 |
int length() const {
|
deba@2335
|
38 |
int len = 0;
|
deba@2335
|
39 |
typename Graph::Node node = target;
|
deba@2335
|
40 |
typename Graph::Edge edge;
|
deba@2335
|
41 |
while ((edge = predMap[node]) != INVALID) {
|
deba@2335
|
42 |
node = graph.source(edge);
|
deba@2335
|
43 |
++len;
|
deba@2335
|
44 |
}
|
deba@2335
|
45 |
return len;
|
deba@2335
|
46 |
}
|
deba@2335
|
47 |
|
deba@2335
|
48 |
bool empty() const {
|
deba@2335
|
49 |
return predMap[target] != INVALID;
|
deba@2335
|
50 |
}
|
deba@2335
|
51 |
|
deba@2357
|
52 |
class RevEdgeIt {
|
deba@2335
|
53 |
public:
|
deba@2357
|
54 |
RevEdgeIt() {}
|
deba@2357
|
55 |
RevEdgeIt(Invalid) : path(0), current(INVALID) {}
|
deba@2357
|
56 |
RevEdgeIt(const PredMapPath& _path)
|
deba@2467
|
57 |
: path(&_path), current(_path.target) {
|
deba@2467
|
58 |
if (path->predMap[current] == INVALID) current = INVALID;
|
deba@2467
|
59 |
}
|
deba@2335
|
60 |
|
deba@2335
|
61 |
operator const typename Graph::Edge() const {
|
deba@2335
|
62 |
return path->predMap[current];
|
deba@2335
|
63 |
}
|
deba@2335
|
64 |
|
deba@2357
|
65 |
RevEdgeIt& operator++() {
|
deba@2335
|
66 |
current = path->graph.source(path->predMap[current]);
|
deba@2335
|
67 |
if (path->predMap[current] == INVALID) current = INVALID;
|
deba@2335
|
68 |
return *this;
|
deba@2335
|
69 |
}
|
deba@2335
|
70 |
|
deba@2357
|
71 |
bool operator==(const RevEdgeIt& e) const {
|
deba@2335
|
72 |
return current == e.current;
|
deba@2335
|
73 |
}
|
deba@2335
|
74 |
|
deba@2357
|
75 |
bool operator!=(const RevEdgeIt& e) const {
|
deba@2335
|
76 |
return current != e.current;
|
deba@2335
|
77 |
}
|
deba@2335
|
78 |
|
deba@2357
|
79 |
bool operator<(const RevEdgeIt& e) const {
|
deba@2335
|
80 |
return current < e.current;
|
deba@2335
|
81 |
}
|
deba@2335
|
82 |
|
deba@2335
|
83 |
private:
|
deba@2335
|
84 |
const PredMapPath* path;
|
deba@2335
|
85 |
typename Graph::Node current;
|
deba@2335
|
86 |
};
|
deba@2335
|
87 |
|
deba@2335
|
88 |
private:
|
deba@2335
|
89 |
const Graph& graph;
|
deba@2335
|
90 |
const PredMap& predMap;
|
deba@2335
|
91 |
typename Graph::Node target;
|
deba@2335
|
92 |
};
|
deba@2335
|
93 |
|
deba@2335
|
94 |
|
deba@2335
|
95 |
template <typename _Graph, typename _PredMatrixMap>
|
deba@2335
|
96 |
class PredMatrixMapPath {
|
deba@2335
|
97 |
public:
|
deba@2335
|
98 |
typedef True RevPathTag;
|
deba@2335
|
99 |
|
deba@2335
|
100 |
typedef _Graph Graph;
|
deba@2335
|
101 |
typedef typename Graph::Edge Edge;
|
deba@2335
|
102 |
typedef _PredMatrixMap PredMatrixMap;
|
deba@2335
|
103 |
|
deba@2335
|
104 |
PredMatrixMapPath(const Graph& _graph,
|
deba@2335
|
105 |
const PredMatrixMap& _predMatrixMap,
|
deba@2335
|
106 |
typename Graph::Node _source,
|
deba@2335
|
107 |
typename Graph::Node _target)
|
deba@2335
|
108 |
: graph(_graph), predMatrixMap(_predMatrixMap),
|
deba@2335
|
109 |
source(_source), target(_target) {}
|
deba@2335
|
110 |
|
deba@2335
|
111 |
int length() const {
|
deba@2335
|
112 |
int len = 0;
|
deba@2335
|
113 |
typename Graph::Node node = target;
|
deba@2335
|
114 |
typename Graph::Edge edge;
|
deba@2335
|
115 |
while ((edge = predMatrixMap(source, node)) != INVALID) {
|
deba@2335
|
116 |
node = graph.source(edge);
|
deba@2335
|
117 |
++len;
|
deba@2335
|
118 |
}
|
deba@2335
|
119 |
return len;
|
deba@2335
|
120 |
}
|
deba@2335
|
121 |
|
deba@2335
|
122 |
bool empty() const {
|
deba@2335
|
123 |
return source != target;
|
deba@2335
|
124 |
}
|
deba@2335
|
125 |
|
deba@2357
|
126 |
class RevEdgeIt {
|
deba@2335
|
127 |
public:
|
deba@2357
|
128 |
RevEdgeIt() {}
|
deba@2357
|
129 |
RevEdgeIt(Invalid) : path(0), current(INVALID) {}
|
deba@2357
|
130 |
RevEdgeIt(const PredMatrixMapPath& _path)
|
deba@2467
|
131 |
: path(&_path), current(_path.target) {
|
deba@2467
|
132 |
if (path->predMatrixMap(path->source, current) == INVALID)
|
deba@2467
|
133 |
current = INVALID;
|
deba@2467
|
134 |
}
|
deba@2335
|
135 |
|
deba@2335
|
136 |
operator const typename Graph::Edge() const {
|
deba@2335
|
137 |
return path->predMatrixMap(path->source, current);
|
deba@2335
|
138 |
}
|
deba@2335
|
139 |
|
deba@2357
|
140 |
RevEdgeIt& operator++() {
|
deba@2335
|
141 |
current =
|
deba@2335
|
142 |
path->graph.source(path->predMatrixMap(path->source, current));
|
deba@2335
|
143 |
if (path->predMatrixMap(path->source, current) == INVALID)
|
deba@2335
|
144 |
current = INVALID;
|
deba@2335
|
145 |
return *this;
|
deba@2335
|
146 |
}
|
deba@2335
|
147 |
|
deba@2357
|
148 |
bool operator==(const RevEdgeIt& e) const {
|
deba@2335
|
149 |
return current == e.current;
|
deba@2335
|
150 |
}
|
deba@2335
|
151 |
|
deba@2357
|
152 |
bool operator!=(const RevEdgeIt& e) const {
|
deba@2335
|
153 |
return current != e.current;
|
deba@2335
|
154 |
}
|
deba@2335
|
155 |
|
deba@2357
|
156 |
bool operator<(const RevEdgeIt& e) const {
|
deba@2335
|
157 |
return current < e.current;
|
deba@2335
|
158 |
}
|
deba@2335
|
159 |
|
deba@2335
|
160 |
private:
|
deba@2335
|
161 |
const PredMatrixMapPath* path;
|
deba@2335
|
162 |
typename Graph::Node current;
|
deba@2335
|
163 |
};
|
deba@2335
|
164 |
|
deba@2335
|
165 |
private:
|
deba@2335
|
166 |
const Graph& graph;
|
deba@2335
|
167 |
const PredMatrixMap& predMatrixMap;
|
deba@2335
|
168 |
typename Graph::Node source;
|
deba@2335
|
169 |
typename Graph::Node target;
|
deba@2335
|
170 |
};
|
deba@2335
|
171 |
|
deba@2335
|
172 |
}
|
deba@2335
|
173 |
|
deba@2335
|
174 |
#endif
|