marci@174
|
1 |
// -*- c++ -*-
|
marci@259
|
2 |
#ifndef HUGO_GRAPH_WRAPPER_H
|
marci@259
|
3 |
#define HUGO_GRAPH_WRAPPER_H
|
marci@76
|
4 |
|
marci@174
|
5 |
#include <invalid.h>
|
marci@174
|
6 |
|
alpar@105
|
7 |
namespace hugo {
|
marci@76
|
8 |
|
marci@76
|
9 |
template<typename Graph>
|
marci@76
|
10 |
class TrivGraphWrapper {
|
marci@199
|
11 |
protected:
|
marci@76
|
12 |
Graph* graph;
|
marci@76
|
13 |
|
marci@76
|
14 |
public:
|
marci@303
|
15 |
typedef Graph ParentGraph;
|
marci@303
|
16 |
|
marci@303
|
17 |
// TrivGraphWrapper() : graph(0) { }
|
marci@303
|
18 |
TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@303
|
19 |
// void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@303
|
20 |
// Graph& getGraph() const { return *graph; }
|
marci@76
|
21 |
|
marci@174
|
22 |
typedef typename Graph::Node Node;
|
marci@265
|
23 |
class NodeIt : public Graph::NodeIt {
|
marci@265
|
24 |
public:
|
marci@265
|
25 |
NodeIt() { }
|
marci@265
|
26 |
NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { }
|
marci@265
|
27 |
NodeIt(const Invalid& i) : Graph::NodeIt(i) { }
|
marci@265
|
28 |
NodeIt(const TrivGraphWrapper<Graph>& _G) :
|
marci@265
|
29 |
Graph::NodeIt(*(_G.graph)) { }
|
marci@265
|
30 |
};
|
marci@174
|
31 |
typedef typename Graph::Edge Edge;
|
marci@265
|
32 |
class OutEdgeIt : public Graph::OutEdgeIt {
|
marci@265
|
33 |
public:
|
marci@265
|
34 |
OutEdgeIt() { }
|
marci@265
|
35 |
OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { }
|
marci@265
|
36 |
OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { }
|
marci@265
|
37 |
OutEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) :
|
marci@265
|
38 |
Graph::OutEdgeIt(*(_G.graph), n) { }
|
marci@265
|
39 |
};
|
marci@265
|
40 |
class InEdgeIt : public Graph::InEdgeIt {
|
marci@265
|
41 |
public:
|
marci@265
|
42 |
InEdgeIt() { }
|
marci@265
|
43 |
InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { }
|
marci@265
|
44 |
InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { }
|
marci@265
|
45 |
InEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) :
|
marci@265
|
46 |
Graph::InEdgeIt(*(_G.graph), n) { }
|
marci@265
|
47 |
};
|
marci@155
|
48 |
//typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@265
|
49 |
class EdgeIt : public Graph::EdgeIt {
|
marci@265
|
50 |
public:
|
marci@265
|
51 |
EdgeIt() { }
|
marci@265
|
52 |
EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { }
|
marci@265
|
53 |
EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { }
|
marci@265
|
54 |
EdgeIt(const TrivGraphWrapper<Graph>& _G) :
|
marci@265
|
55 |
Graph::EdgeIt(*(_G.graph)) { }
|
marci@265
|
56 |
};
|
marci@168
|
57 |
|
marci@265
|
58 |
NodeIt& first(NodeIt& i) const {
|
marci@265
|
59 |
i=NodeIt(*this);
|
marci@265
|
60 |
return i;
|
marci@265
|
61 |
}
|
marci@265
|
62 |
EdgeIt& first(EdgeIt& i) const {
|
marci@265
|
63 |
i=EdgeIt(*this);
|
marci@265
|
64 |
return i;
|
marci@265
|
65 |
}
|
marci@265
|
66 |
// template<typename I> I& first(I& i) const {
|
marci@265
|
67 |
// i=I(*this);
|
marci@265
|
68 |
// return i;
|
marci@265
|
69 |
// }
|
marci@265
|
70 |
OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
|
marci@265
|
71 |
i=OutEdgeIt(*this, p);
|
marci@265
|
72 |
return i;
|
marci@265
|
73 |
}
|
marci@265
|
74 |
InEdgeIt& first(InEdgeIt& i, const Node& p) const {
|
marci@265
|
75 |
i=InEdgeIt(*this, p);
|
marci@265
|
76 |
return i;
|
marci@265
|
77 |
}
|
marci@265
|
78 |
// template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@265
|
79 |
// i=I(*this, p);
|
marci@265
|
80 |
// return i;
|
marci@265
|
81 |
// }
|
marci@76
|
82 |
|
marci@265
|
83 |
// template<typename I> I getNext(const I& i) const {
|
marci@265
|
84 |
// return graph->getNext(i); }
|
marci@265
|
85 |
template<typename I> I& next(I &i) const { graph->next(i); return i; }
|
marci@76
|
86 |
|
marci@76
|
87 |
template< typename It > It first() const {
|
marci@303
|
88 |
It e; this->first(e); return e; }
|
marci@76
|
89 |
|
marci@174
|
90 |
template< typename It > It first(const Node& v) const {
|
marci@303
|
91 |
It e; this->first(e, v); return e; }
|
marci@76
|
92 |
|
marci@174
|
93 |
Node head(const Edge& e) const { return graph->head(e); }
|
marci@174
|
94 |
Node tail(const Edge& e) const { return graph->tail(e); }
|
marci@155
|
95 |
|
marci@303
|
96 |
template<typename I> bool valid(const I& i) const {
|
marci@303
|
97 |
return graph->valid(i); }
|
marci@155
|
98 |
|
marci@155
|
99 |
//template<typename I> void setInvalid(const I &i);
|
marci@155
|
100 |
//{ return graph->setInvalid(i); }
|
marci@155
|
101 |
|
marci@155
|
102 |
int nodeNum() const { return graph->nodeNum(); }
|
marci@155
|
103 |
int edgeNum() const { return graph->edgeNum(); }
|
marci@76
|
104 |
|
marci@174
|
105 |
template<typename I> Node aNode(const I& e) const {
|
marci@76
|
106 |
return graph->aNode(e); }
|
marci@174
|
107 |
template<typename I> Node bNode(const I& e) const {
|
marci@76
|
108 |
return graph->bNode(e); }
|
marci@76
|
109 |
|
marci@174
|
110 |
Node addNode() const { return graph->addNode(); }
|
marci@174
|
111 |
Edge addEdge(const Node& tail, const Node& head) const {
|
marci@76
|
112 |
return graph->addEdge(tail, head); }
|
marci@76
|
113 |
|
marci@76
|
114 |
template<typename I> void erase(const I& i) const { graph->erase(i); }
|
marci@76
|
115 |
|
marci@76
|
116 |
void clear() const { graph->clear(); }
|
marci@155
|
117 |
|
marci@76
|
118 |
template<typename T> class NodeMap : public Graph::NodeMap<T> {
|
marci@76
|
119 |
public:
|
marci@266
|
120 |
NodeMap(const TrivGraphWrapper<Graph>& _G) :
|
marci@265
|
121 |
Graph::NodeMap<T>(*(_G.graph)) { }
|
marci@155
|
122 |
NodeMap(const TrivGraphWrapper<Graph>& _G, T a) :
|
marci@265
|
123 |
Graph::NodeMap<T>(*(_G.graph), a) { }
|
marci@76
|
124 |
};
|
marci@168
|
125 |
|
marci@155
|
126 |
template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
|
marci@155
|
127 |
public:
|
marci@266
|
128 |
EdgeMap(const TrivGraphWrapper<Graph>& _G) :
|
marci@265
|
129 |
Graph::EdgeMap<T>(*(_G.graph)) { }
|
marci@155
|
130 |
EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) :
|
marci@265
|
131 |
Graph::EdgeMap<T>(*(_G.graph), a) { }
|
marci@155
|
132 |
};
|
marci@266
|
133 |
|
marci@303
|
134 |
// template<typename Map, typename T> class NodeMapWrapper {
|
marci@303
|
135 |
// protected:
|
marci@303
|
136 |
// Map* map;
|
marci@303
|
137 |
// public:
|
marci@303
|
138 |
// NodeMapWrapper(Map& _map) : map(&_map) { }
|
marci@303
|
139 |
// void set(Node n, T a) { map->set(n, a); }
|
marci@303
|
140 |
// T get(Node n) const { return map->get(n); }
|
marci@303
|
141 |
// };
|
marci@266
|
142 |
|
marci@303
|
143 |
// template<typename Map, typename T> class EdgeMapWrapper {
|
marci@303
|
144 |
// protected:
|
marci@303
|
145 |
// Map* map;
|
marci@303
|
146 |
// public:
|
marci@303
|
147 |
// EdgeMapWrapper(Map& _map) : map(&_map) { }
|
marci@303
|
148 |
// void set(Edge n, T a) { map->set(n, a); }
|
marci@303
|
149 |
// T get(Edge n) const { return map->get(n); }
|
marci@303
|
150 |
// };
|
marci@76
|
151 |
};
|
marci@76
|
152 |
|
marci@303
|
153 |
|
marci@303
|
154 |
template<typename Graph>
|
marci@303
|
155 |
class GraphWrapper {
|
marci@212
|
156 |
protected:
|
marci@303
|
157 |
Graph* graph;
|
marci@212
|
158 |
|
marci@212
|
159 |
public:
|
marci@303
|
160 |
typedef Graph ParentGraph;
|
marci@212
|
161 |
|
marci@303
|
162 |
// GraphWrapper() : graph(0) { }
|
marci@303
|
163 |
GraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@303
|
164 |
// void setGraph(Graph& _graph) { graph=&_graph; }
|
marci@303
|
165 |
// Graph& getGraph() const { return *graph; }
|
marci@303
|
166 |
|
marci@303
|
167 |
typedef typename Graph::Node Node;
|
marci@303
|
168 |
class NodeIt : public Graph::NodeIt {
|
marci@265
|
169 |
public:
|
marci@265
|
170 |
NodeIt() { }
|
marci@303
|
171 |
NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { }
|
marci@303
|
172 |
NodeIt(const Invalid& i) : Graph::NodeIt(i) { }
|
marci@303
|
173 |
NodeIt(const GraphWrapper<Graph>& _G) :
|
marci@303
|
174 |
Graph::NodeIt(*(_G.graph)) { }
|
marci@265
|
175 |
};
|
marci@303
|
176 |
typedef typename Graph::Edge Edge;
|
marci@303
|
177 |
class OutEdgeIt : public Graph::OutEdgeIt {
|
marci@265
|
178 |
public:
|
marci@265
|
179 |
OutEdgeIt() { }
|
marci@303
|
180 |
OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { }
|
marci@303
|
181 |
OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { }
|
marci@303
|
182 |
OutEdgeIt(const GraphWrapper<Graph>& _G, const Node& n) :
|
marci@303
|
183 |
Graph::OutEdgeIt(*(_G.graph), n) { }
|
marci@265
|
184 |
};
|
marci@303
|
185 |
class InEdgeIt : public Graph::InEdgeIt {
|
marci@265
|
186 |
public:
|
marci@265
|
187 |
InEdgeIt() { }
|
marci@303
|
188 |
InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { }
|
marci@303
|
189 |
InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { }
|
marci@303
|
190 |
InEdgeIt(const GraphWrapper<Graph>& _G, const Node& n) :
|
marci@303
|
191 |
Graph::InEdgeIt(*(_G.graph), n) { }
|
marci@265
|
192 |
};
|
marci@303
|
193 |
//typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@303
|
194 |
class EdgeIt : public Graph::EdgeIt {
|
marci@265
|
195 |
public:
|
marci@265
|
196 |
EdgeIt() { }
|
marci@303
|
197 |
EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { }
|
marci@303
|
198 |
EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { }
|
marci@303
|
199 |
EdgeIt(const GraphWrapper<Graph>& _G) :
|
marci@303
|
200 |
Graph::EdgeIt(*(_G.graph)) { }
|
marci@265
|
201 |
};
|
marci@303
|
202 |
|
marci@303
|
203 |
NodeIt& first(NodeIt& i) const {
|
marci@303
|
204 |
i=NodeIt(*this);
|
marci@265
|
205 |
return i;
|
marci@265
|
206 |
}
|
marci@303
|
207 |
EdgeIt& first(EdgeIt& i) const {
|
marci@303
|
208 |
i=EdgeIt(*this);
|
marci@303
|
209 |
return i;
|
marci@265
|
210 |
}
|
marci@303
|
211 |
// template<typename I> I& first(I& i) const {
|
marci@303
|
212 |
// i=I(*this);
|
marci@303
|
213 |
// return i;
|
marci@303
|
214 |
// }
|
marci@303
|
215 |
OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
|
marci@303
|
216 |
i=OutEdgeIt(*this, p);
|
marci@303
|
217 |
return i;
|
marci@303
|
218 |
}
|
marci@303
|
219 |
InEdgeIt& first(InEdgeIt& i, const Node& p) const {
|
marci@303
|
220 |
i=InEdgeIt(*this, p);
|
marci@303
|
221 |
return i;
|
marci@303
|
222 |
}
|
marci@303
|
223 |
// template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@303
|
224 |
// i=I(*this, p);
|
marci@303
|
225 |
// return i;
|
marci@303
|
226 |
// }
|
marci@212
|
227 |
|
marci@303
|
228 |
// template<typename I> I getNext(const I& i) const {
|
marci@303
|
229 |
// return gw.getNext(i); }
|
marci@303
|
230 |
template<typename I> I& next(I &i) const { graph->next(i); return i; }
|
marci@212
|
231 |
|
marci@212
|
232 |
template< typename It > It first() const {
|
marci@212
|
233 |
It e; this->first(e); return e; }
|
marci@212
|
234 |
|
marci@212
|
235 |
template< typename It > It first(const Node& v) const {
|
marci@212
|
236 |
It e; this->first(e, v); return e; }
|
marci@212
|
237 |
|
marci@303
|
238 |
Node head(const Edge& e) const { return graph->head(e); }
|
marci@303
|
239 |
Node tail(const Edge& e) const { return graph->tail(e); }
|
marci@212
|
240 |
|
marci@303
|
241 |
template<typename I> bool valid(const I& i) const {
|
marci@303
|
242 |
return graph->valid(i); }
|
marci@212
|
243 |
|
marci@212
|
244 |
//template<typename I> void setInvalid(const I &i);
|
marci@212
|
245 |
//{ return graph->setInvalid(i); }
|
marci@212
|
246 |
|
marci@303
|
247 |
int nodeNum() const { return graph->nodeNum(); }
|
marci@303
|
248 |
int edgeNum() const { return graph->edgeNum(); }
|
marci@212
|
249 |
|
marci@303
|
250 |
template<typename I> Node aNode(const I& e) const {
|
marci@303
|
251 |
return graph->aNode(e); }
|
marci@303
|
252 |
template<typename I> Node bNode(const I& e) const {
|
marci@303
|
253 |
return graph->bNode(e); }
|
marci@212
|
254 |
|
marci@303
|
255 |
Node addNode() const { return graph->addNode(); }
|
marci@212
|
256 |
Edge addEdge(const Node& tail, const Node& head) const {
|
marci@303
|
257 |
return graph->addEdge(tail, head); }
|
marci@212
|
258 |
|
marci@303
|
259 |
template<typename I> void erase(const I& i) const { graph->erase(i); }
|
marci@212
|
260 |
|
marci@303
|
261 |
void clear() const { graph->clear(); }
|
marci@212
|
262 |
|
marci@303
|
263 |
template<typename T> class NodeMap : public Graph::NodeMap<T> {
|
marci@212
|
264 |
public:
|
marci@303
|
265 |
NodeMap(const GraphWrapper<Graph>& _G) :
|
marci@303
|
266 |
Graph::NodeMap<T>(*(_G.graph)) { }
|
marci@303
|
267 |
NodeMap(const GraphWrapper<Graph>& _G, T a) :
|
marci@303
|
268 |
Graph::NodeMap<T>(*(_G.graph), a) { }
|
marci@212
|
269 |
};
|
marci@212
|
270 |
|
marci@303
|
271 |
template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
|
marci@212
|
272 |
public:
|
marci@303
|
273 |
EdgeMap(const GraphWrapper<Graph>& _G) :
|
marci@303
|
274 |
Graph::EdgeMap<T>(*(_G.graph)) { }
|
marci@303
|
275 |
EdgeMap(const GraphWrapper<Graph>& _G, T a) :
|
marci@303
|
276 |
Graph::EdgeMap<T>(*(_G.graph), a) { }
|
marci@212
|
277 |
};
|
marci@212
|
278 |
};
|
marci@212
|
279 |
|
marci@303
|
280 |
|
marci@230
|
281 |
// template<typename Graph>
|
marci@230
|
282 |
// class RevGraphWrapper
|
marci@230
|
283 |
// {
|
marci@230
|
284 |
// protected:
|
marci@230
|
285 |
// Graph* graph;
|
marci@230
|
286 |
|
marci@230
|
287 |
// public:
|
marci@303
|
288 |
// typedef Graph ParentGraph;
|
marci@230
|
289 |
|
marci@230
|
290 |
// typedef typename Graph::Node Node;
|
marci@230
|
291 |
// typedef typename Graph::NodeIt NodeIt;
|
marci@230
|
292 |
|
marci@230
|
293 |
// typedef typename Graph::Edge Edge;
|
marci@230
|
294 |
// typedef typename Graph::OutEdgeIt InEdgeIt;
|
marci@230
|
295 |
// typedef typename Graph::InEdgeIt OutEdgeIt;
|
marci@230
|
296 |
// //typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@230
|
297 |
// typedef typename Graph::EdgeIt EdgeIt;
|
marci@230
|
298 |
|
marci@230
|
299 |
// //RevGraphWrapper() : graph(0) { }
|
marci@230
|
300 |
// RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@230
|
301 |
|
marci@230
|
302 |
// void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@230
|
303 |
// Graph& getGraph() const { return (*graph); }
|
marci@230
|
304 |
|
marci@230
|
305 |
// template<typename I> I& first(I& i) const { return graph->first(i); }
|
marci@230
|
306 |
// template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@230
|
307 |
// return graph->first(i, p); }
|
marci@230
|
308 |
|
marci@230
|
309 |
// template<typename I> I getNext(const I& i) const {
|
marci@230
|
310 |
// return graph->getNext(i); }
|
marci@230
|
311 |
// template<typename I> I& next(I &i) const { return graph->next(i); }
|
marci@230
|
312 |
|
marci@230
|
313 |
// template< typename It > It first() const {
|
marci@230
|
314 |
// It e; first(e); return e; }
|
marci@230
|
315 |
|
marci@230
|
316 |
// template< typename It > It first(const Node& v) const {
|
marci@230
|
317 |
// It e; first(e, v); return e; }
|
marci@230
|
318 |
|
marci@230
|
319 |
// Node head(const Edge& e) const { return graph->tail(e); }
|
marci@230
|
320 |
// Node tail(const Edge& e) const { return graph->head(e); }
|
marci@230
|
321 |
|
marci@230
|
322 |
// template<typename I> bool valid(const I& i) const
|
marci@230
|
323 |
// { return graph->valid(i); }
|
marci@230
|
324 |
|
marci@230
|
325 |
// //template<typename I> void setInvalid(const I &i);
|
marci@230
|
326 |
// //{ return graph->setInvalid(i); }
|
marci@230
|
327 |
|
marci@230
|
328 |
// template<typename I> Node aNode(const I& e) const {
|
marci@230
|
329 |
// return graph->aNode(e); }
|
marci@230
|
330 |
// template<typename I> Node bNode(const I& e) const {
|
marci@230
|
331 |
// return graph->bNode(e); }
|
marci@230
|
332 |
|
marci@230
|
333 |
// Node addNode() const { return graph->addNode(); }
|
marci@230
|
334 |
// Edge addEdge(const Node& tail, const Node& head) const {
|
marci@230
|
335 |
// return graph->addEdge(tail, head); }
|
marci@230
|
336 |
|
marci@230
|
337 |
// int nodeNum() const { return graph->nodeNum(); }
|
marci@230
|
338 |
// int edgeNum() const { return graph->edgeNum(); }
|
marci@230
|
339 |
|
marci@230
|
340 |
// template<typename I> void erase(const I& i) const { graph->erase(i); }
|
marci@230
|
341 |
|
marci@230
|
342 |
// void clear() const { graph->clear(); }
|
marci@230
|
343 |
|
marci@230
|
344 |
// template<typename T> class NodeMap : public Graph::NodeMap<T> {
|
marci@230
|
345 |
// public:
|
marci@230
|
346 |
// NodeMap(const RevGraphWrapper<Graph>& _G) :
|
marci@230
|
347 |
// Graph::NodeMap<T>(_G.getGraph()) { }
|
marci@230
|
348 |
// NodeMap(const RevGraphWrapper<Graph>& _G, T a) :
|
marci@230
|
349 |
// Graph::NodeMap<T>(_G.getGraph(), a) { }
|
marci@230
|
350 |
// };
|
marci@230
|
351 |
|
marci@230
|
352 |
// template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
|
marci@230
|
353 |
// public:
|
marci@230
|
354 |
// EdgeMap(const RevGraphWrapper<Graph>& _G) :
|
marci@230
|
355 |
// Graph::EdgeMap<T>(_G.getGraph()) { }
|
marci@230
|
356 |
// EdgeMap(const RevGraphWrapper<Graph>& _G, T a) :
|
marci@230
|
357 |
// Graph::EdgeMap<T>(_G.getGraph(), a) { }
|
marci@230
|
358 |
// };
|
marci@230
|
359 |
// };
|
marci@230
|
360 |
|
marci@235
|
361 |
|
marci@303
|
362 |
template<typename Graph>
|
marci@303
|
363 |
class RevGraphWrapper : public GraphWrapper<Graph> {
|
marci@230
|
364 |
public:
|
marci@303
|
365 |
typedef typename GraphWrapper<Graph>::Node Node;
|
marci@303
|
366 |
typedef typename GraphWrapper<Graph>::Edge Edge;
|
marci@279
|
367 |
//FIXME
|
marci@303
|
368 |
//If Graph::OutEdgeIt is not defined
|
marci@279
|
369 |
//and we do not want to use RevGraphWrapper::InEdgeIt,
|
marci@279
|
370 |
//this won't work, because of typedef
|
marci@279
|
371 |
//OR
|
marci@279
|
372 |
//graphs have to define their non-existing iterators to void
|
marci@279
|
373 |
//Unfortunately all the typedefs are instantiated in templates,
|
marci@279
|
374 |
//unlike other stuff
|
marci@303
|
375 |
typedef typename GraphWrapper<Graph>::OutEdgeIt InEdgeIt;
|
marci@303
|
376 |
typedef typename GraphWrapper<Graph>::InEdgeIt OutEdgeIt;
|
marci@237
|
377 |
|
marci@303
|
378 |
// RevGraphWrapper() : GraphWrapper<Graph>() { }
|
marci@303
|
379 |
RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }
|
marci@238
|
380 |
|
marci@237
|
381 |
Node head(const Edge& e) const
|
marci@303
|
382 |
{ return GraphWrapper<Graph>::tail(e); }
|
marci@237
|
383 |
Node tail(const Edge& e) const
|
marci@303
|
384 |
{ return GraphWrapper<Graph>::head(e); }
|
marci@76
|
385 |
};
|
marci@76
|
386 |
|
marci@263
|
387 |
//Subgraph on the same node-set and partial edge-set
|
marci@303
|
388 |
template<typename Graph, typename EdgeFilterMap>
|
marci@303
|
389 |
class SubGraphWrapper : public GraphWrapper<Graph> {
|
marci@263
|
390 |
protected:
|
marci@263
|
391 |
EdgeFilterMap* filter_map;
|
marci@263
|
392 |
public:
|
marci@303
|
393 |
typedef typename GraphWrapper<Graph>::Node Node;
|
marci@303
|
394 |
typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
|
marci@303
|
395 |
typedef typename GraphWrapper<Graph>::Edge Edge;
|
marci@303
|
396 |
typedef typename GraphWrapper<Graph>::EdgeIt EdgeIt;
|
marci@303
|
397 |
typedef typename GraphWrapper<Graph>::InEdgeIt InEdgeIt;
|
marci@303
|
398 |
typedef typename GraphWrapper<Graph>::OutEdgeIt OutEdgeIt;
|
marci@263
|
399 |
|
marci@303
|
400 |
// SubGraphWrapper() : GraphWrapper<Graph>(), filter_map(0) { }
|
marci@303
|
401 |
SubGraphWrapper(Graph& _graph, EdgeFilterMap& _filter_map) :
|
marci@303
|
402 |
GraphWrapper<Graph>(_graph), filter_map(&_filter_map) { }
|
marci@263
|
403 |
|
marci@263
|
404 |
template<typename I> I& first(I& i) const {
|
marci@303
|
405 |
graph->first(i);
|
marci@303
|
406 |
//while (graph->valid(i) && !filter_map->get(i)) { graph->next(i); }
|
marci@303
|
407 |
while (graph->valid(i) && !(*filter_map)[i]) { graph->next(i); }
|
marci@263
|
408 |
return i;
|
marci@263
|
409 |
}
|
marci@263
|
410 |
template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@303
|
411 |
graph->first(i, p);
|
marci@303
|
412 |
// while (graph->valid(i) && !filter_map->get(i)) { graph->next(i); }
|
marci@303
|
413 |
while (graph->valid(i) && !(*filter_map)[i]) { graph->next(i); }
|
marci@263
|
414 |
return i;
|
marci@263
|
415 |
}
|
marci@263
|
416 |
|
marci@263
|
417 |
//template<typename I> I getNext(const I& i) const {
|
marci@263
|
418 |
// return gw.getNext(i);
|
marci@263
|
419 |
//}
|
marci@263
|
420 |
template<typename I> I& next(I &i) const {
|
marci@303
|
421 |
graph->next(i);
|
marci@303
|
422 |
// while (graph->valid(i) && !filter_map-get(i)) { graph->next(i); }
|
marci@303
|
423 |
while (graph->valid(i) && !(*filter_map)[i]) { graph->next(i); }
|
marci@263
|
424 |
return i;
|
marci@263
|
425 |
}
|
marci@263
|
426 |
|
marci@263
|
427 |
template< typename It > It first() const {
|
marci@263
|
428 |
It e; this->first(e); return e; }
|
marci@263
|
429 |
|
marci@263
|
430 |
template< typename It > It first(const Node& v) const {
|
marci@263
|
431 |
It e; this->first(e, v); return e; }
|
marci@263
|
432 |
};
|
marci@155
|
433 |
|
marci@238
|
434 |
// template<typename GraphWrapper>
|
marci@236
|
435 |
// class UndirGraphWrapper {
|
marci@236
|
436 |
// protected:
|
marci@238
|
437 |
// //Graph* graph;
|
marci@238
|
438 |
// GraphWrapper gw;
|
marci@238
|
439 |
|
marci@236
|
440 |
// public:
|
marci@303
|
441 |
// typedef GraphWrapper ParentGraph;
|
marci@236
|
442 |
|
marci@238
|
443 |
// typedef typename GraphWrapper::Node Node;
|
marci@238
|
444 |
// typedef typename GraphWrapper::NodeIt NodeIt;
|
marci@236
|
445 |
|
marci@236
|
446 |
// //typedef typename Graph::Edge Edge;
|
marci@236
|
447 |
// //typedef typename Graph::OutEdgeIt OutEdgeIt;
|
marci@236
|
448 |
// //typedef typename Graph::InEdgeIt InEdgeIt;
|
marci@236
|
449 |
// //typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@236
|
450 |
// //typedef typename Graph::EdgeIt EdgeIt;
|
marci@236
|
451 |
|
marci@236
|
452 |
// //private:
|
marci@238
|
453 |
// typedef typename GraphWrapper::Edge GraphEdge;
|
marci@238
|
454 |
// typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt;
|
marci@238
|
455 |
// typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt;
|
marci@236
|
456 |
// //public:
|
marci@236
|
457 |
|
marci@236
|
458 |
// //UndirGraphWrapper() : graph(0) { }
|
marci@238
|
459 |
// UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
|
marci@236
|
460 |
|
marci@238
|
461 |
// //void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@238
|
462 |
// //Graph& getGraph() const { return (*graph); }
|
marci@236
|
463 |
|
marci@236
|
464 |
// class Edge {
|
marci@238
|
465 |
// friend class UndirGraphWrapper<GraphWrapper>;
|
marci@236
|
466 |
// bool out_or_in; //true iff out
|
marci@236
|
467 |
// GraphOutEdgeIt out;
|
marci@236
|
468 |
// GraphInEdgeIt in;
|
marci@236
|
469 |
// public:
|
marci@236
|
470 |
// Edge() : out_or_in(), out(), in() { }
|
marci@236
|
471 |
// Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
|
marci@236
|
472 |
// operator GraphEdge() const {
|
marci@236
|
473 |
// if (out_or_in) return(out); else return(in);
|
marci@236
|
474 |
// }
|
marci@236
|
475 |
// friend bool operator==(const Edge& u, const Edge& v) {
|
marci@236
|
476 |
// if (v.out_or_in)
|
marci@236
|
477 |
// return (u.out_or_in && u.out==v.out);
|
marci@236
|
478 |
// else
|
marci@236
|
479 |
// return (!u.out_or_in && u.in==v.in);
|
marci@236
|
480 |
// }
|
marci@236
|
481 |
// friend bool operator!=(const Edge& u, const Edge& v) {
|
marci@236
|
482 |
// if (v.out_or_in)
|
marci@236
|
483 |
// return (!u.out_or_in || u.out!=v.out);
|
marci@236
|
484 |
// else
|
marci@236
|
485 |
// return (u.out_or_in || u.in!=v.in);
|
marci@236
|
486 |
// }
|
marci@236
|
487 |
// };
|
marci@236
|
488 |
|
marci@236
|
489 |
// class OutEdgeIt : public Edge {
|
marci@238
|
490 |
// friend class UndirGraphWrapper<GraphWrapper>;
|
marci@236
|
491 |
// public:
|
marci@236
|
492 |
// OutEdgeIt() : Edge() { }
|
marci@236
|
493 |
// OutEdgeIt(const Invalid& i) : Edge(i) { }
|
marci@238
|
494 |
// OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n)
|
marci@238
|
495 |
// : Edge() {
|
marci@236
|
496 |
// out_or_in=true;
|
marci@238
|
497 |
// _G.gw.first(out, n);
|
marci@238
|
498 |
// if (!(_G.gw.valid(out))) {
|
marci@236
|
499 |
// out_or_in=false;
|
marci@238
|
500 |
// _G.gw.first(in, n);
|
marci@236
|
501 |
// }
|
marci@236
|
502 |
// }
|
marci@236
|
503 |
// };
|
marci@236
|
504 |
|
marci@236
|
505 |
// OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
|
marci@236
|
506 |
// e.out_or_in=true;
|
marci@238
|
507 |
// gw.first(e.out, n);
|
marci@238
|
508 |
// if (!(gw.valid(e.out))) {
|
marci@236
|
509 |
// e.out_or_in=false;
|
marci@238
|
510 |
// gw.first(e.in, n);
|
marci@236
|
511 |
// }
|
marci@236
|
512 |
// return e;
|
marci@236
|
513 |
// }
|
marci@236
|
514 |
|
marci@236
|
515 |
// OutEdgeIt& next(OutEdgeIt& e) const {
|
marci@236
|
516 |
// if (e.out_or_in) {
|
marci@238
|
517 |
// Node n=gw.tail(e.out);
|
marci@238
|
518 |
// gw.next(e.out);
|
marci@238
|
519 |
// if (!gw.valid(e.out)) {
|
marci@236
|
520 |
// e.out_or_in=false;
|
marci@238
|
521 |
// gw.first(e.in, n);
|
marci@236
|
522 |
// }
|
marci@236
|
523 |
// } else {
|
marci@238
|
524 |
// gw.next(e.in);
|
marci@236
|
525 |
// }
|
marci@236
|
526 |
// return e;
|
marci@236
|
527 |
// }
|
marci@236
|
528 |
|
marci@236
|
529 |
// Node aNode(const OutEdgeIt& e) const {
|
marci@238
|
530 |
// if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
|
marci@236
|
531 |
// Node bNode(const OutEdgeIt& e) const {
|
marci@238
|
532 |
// if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
|
marci@236
|
533 |
|
marci@236
|
534 |
// typedef OutEdgeIt InEdgeIt;
|
marci@236
|
535 |
|
marci@238
|
536 |
// template<typename I> I& first(I& i) const { return gw.first(i); }
|
marci@236
|
537 |
// // template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@236
|
538 |
// // return graph->first(i, p); }
|
marci@236
|
539 |
|
marci@236
|
540 |
// template<typename I> I getNext(const I& i) const {
|
marci@238
|
541 |
// return gw.getNext(i); }
|
marci@238
|
542 |
// template<typename I> I& next(I &i) const { return gw.next(i); }
|
marci@236
|
543 |
|
marci@236
|
544 |
// template< typename It > It first() const {
|
marci@236
|
545 |
// It e; first(e); return e; }
|
marci@236
|
546 |
|
marci@236
|
547 |
// template< typename It > It first(const Node& v) const {
|
marci@236
|
548 |
// It e; first(e, v); return e; }
|
marci@236
|
549 |
|
marci@238
|
550 |
// Node head(const Edge& e) const { return gw.head(e); }
|
marci@238
|
551 |
// Node tail(const Edge& e) const { return gw.tail(e); }
|
marci@236
|
552 |
|
marci@236
|
553 |
// template<typename I> bool valid(const I& i) const
|
marci@238
|
554 |
// { return gw.valid(i); }
|
marci@236
|
555 |
|
marci@236
|
556 |
// //template<typename I> void setInvalid(const I &i);
|
marci@236
|
557 |
// //{ return graph->setInvalid(i); }
|
marci@236
|
558 |
|
marci@238
|
559 |
// int nodeNum() const { return gw.nodeNum(); }
|
marci@238
|
560 |
// int edgeNum() const { return gw.edgeNum(); }
|
marci@236
|
561 |
|
marci@236
|
562 |
// // template<typename I> Node aNode(const I& e) const {
|
marci@236
|
563 |
// // return graph->aNode(e); }
|
marci@236
|
564 |
// // template<typename I> Node bNode(const I& e) const {
|
marci@236
|
565 |
// // return graph->bNode(e); }
|
marci@236
|
566 |
|
marci@238
|
567 |
// Node addNode() const { return gw.addNode(); }
|
marci@236
|
568 |
// // FIXME: ez igy nem jo, mert nem
|
marci@236
|
569 |
// // Edge addEdge(const Node& tail, const Node& head) const {
|
marci@236
|
570 |
// // return graph->addEdge(tail, head); }
|
marci@236
|
571 |
|
marci@238
|
572 |
// template<typename I> void erase(const I& i) const { gw.erase(i); }
|
marci@236
|
573 |
|
marci@238
|
574 |
// void clear() const { gw.clear(); }
|
marci@236
|
575 |
|
marci@238
|
576 |
// template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
|
marci@236
|
577 |
// public:
|
marci@238
|
578 |
// NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
|
marci@238
|
579 |
// GraphWrapper::NodeMap<T>(_G.gw) { }
|
marci@238
|
580 |
// NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
|
marci@238
|
581 |
// GraphWrapper::NodeMap<T>(_G.gw, a) { }
|
marci@236
|
582 |
// };
|
marci@236
|
583 |
|
marci@238
|
584 |
// template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
|
marci@236
|
585 |
// public:
|
marci@238
|
586 |
// EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
|
marci@238
|
587 |
// GraphWrapper::EdgeMap<T>(_G.gw) { }
|
marci@238
|
588 |
// EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
|
marci@238
|
589 |
// GraphWrapper::EdgeMap<T>(_G.gw, a) { }
|
marci@236
|
590 |
// };
|
marci@236
|
591 |
// };
|
marci@236
|
592 |
|
marci@236
|
593 |
|
marci@303
|
594 |
template<typename Graph>
|
marci@303
|
595 |
class UndirGraphWrapper : public GraphWrapper<Graph> {
|
marci@199
|
596 |
protected:
|
marci@303
|
597 |
typedef typename Graph::Edge GraphEdge;
|
marci@303
|
598 |
typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
|
marci@303
|
599 |
typedef typename Graph::InEdgeIt GraphInEdgeIt;
|
marci@303
|
600 |
public:
|
marci@303
|
601 |
typedef typename GraphWrapper<Graph>::Node Node;
|
marci@303
|
602 |
typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
|
marci@236
|
603 |
|
marci@303
|
604 |
// UndirGraphWrapper() : GraphWrapper<Graph>() { }
|
marci@303
|
605 |
UndirGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }
|
marci@158
|
606 |
|
marci@174
|
607 |
class Edge {
|
marci@303
|
608 |
friend class UndirGraphWrapper<Graph>;
|
marci@279
|
609 |
protected:
|
marci@158
|
610 |
bool out_or_in; //true iff out
|
marci@158
|
611 |
GraphOutEdgeIt out;
|
marci@158
|
612 |
GraphInEdgeIt in;
|
marci@158
|
613 |
public:
|
marci@174
|
614 |
Edge() : out_or_in(), out(), in() { }
|
marci@174
|
615 |
Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
|
marci@174
|
616 |
operator GraphEdge() const {
|
marci@158
|
617 |
if (out_or_in) return(out); else return(in);
|
marci@158
|
618 |
}
|
marci@239
|
619 |
//FIXME
|
marci@239
|
620 |
//2 edges are equal if they "refer" to the same physical edge
|
marci@239
|
621 |
//is it good?
|
marci@174
|
622 |
friend bool operator==(const Edge& u, const Edge& v) {
|
marci@174
|
623 |
if (v.out_or_in)
|
marci@239
|
624 |
if (u.out_or_in) return (u.out==v.out); else return (u.out==v.in);
|
marci@239
|
625 |
//return (u.out_or_in && u.out==v.out);
|
marci@174
|
626 |
else
|
marci@239
|
627 |
if (u.out_or_in) return (u.out==v.in); else return (u.in==v.in);
|
marci@239
|
628 |
//return (!u.out_or_in && u.in==v.in);
|
marci@174
|
629 |
}
|
marci@174
|
630 |
friend bool operator!=(const Edge& u, const Edge& v) {
|
marci@174
|
631 |
if (v.out_or_in)
|
marci@239
|
632 |
if (u.out_or_in) return (u.out!=v.out); else return (u.out!=v.in);
|
marci@239
|
633 |
//return (!u.out_or_in || u.out!=v.out);
|
marci@174
|
634 |
else
|
marci@239
|
635 |
if (u.out_or_in) return (u.out!=v.in); else return (u.in!=v.in);
|
marci@239
|
636 |
//return (u.out_or_in || u.in!=v.in);
|
marci@174
|
637 |
}
|
marci@158
|
638 |
};
|
marci@158
|
639 |
|
marci@174
|
640 |
class OutEdgeIt : public Edge {
|
marci@303
|
641 |
friend class UndirGraphWrapper<Graph>;
|
marci@158
|
642 |
public:
|
marci@174
|
643 |
OutEdgeIt() : Edge() { }
|
marci@174
|
644 |
OutEdgeIt(const Invalid& i) : Edge(i) { }
|
marci@303
|
645 |
OutEdgeIt(const UndirGraphWrapper<Graph>& _G, const Node& n)
|
marci@236
|
646 |
: Edge() {
|
marci@303
|
647 |
out_or_in=true; _G.graph->first(out, n);
|
marci@303
|
648 |
if (!(_G.graph->valid(out))) { out_or_in=false; _G.graph->first(in, n); }
|
marci@158
|
649 |
}
|
marci@158
|
650 |
};
|
marci@158
|
651 |
|
marci@238
|
652 |
typedef OutEdgeIt InEdgeIt;
|
marci@238
|
653 |
|
marci@238
|
654 |
class EdgeIt : public Edge {
|
marci@303
|
655 |
friend class UndirGraphWrapper<Graph>;
|
marci@238
|
656 |
protected:
|
marci@238
|
657 |
NodeIt v;
|
marci@238
|
658 |
public:
|
marci@238
|
659 |
EdgeIt() : Edge() { }
|
marci@238
|
660 |
EdgeIt(const Invalid& i) : Edge(i) { }
|
marci@303
|
661 |
EdgeIt(const UndirGraphWrapper<Graph>& _G)
|
marci@238
|
662 |
: Edge() {
|
marci@238
|
663 |
out_or_in=true;
|
marci@238
|
664 |
//Node v;
|
marci@238
|
665 |
_G.first(v);
|
marci@303
|
666 |
if (_G.valid(v)) _G.graph->first(out); else out=INVALID;
|
marci@303
|
667 |
while (_G.valid(v) && !_G.graph->valid(out)) {
|
marci@303
|
668 |
_G.graph->next(v);
|
marci@303
|
669 |
if (_G.valid(v)) _G.graph->first(out);
|
marci@238
|
670 |
}
|
marci@238
|
671 |
}
|
marci@238
|
672 |
};
|
marci@238
|
673 |
|
marci@212
|
674 |
OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
|
marci@303
|
675 |
e.out_or_in=true; graph->first(e.out, n);
|
marci@303
|
676 |
if (!(graph->valid(e.out))) { e.out_or_in=false; graph->first(e.in, n); }
|
marci@158
|
677 |
return e;
|
marci@158
|
678 |
}
|
marci@158
|
679 |
|
marci@238
|
680 |
EdgeIt& first(EdgeIt& e) const {
|
marci@238
|
681 |
e.out_or_in=true;
|
marci@238
|
682 |
//NodeIt v;
|
marci@238
|
683 |
first(e.v);
|
marci@303
|
684 |
if (valid(e.v)) graph->first(e.out, e.v); else e.out=INVALID;
|
marci@303
|
685 |
while (valid(e.v) && !graph->valid(e.out)) {
|
marci@303
|
686 |
graph->next(e.v);
|
marci@303
|
687 |
if (valid(e.v)) graph->first(e.out, e.v);
|
marci@238
|
688 |
}
|
marci@238
|
689 |
return e;
|
marci@238
|
690 |
}
|
marci@238
|
691 |
|
marci@303
|
692 |
template<typename I> I& first(I& i) const { graph->first(i); return i; }
|
marci@238
|
693 |
template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@303
|
694 |
graph->first(i, p); return i; }
|
marci@238
|
695 |
|
marci@158
|
696 |
OutEdgeIt& next(OutEdgeIt& e) const {
|
marci@158
|
697 |
if (e.out_or_in) {
|
marci@303
|
698 |
Node n=graph->tail(e.out);
|
marci@303
|
699 |
graph->next(e.out);
|
marci@303
|
700 |
if (!graph->valid(e.out)) { e.out_or_in=false; graph->first(e.in, n); }
|
marci@158
|
701 |
} else {
|
marci@303
|
702 |
graph->next(e.in);
|
marci@158
|
703 |
}
|
marci@158
|
704 |
return e;
|
marci@158
|
705 |
}
|
marci@158
|
706 |
|
marci@238
|
707 |
EdgeIt& next(EdgeIt& e) const {
|
marci@238
|
708 |
//NodeIt v=tail(e);
|
marci@303
|
709 |
graph->next(e.out);
|
marci@303
|
710 |
while (valid(e.v) && !graph->valid(e.out)) {
|
marci@238
|
711 |
next(e.v);
|
marci@303
|
712 |
if (valid(e.v)) graph->first(e.out, e.v);
|
marci@238
|
713 |
}
|
marci@238
|
714 |
return e;
|
marci@238
|
715 |
}
|
marci@158
|
716 |
|
marci@305
|
717 |
template<typename I> I& next(I &i) const { graph->next(i); return i; }
|
marci@265
|
718 |
// template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
|
marci@158
|
719 |
|
marci@158
|
720 |
template< typename It > It first() const {
|
marci@303
|
721 |
It e; this->first(e); return e; }
|
marci@158
|
722 |
|
marci@174
|
723 |
template< typename It > It first(const Node& v) const {
|
marci@303
|
724 |
It e; this->first(e, v); return e; }
|
marci@158
|
725 |
|
marci@238
|
726 |
// Node head(const Edge& e) const { return gw.head(e); }
|
marci@238
|
727 |
// Node tail(const Edge& e) const { return gw.tail(e); }
|
marci@158
|
728 |
|
marci@238
|
729 |
// template<typename I> bool valid(const I& i) const
|
marci@238
|
730 |
// { return gw.valid(i); }
|
marci@158
|
731 |
|
marci@238
|
732 |
// int nodeNum() const { return gw.nodeNum(); }
|
marci@238
|
733 |
// int edgeNum() const { return gw.edgeNum(); }
|
marci@158
|
734 |
|
marci@174
|
735 |
// template<typename I> Node aNode(const I& e) const {
|
marci@158
|
736 |
// return graph->aNode(e); }
|
marci@174
|
737 |
// template<typename I> Node bNode(const I& e) const {
|
marci@158
|
738 |
// return graph->bNode(e); }
|
marci@238
|
739 |
|
marci@238
|
740 |
Node aNode(const OutEdgeIt& e) const {
|
marci@303
|
741 |
if (e.out_or_in) return graph->tail(e); else return graph->head(e); }
|
marci@238
|
742 |
Node bNode(const OutEdgeIt& e) const {
|
marci@303
|
743 |
if (e.out_or_in) return graph->head(e); else return graph->tail(e); }
|
marci@158
|
744 |
|
marci@238
|
745 |
// Node addNode() const { return gw.addNode(); }
|
marci@238
|
746 |
|
marci@231
|
747 |
// FIXME: ez igy nem jo, mert nem
|
marci@231
|
748 |
// Edge addEdge(const Node& tail, const Node& head) const {
|
marci@231
|
749 |
// return graph->addEdge(tail, head); }
|
marci@158
|
750 |
|
marci@238
|
751 |
// template<typename I> void erase(const I& i) const { gw.erase(i); }
|
marci@158
|
752 |
|
marci@238
|
753 |
// void clear() const { gw.clear(); }
|
marci@158
|
754 |
|
marci@303
|
755 |
// template<typename T> class NodeMap : public Graph::NodeMap<T> {
|
marci@238
|
756 |
// public:
|
marci@303
|
757 |
// NodeMap(const UndirGraphWrapper<Graph>& _G) :
|
marci@303
|
758 |
// Graph::NodeMap<T>(_G.gw) { }
|
marci@303
|
759 |
// NodeMap(const UndirGraphWrapper<Graph>& _G, T a) :
|
marci@303
|
760 |
// Graph::NodeMap<T>(_G.gw, a) { }
|
marci@238
|
761 |
// };
|
marci@168
|
762 |
|
marci@238
|
763 |
// template<typename T> class EdgeMap :
|
marci@303
|
764 |
// public GraphWrapperSkeleton<Graph>::EdgeMap<T> {
|
marci@238
|
765 |
// public:
|
marci@303
|
766 |
// EdgeMap(const UndirGraphWrapper<Graph>& _G) :
|
marci@303
|
767 |
// GraphWrapperSkeleton<Graph>::EdgeMap<T>(_G.gw) { }
|
marci@303
|
768 |
// EdgeMap(const UndirGraphWrapper<Graph>& _G, T a) :
|
marci@303
|
769 |
// Graph::EdgeMap<T>(_G.gw, a) { }
|
marci@238
|
770 |
// };
|
marci@238
|
771 |
};
|
marci@158
|
772 |
|
marci@158
|
773 |
|
marci@158
|
774 |
|
marci@236
|
775 |
|
marci@236
|
776 |
|
marci@155
|
777 |
// template<typename Graph>
|
marci@155
|
778 |
// class SymGraphWrapper
|
marci@155
|
779 |
// {
|
marci@155
|
780 |
// Graph* graph;
|
marci@76
|
781 |
|
marci@155
|
782 |
// public:
|
marci@303
|
783 |
// typedef Graph ParentGraph;
|
marci@155
|
784 |
|
marci@174
|
785 |
// typedef typename Graph::Node Node;
|
marci@174
|
786 |
// typedef typename Graph::Edge Edge;
|
marci@174
|
787 |
|
marci@155
|
788 |
// typedef typename Graph::NodeIt NodeIt;
|
marci@155
|
789 |
|
marci@155
|
790 |
// //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
|
marci@155
|
791 |
// //iranyitatlant, ami van
|
marci@155
|
792 |
// //mert csak 1 dolgot lehet be typedef-elni
|
marci@155
|
793 |
// typedef typename Graph::OutEdgeIt SymEdgeIt;
|
marci@155
|
794 |
// //typedef typename Graph::InEdgeIt SymEdgeIt;
|
marci@155
|
795 |
// //typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@174
|
796 |
// typedef typename Graph::EdgeIt EdgeIt;
|
marci@155
|
797 |
|
marci@155
|
798 |
// int nodeNum() const { return graph->nodeNum(); }
|
marci@155
|
799 |
// int edgeNum() const { return graph->edgeNum(); }
|
marci@155
|
800 |
|
marci@212
|
801 |
// template<typename I> I& first(I& i) const { return graph->first(i); }
|
marci@212
|
802 |
// template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@212
|
803 |
// return graph->first(i, p); }
|
marci@155
|
804 |
// //template<typename I> I next(const I i); { return graph->goNext(i); }
|
marci@155
|
805 |
// //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
|
marci@155
|
806 |
|
marci@155
|
807 |
// template< typename It > It first() const {
|
marci@212
|
808 |
// It e; first(e); return e; }
|
marci@155
|
809 |
|
marci@174
|
810 |
// template< typename It > It first(Node v) const {
|
marci@212
|
811 |
// It e; first(e, v); return e; }
|
marci@155
|
812 |
|
marci@174
|
813 |
// Node head(const Edge& e) const { return graph->head(e); }
|
marci@174
|
814 |
// Node tail(const Edge& e) const { return graph->tail(e); }
|
marci@155
|
815 |
|
marci@174
|
816 |
// template<typename I> Node aNode(const I& e) const {
|
marci@155
|
817 |
// return graph->aNode(e); }
|
marci@174
|
818 |
// template<typename I> Node bNode(const I& e) const {
|
marci@155
|
819 |
// return graph->bNode(e); }
|
marci@155
|
820 |
|
marci@155
|
821 |
// //template<typename I> bool valid(const I i);
|
marci@155
|
822 |
// //{ return graph->valid(i); }
|
marci@155
|
823 |
|
marci@155
|
824 |
// //template<typename I> void setInvalid(const I &i);
|
marci@155
|
825 |
// //{ return graph->setInvalid(i); }
|
marci@155
|
826 |
|
marci@174
|
827 |
// Node addNode() { return graph->addNode(); }
|
marci@174
|
828 |
// Edge addEdge(const Node& tail, const Node& head) {
|
marci@155
|
829 |
// return graph->addEdge(tail, head); }
|
marci@155
|
830 |
|
marci@155
|
831 |
// template<typename I> void erase(const I& i) { graph->erase(i); }
|
marci@155
|
832 |
|
marci@155
|
833 |
// void clear() { graph->clear(); }
|
marci@155
|
834 |
|
marci@155
|
835 |
// template<typename T> class NodeMap : public Graph::NodeMap<T> { };
|
marci@155
|
836 |
// template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
|
marci@155
|
837 |
|
marci@155
|
838 |
// void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@155
|
839 |
// Graph& getGraph() { return (*graph); }
|
marci@155
|
840 |
|
marci@155
|
841 |
// //SymGraphWrapper() : graph(0) { }
|
marci@155
|
842 |
// SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@155
|
843 |
// };
|
marci@155
|
844 |
|
marci@155
|
845 |
|
marci@303
|
846 |
template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
|
marci@303
|
847 |
class ResGraphWrapper : public GraphWrapper<Graph>{
|
marci@76
|
848 |
public:
|
marci@303
|
849 |
typedef typename GraphWrapper<Graph>::Node Node;
|
marci@303
|
850 |
typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
|
marci@199
|
851 |
protected:
|
marci@303
|
852 |
typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
|
marci@303
|
853 |
typedef typename Graph::InEdgeIt GraphInEdgeIt;
|
marci@303
|
854 |
typedef typename Graph::Edge GraphEdge;
|
marci@155
|
855 |
FlowMap* flow;
|
marci@155
|
856 |
const CapacityMap* capacity;
|
marci@155
|
857 |
public:
|
marci@168
|
858 |
|
marci@303
|
859 |
ResGraphWrapper(Graph& _graph, FlowMap& _flow,
|
marci@266
|
860 |
const CapacityMap& _capacity) :
|
marci@303
|
861 |
GraphWrapper<Graph>(_graph), flow(&_flow), capacity(&_capacity) { }
|
marci@168
|
862 |
|
marci@174
|
863 |
class Edge;
|
marci@155
|
864 |
class OutEdgeIt;
|
marci@174
|
865 |
friend class Edge;
|
marci@155
|
866 |
friend class OutEdgeIt;
|
marci@76
|
867 |
|
marci@174
|
868 |
class Edge {
|
marci@303
|
869 |
friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
|
marci@155
|
870 |
protected:
|
marci@168
|
871 |
bool out_or_in; //true, iff out
|
marci@303
|
872 |
GraphOutEdgeIt out;
|
marci@303
|
873 |
GraphInEdgeIt in;
|
marci@155
|
874 |
public:
|
marci@174
|
875 |
Edge() : out_or_in(true) { }
|
marci@174
|
876 |
Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
|
marci@168
|
877 |
// bool valid() const {
|
marci@168
|
878 |
// return out_or_in && out.valid() || in.valid(); }
|
marci@174
|
879 |
friend bool operator==(const Edge& u, const Edge& v) {
|
marci@174
|
880 |
if (v.out_or_in)
|
marci@174
|
881 |
return (u.out_or_in && u.out==v.out);
|
marci@174
|
882 |
else
|
marci@174
|
883 |
return (!u.out_or_in && u.in==v.in);
|
marci@174
|
884 |
}
|
marci@174
|
885 |
friend bool operator!=(const Edge& u, const Edge& v) {
|
marci@174
|
886 |
if (v.out_or_in)
|
marci@174
|
887 |
return (!u.out_or_in || u.out!=v.out);
|
marci@174
|
888 |
else
|
marci@174
|
889 |
return (u.out_or_in || u.in!=v.in);
|
marci@174
|
890 |
}
|
marci@303
|
891 |
operator GraphEdge() const {
|
marci@303
|
892 |
if (out_or_in) return(out); else return(in);
|
marci@303
|
893 |
}
|
marci@155
|
894 |
};
|
marci@155
|
895 |
|
marci@155
|
896 |
|
marci@174
|
897 |
class OutEdgeIt : public Edge {
|
marci@303
|
898 |
friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
|
marci@155
|
899 |
public:
|
marci@155
|
900 |
OutEdgeIt() { }
|
marci@168
|
901 |
//FIXME
|
marci@174
|
902 |
OutEdgeIt(const Edge& e) : Edge(e) { }
|
marci@174
|
903 |
OutEdgeIt(const Invalid& i) : Edge(i) { }
|
marci@303
|
904 |
OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() {
|
marci@303
|
905 |
resG.graph->first(out, v);
|
marci@303
|
906 |
while( resG.graph->valid(out) && !(resG.resCap(out)>0) ) { resG.graph->next(out); }
|
marci@303
|
907 |
if (!resG.graph->valid(out)) {
|
marci@155
|
908 |
out_or_in=0;
|
marci@303
|
909 |
resG.graph->first(in, v);
|
marci@303
|
910 |
while( resG.graph->valid(in) && !(resG.resCap(in)>0) ) { resG.graph->next(in); }
|
marci@155
|
911 |
}
|
marci@155
|
912 |
}
|
marci@168
|
913 |
// public:
|
marci@168
|
914 |
// OutEdgeIt& operator++() {
|
marci@168
|
915 |
// if (out_or_in) {
|
marci@174
|
916 |
// Node v=/*resG->*/G->aNode(out);
|
marci@168
|
917 |
// ++out;
|
marci@269
|
918 |
// while( out.valid() && !(Edge::resCap()>0) ) { ++out; }
|
marci@168
|
919 |
// if (!out.valid()) {
|
marci@168
|
920 |
// out_or_in=0;
|
marci@212
|
921 |
// G->first(in, v);
|
marci@269
|
922 |
// while( in.valid() && !(Edge::resCap()>0) ) { ++in; }
|
marci@168
|
923 |
// }
|
marci@168
|
924 |
// } else {
|
marci@168
|
925 |
// ++in;
|
marci@269
|
926 |
// while( in.valid() && !(Edge::resCap()>0) ) { ++in; }
|
marci@168
|
927 |
// }
|
marci@168
|
928 |
// return *this;
|
marci@168
|
929 |
// }
|
marci@155
|
930 |
};
|
marci@155
|
931 |
|
marci@263
|
932 |
//FIXME This is just for having InEdgeIt
|
marci@263
|
933 |
typedef void InEdgeIt;
|
marci@263
|
934 |
|
marci@174
|
935 |
class EdgeIt : public Edge {
|
marci@303
|
936 |
friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
|
marci@265
|
937 |
NodeIt v;
|
marci@155
|
938 |
public:
|
marci@174
|
939 |
EdgeIt() { }
|
marci@174
|
940 |
//EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }
|
marci@174
|
941 |
EdgeIt(const Invalid& i) : Edge(i) { }
|
marci@303
|
942 |
EdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) : Edge() {
|
marci@303
|
943 |
resG.graph->first(v);
|
marci@303
|
944 |
if (resG.graph->valid(v)) resG.graph->first(out, v); else out=INVALID;
|
marci@303
|
945 |
while (resG.graph->valid(out) && !(resG.resCap(out)>0) ) { resG.graph->next(out); }
|
marci@303
|
946 |
while (resG.graph->valid(v) && !resG.graph->valid(out)) {
|
marci@303
|
947 |
resG.graph->next(v);
|
marci@303
|
948 |
if (resG.graph->valid(v)) resG.graph->first(out, v);
|
marci@303
|
949 |
while (resG.graph->valid(out) && !(resG.resCap(out)>0) ) { resG.graph->next(out); }
|
marci@155
|
950 |
}
|
marci@303
|
951 |
if (!resG.graph->valid(out)) {
|
marci@155
|
952 |
out_or_in=0;
|
marci@303
|
953 |
resG.graph->first(v);
|
marci@303
|
954 |
if (resG.graph->valid(v)) resG.graph->first(in, v); else in=INVALID;
|
marci@303
|
955 |
while (resG.graph->valid(in) && !(resG.resCap(in)>0) ) { resG.graph->next(in); }
|
marci@303
|
956 |
while (resG.graph->valid(v) && !resG.graph->valid(in)) {
|
marci@303
|
957 |
resG.graph->next(v);
|
marci@303
|
958 |
if (resG.graph->valid(v)) resG.graph->first(in, v);
|
marci@303
|
959 |
while (resG.graph->valid(in) && !(resG.resCap(in)>0) ) { resG.graph->next(in); }
|
marci@155
|
960 |
}
|
marci@155
|
961 |
}
|
marci@155
|
962 |
}
|
marci@174
|
963 |
// EdgeIt& operator++() {
|
marci@168
|
964 |
// if (out_or_in) {
|
marci@168
|
965 |
// ++out;
|
marci@269
|
966 |
// while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
|
marci@168
|
967 |
// while (v.valid() && !out.valid()) {
|
marci@168
|
968 |
// ++v;
|
marci@212
|
969 |
// if (v.valid()) G->first(out, v);
|
marci@269
|
970 |
// while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
|
marci@168
|
971 |
// }
|
marci@168
|
972 |
// if (!out.valid()) {
|
marci@168
|
973 |
// out_or_in=0;
|
marci@212
|
974 |
// G->first(v);
|
marci@303
|
975 |
// if (v.valid()) G->first(in, v); else in=GraphInEdgeIt();
|
marci@269
|
976 |
// while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
|
marci@168
|
977 |
// while (v.valid() && !in.valid()) {
|
marci@168
|
978 |
// ++v;
|
marci@212
|
979 |
// if (v.valid()) G->first(in, v);
|
marci@269
|
980 |
// while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
|
marci@168
|
981 |
// }
|
marci@168
|
982 |
// }
|
marci@168
|
983 |
// } else {
|
marci@168
|
984 |
// ++in;
|
marci@269
|
985 |
// while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
|
marci@168
|
986 |
// while (v.valid() && !in.valid()) {
|
marci@168
|
987 |
// ++v;
|
marci@212
|
988 |
// if (v.valid()) G->first(in, v);
|
marci@269
|
989 |
// while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
|
marci@168
|
990 |
// }
|
marci@168
|
991 |
// }
|
marci@168
|
992 |
// return *this;
|
marci@168
|
993 |
// }
|
marci@155
|
994 |
};
|
marci@155
|
995 |
|
marci@303
|
996 |
NodeIt& first(NodeIt& v) const { graph->first(v); return v; }
|
marci@212
|
997 |
OutEdgeIt& first(OutEdgeIt& e, Node v) const {
|
marci@168
|
998 |
e=OutEdgeIt(*this, v);
|
marci@174
|
999 |
return e;
|
marci@155
|
1000 |
}
|
marci@212
|
1001 |
EdgeIt& first(EdgeIt& e) const {
|
marci@174
|
1002 |
e=EdgeIt(*this);
|
marci@174
|
1003 |
return e;
|
marci@155
|
1004 |
}
|
marci@155
|
1005 |
|
marci@305
|
1006 |
NodeIt& next(NodeIt& n) const { graph->next(n); return n; }
|
marci@155
|
1007 |
|
marci@155
|
1008 |
OutEdgeIt& next(OutEdgeIt& e) const {
|
marci@155
|
1009 |
if (e.out_or_in) {
|
marci@303
|
1010 |
Node v=graph->aNode(e.out);
|
marci@303
|
1011 |
graph->next(e.out);
|
marci@303
|
1012 |
while( graph->valid(e.out) && !(resCap(e.out)>0) ) { graph->next(e.out); }
|
marci@303
|
1013 |
if (!graph->valid(e.out)) {
|
marci@155
|
1014 |
e.out_or_in=0;
|
marci@303
|
1015 |
graph->first(e.in, v);
|
marci@303
|
1016 |
while( graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); }
|
marci@155
|
1017 |
}
|
marci@155
|
1018 |
} else {
|
marci@303
|
1019 |
graph->next(e.in);
|
marci@303
|
1020 |
while( graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); }
|
marci@155
|
1021 |
}
|
marci@155
|
1022 |
return e;
|
marci@155
|
1023 |
}
|
marci@155
|
1024 |
|
marci@174
|
1025 |
EdgeIt& next(EdgeIt& e) const {
|
marci@155
|
1026 |
if (e.out_or_in) {
|
marci@303
|
1027 |
graph->next(e.out);
|
marci@303
|
1028 |
while (graph->valid(e.out) && !(resCap(e.out)>0) ) { graph->next(e.out); }
|
marci@303
|
1029 |
while (graph->valid(e.v) && !graph->valid(e.out)) {
|
marci@303
|
1030 |
graph->next(e.v);
|
marci@303
|
1031 |
if (graph->valid(e.v)) graph->first(e.out, e.v);
|
marci@303
|
1032 |
while (graph->valid(e.out) && !(resCap(e.out)>0) ) { graph->next(e.out); }
|
marci@155
|
1033 |
}
|
marci@303
|
1034 |
if (!graph->valid(e.out)) {
|
marci@155
|
1035 |
e.out_or_in=0;
|
marci@303
|
1036 |
graph->first(e.v);
|
marci@303
|
1037 |
if (graph->valid(e.v)) graph->first(e.in, e.v); else e.in=INVALID;
|
marci@303
|
1038 |
while (graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); }
|
marci@303
|
1039 |
while (graph->valid(e.v) && !graph->valid(e.in)) {
|
marci@303
|
1040 |
graph->next(e.v);
|
marci@303
|
1041 |
if (graph->valid(e.v)) graph->first(e.in, e.v);
|
marci@303
|
1042 |
while (graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); }
|
marci@155
|
1043 |
}
|
marci@155
|
1044 |
}
|
marci@155
|
1045 |
} else {
|
marci@303
|
1046 |
graph->next(e.in);
|
marci@303
|
1047 |
while (graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); }
|
marci@303
|
1048 |
while (graph->valid(e.v) && !graph->valid(e.in)) {
|
marci@303
|
1049 |
graph->next(e.v);
|
marci@303
|
1050 |
if (graph->valid(e.v)) graph->first(e.in, e.v);
|
marci@303
|
1051 |
while (graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); }
|
marci@155
|
1052 |
}
|
marci@155
|
1053 |
}
|
marci@155
|
1054 |
return e;
|
marci@155
|
1055 |
}
|
marci@76
|
1056 |
|
marci@76
|
1057 |
|
marci@155
|
1058 |
template< typename It >
|
marci@155
|
1059 |
It first() const {
|
marci@155
|
1060 |
It e;
|
marci@212
|
1061 |
first(e);
|
marci@155
|
1062 |
return e;
|
marci@155
|
1063 |
}
|
marci@76
|
1064 |
|
marci@155
|
1065 |
template< typename It >
|
marci@174
|
1066 |
It first(Node v) const {
|
marci@155
|
1067 |
It e;
|
marci@212
|
1068 |
first(e, v);
|
marci@155
|
1069 |
return e;
|
marci@155
|
1070 |
}
|
marci@76
|
1071 |
|
marci@174
|
1072 |
Node tail(Edge e) const {
|
marci@303
|
1073 |
return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
|
marci@174
|
1074 |
Node head(Edge e) const {
|
marci@303
|
1075 |
return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
|
marci@76
|
1076 |
|
marci@174
|
1077 |
Node aNode(OutEdgeIt e) const {
|
marci@303
|
1078 |
return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
|
marci@174
|
1079 |
Node bNode(OutEdgeIt e) const {
|
marci@303
|
1080 |
return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
|
marci@76
|
1081 |
|
marci@303
|
1082 |
int nodeNum() const { return graph->nodeNum(); }
|
marci@263
|
1083 |
//FIXME
|
marci@303
|
1084 |
//int edgeNum() const { return graph->edgeNum(); }
|
marci@263
|
1085 |
|
marci@263
|
1086 |
|
marci@303
|
1087 |
int id(Node v) const { return graph->id(v); }
|
marci@155
|
1088 |
|
marci@303
|
1089 |
bool valid(Node n) const { return graph->valid(n); }
|
marci@174
|
1090 |
bool valid(Edge e) const {
|
marci@303
|
1091 |
return e.out_or_in ? graph->valid(e.out) : graph->valid(e.in); }
|
marci@155
|
1092 |
|
marci@174
|
1093 |
void augment(const Edge& e, Number a) const {
|
marci@168
|
1094 |
if (e.out_or_in)
|
marci@303
|
1095 |
// flow->set(e.out, flow->get(e.out)+a);
|
marci@303
|
1096 |
flow->set(e.out, (*flow)[e.out]+a);
|
marci@168
|
1097 |
else
|
marci@303
|
1098 |
// flow->set(e.in, flow->get(e.in)-a);
|
marci@303
|
1099 |
flow->set(e.in, (*flow)[e.in]-a);
|
marci@168
|
1100 |
}
|
marci@168
|
1101 |
|
marci@269
|
1102 |
Number resCap(const Edge& e) const {
|
marci@168
|
1103 |
if (e.out_or_in)
|
marci@303
|
1104 |
// return (capacity->get(e.out)-flow->get(e.out));
|
marci@303
|
1105 |
return ((*capacity)[e.out]-(*flow)[e.out]);
|
marci@168
|
1106 |
else
|
marci@303
|
1107 |
// return (flow->get(e.in));
|
marci@303
|
1108 |
return ((*flow)[e.in]);
|
marci@168
|
1109 |
}
|
marci@168
|
1110 |
|
marci@303
|
1111 |
Number resCap(GraphOutEdgeIt out) const {
|
marci@303
|
1112 |
// return (capacity->get(out)-flow->get(out));
|
marci@303
|
1113 |
return ((*capacity)[out]-(*flow)[out]);
|
marci@168
|
1114 |
}
|
marci@168
|
1115 |
|
marci@303
|
1116 |
Number resCap(GraphInEdgeIt in) const {
|
marci@303
|
1117 |
// return (flow->get(in));
|
marci@303
|
1118 |
return ((*flow)[in]);
|
marci@168
|
1119 |
}
|
marci@168
|
1120 |
|
marci@303
|
1121 |
// template<typename T> class NodeMap : public Graph::NodeMap<T> {
|
marci@266
|
1122 |
// public:
|
marci@303
|
1123 |
// NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G)
|
marci@303
|
1124 |
// : Graph::NodeMap<T>(_G.gw) { }
|
marci@303
|
1125 |
// NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G,
|
marci@303
|
1126 |
// T a) : Graph::NodeMap<T>(_G.gw, a) { }
|
marci@266
|
1127 |
// };
|
marci@155
|
1128 |
|
marci@155
|
1129 |
// template <typename T>
|
marci@155
|
1130 |
// class NodeMap {
|
marci@155
|
1131 |
// typename Graph::NodeMap<T> node_map;
|
marci@155
|
1132 |
// public:
|
marci@174
|
1133 |
// NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { }
|
marci@174
|
1134 |
// NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { }
|
marci@174
|
1135 |
// void set(Node nit, T a) { node_map.set(nit, a); }
|
marci@174
|
1136 |
// T get(Node nit) const { return node_map.get(nit); }
|
marci@155
|
1137 |
// };
|
marci@155
|
1138 |
|
marci@155
|
1139 |
template <typename T>
|
marci@155
|
1140 |
class EdgeMap {
|
marci@303
|
1141 |
typename Graph::EdgeMap<T> forward_map, backward_map;
|
marci@155
|
1142 |
public:
|
marci@303
|
1143 |
EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
|
marci@303
|
1144 |
EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
|
marci@174
|
1145 |
void set(Edge e, T a) {
|
marci@155
|
1146 |
if (e.out_or_in)
|
marci@155
|
1147 |
forward_map.set(e.out, a);
|
marci@155
|
1148 |
else
|
marci@155
|
1149 |
backward_map.set(e.in, a);
|
marci@155
|
1150 |
}
|
marci@303
|
1151 |
T operator[](Edge e) const {
|
marci@155
|
1152 |
if (e.out_or_in)
|
marci@303
|
1153 |
return forward_map[e.out];
|
marci@155
|
1154 |
else
|
marci@303
|
1155 |
return backward_map[e.in];
|
marci@155
|
1156 |
}
|
marci@303
|
1157 |
// T get(Edge e) const {
|
marci@303
|
1158 |
// if (e.out_or_in)
|
marci@303
|
1159 |
// return forward_map.get(e.out);
|
marci@303
|
1160 |
// else
|
marci@303
|
1161 |
// return backward_map.get(e.in);
|
marci@303
|
1162 |
// }
|
marci@155
|
1163 |
};
|
marci@168
|
1164 |
};
|
marci@168
|
1165 |
|
marci@303
|
1166 |
//ErasingFirstGraphWrapper for blocking flows
|
marci@303
|
1167 |
template<typename Graph, typename FirstOutEdgesMap>
|
marci@303
|
1168 |
class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
|
marci@269
|
1169 |
protected:
|
marci@269
|
1170 |
FirstOutEdgesMap* first_out_edges;
|
marci@269
|
1171 |
public:
|
marci@303
|
1172 |
typedef typename GraphWrapper<Graph>::Node Node;
|
marci@303
|
1173 |
typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
|
marci@303
|
1174 |
typedef typename GraphWrapper<Graph>::Edge Edge;
|
marci@303
|
1175 |
typedef typename GraphWrapper<Graph>::EdgeIt EdgeIt;
|
marci@303
|
1176 |
typedef typename GraphWrapper<Graph>::InEdgeIt InEdgeIt;
|
marci@303
|
1177 |
typedef typename GraphWrapper<Graph>::OutEdgeIt OutEdgeIt;
|
marci@269
|
1178 |
|
marci@303
|
1179 |
ErasingFirstGraphWrapper(Graph& _graph,
|
marci@303
|
1180 |
FirstOutEdgesMap& _first_out_edges) :
|
marci@303
|
1181 |
GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { }
|
marci@269
|
1182 |
|
marci@269
|
1183 |
template<typename I> I& first(I& i) const {
|
marci@303
|
1184 |
graph->first(i);
|
marci@269
|
1185 |
return i;
|
marci@269
|
1186 |
}
|
marci@269
|
1187 |
OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
|
marci@303
|
1188 |
// e=first_out_edges->get(n);
|
marci@303
|
1189 |
e=(*first_out_edges)[n];
|
marci@269
|
1190 |
return e;
|
marci@269
|
1191 |
}
|
marci@269
|
1192 |
template<typename I, typename P> I& first(I& i, const P& p) const {
|
marci@303
|
1193 |
graph->first(i, p);
|
marci@269
|
1194 |
return i;
|
marci@269
|
1195 |
}
|
marci@269
|
1196 |
|
marci@269
|
1197 |
//template<typename I> I getNext(const I& i) const {
|
marci@269
|
1198 |
// return gw.getNext(i);
|
marci@269
|
1199 |
//}
|
marci@269
|
1200 |
template<typename I> I& next(I &i) const {
|
marci@303
|
1201 |
graph->next(i);
|
marci@269
|
1202 |
return i;
|
marci@269
|
1203 |
}
|
marci@269
|
1204 |
|
marci@269
|
1205 |
template< typename It > It first() const {
|
marci@269
|
1206 |
It e; this->first(e); return e; }
|
marci@269
|
1207 |
|
marci@269
|
1208 |
template< typename It > It first(const Node& v) const {
|
marci@269
|
1209 |
It e; this->first(e, v); return e; }
|
marci@269
|
1210 |
|
marci@269
|
1211 |
void erase(const OutEdgeIt& e) const {
|
marci@269
|
1212 |
OutEdgeIt f=e;
|
marci@269
|
1213 |
this->next(f);
|
marci@269
|
1214 |
first_out_edges->set(this->tail(e), f);
|
marci@269
|
1215 |
}
|
marci@269
|
1216 |
};
|
marci@269
|
1217 |
|
marci@148
|
1218 |
// // FIXME: comparison should be made better!!!
|
marci@148
|
1219 |
// template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
|
marci@148
|
1220 |
// class ResGraphWrapper
|
marci@148
|
1221 |
// {
|
marci@148
|
1222 |
// Graph* graph;
|
marci@76
|
1223 |
|
marci@148
|
1224 |
// public:
|
marci@303
|
1225 |
// typedef Graph ParentGraph;
|
marci@76
|
1226 |
|
marci@174
|
1227 |
// typedef typename Graph::Node Node;
|
marci@174
|
1228 |
// typedef typename Graph::Edge Edge;
|
marci@174
|
1229 |
|
marci@148
|
1230 |
// typedef typename Graph::NodeIt NodeIt;
|
marci@76
|
1231 |
|
marci@148
|
1232 |
// class OutEdgeIt {
|
marci@148
|
1233 |
// public:
|
marci@174
|
1234 |
// //Graph::Node n;
|
marci@148
|
1235 |
// bool out_or_in;
|
marci@148
|
1236 |
// typename Graph::OutEdgeIt o;
|
marci@148
|
1237 |
// typename Graph::InEdgeIt i;
|
marci@148
|
1238 |
// };
|
marci@148
|
1239 |
// class InEdgeIt {
|
marci@148
|
1240 |
// public:
|
marci@174
|
1241 |
// //Graph::Node n;
|
marci@148
|
1242 |
// bool out_or_in;
|
marci@148
|
1243 |
// typename Graph::OutEdgeIt o;
|
marci@148
|
1244 |
// typename Graph::InEdgeIt i;
|
marci@148
|
1245 |
// };
|
marci@148
|
1246 |
// typedef typename Graph::SymEdgeIt SymEdgeIt;
|
marci@174
|
1247 |
// typedef typename Graph::EdgeIt EdgeIt;
|
marci@76
|
1248 |
|
marci@259
|
1249 |
// int nodeNum() const { return gw.nodeNum(); }
|
marci@259
|
1250 |
// int edgeNum() const { return gw.edgeNum(); }
|
marci@76
|
1251 |
|
marci@259
|
1252 |
// Node& first(Node& n) const { return gw.first(n); }
|
marci@76
|
1253 |
|
marci@174
|
1254 |
// // Edge and SymEdge is missing!!!!
|
marci@174
|
1255 |
// // Edge <-> In/OutEdgeIt conversion is missing!!!!
|
marci@76
|
1256 |
|
marci@148
|
1257 |
// //FIXME
|
marci@212
|
1258 |
// OutEdgeIt& first(OutEdgeIt& e, const Node& n) const
|
marci@148
|
1259 |
// {
|
marci@148
|
1260 |
// e.n=n;
|
marci@259
|
1261 |
// gw.first(e.o,n);
|
marci@259
|
1262 |
// while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
|
marci@259
|
1263 |
// gw.goNext(e.o);
|
marci@259
|
1264 |
// if(!gw.valid(e.o)) {
|
marci@259
|
1265 |
// gw.first(e.i,n);
|
marci@259
|
1266 |
// while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
|
marci@259
|
1267 |
// gw.goNext(e.i);
|
marci@148
|
1268 |
// }
|
marci@148
|
1269 |
// return e;
|
marci@148
|
1270 |
// }
|
marci@148
|
1271 |
// /*
|
marci@148
|
1272 |
// OutEdgeIt &goNext(OutEdgeIt &e)
|
marci@148
|
1273 |
// {
|
marci@259
|
1274 |
// if(gw.valid(e.o)) {
|
marci@259
|
1275 |
// while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
|
marci@259
|
1276 |
// gw.goNext(e.o);
|
marci@259
|
1277 |
// if(gw.valid(e.o)) return e;
|
marci@259
|
1278 |
// else gw.first(e.i,e.n);
|
marci@148
|
1279 |
// }
|
marci@148
|
1280 |
// else {
|
marci@259
|
1281 |
// while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
|
marci@259
|
1282 |
// gw.goNext(e.i);
|
marci@148
|
1283 |
// return e;
|
marci@148
|
1284 |
// }
|
marci@148
|
1285 |
// }
|
marci@148
|
1286 |
// OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
|
marci@148
|
1287 |
// */
|
marci@259
|
1288 |
// //bool valid(const OutEdgeIt e) { return gw.valid(e.o)||gw.valid(e.i);}
|
marci@76
|
1289 |
|
marci@148
|
1290 |
// //FIXME
|
marci@212
|
1291 |
// InEdgeIt& first(InEdgeIt& e, const Node& n) const
|
marci@148
|
1292 |
// {
|
marci@148
|
1293 |
// e.n=n;
|
marci@259
|
1294 |
// gw.first(e.i,n);
|
marci@259
|
1295 |
// while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
|
marci@259
|
1296 |
// gw.goNext(e.i);
|
marci@259
|
1297 |
// if(!gw.valid(e.i)) {
|
marci@259
|
1298 |
// gw.first(e.o,n);
|
marci@259
|
1299 |
// while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
|
marci@259
|
1300 |
// gw.goNext(e.o);
|
marci@148
|
1301 |
// }
|
marci@148
|
1302 |
// return e;
|
marci@148
|
1303 |
// }
|
marci@148
|
1304 |
// /*
|
marci@148
|
1305 |
// InEdgeIt &goNext(InEdgeIt &e)
|
marci@148
|
1306 |
// {
|
marci@259
|
1307 |
// if(gw.valid(e.i)) {
|
marci@259
|
1308 |
// while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
|
marci@259
|
1309 |
// gw.goNext(e.i);
|
marci@259
|
1310 |
// if(gw.valid(e.i)) return e;
|
marci@259
|
1311 |
// else gw.first(e.o,e.n);
|
marci@148
|
1312 |
// }
|
marci@148
|
1313 |
// else {
|
marci@259
|
1314 |
// while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
|
marci@259
|
1315 |
// gw.goNext(e.o);
|
marci@148
|
1316 |
// return e;
|
marci@148
|
1317 |
// }
|
marci@148
|
1318 |
// }
|
marci@148
|
1319 |
// InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
|
marci@148
|
1320 |
// */
|
marci@259
|
1321 |
// //bool valid(const InEdgeIt e) { return gw.valid(e.i)||gw.valid(e.o);}
|
marci@76
|
1322 |
|
marci@259
|
1323 |
// //template<typename I> I &goNext(I &i); { return gw.goNext(i); }
|
marci@259
|
1324 |
// //template<typename I> I next(const I i); { return gw.goNext(i); }
|
marci@76
|
1325 |
|
marci@148
|
1326 |
// template< typename It > It first() const {
|
marci@212
|
1327 |
// It e; first(e); return e; }
|
marci@76
|
1328 |
|
marci@174
|
1329 |
// template< typename It > It first(Node v) const {
|
marci@212
|
1330 |
// It e; first(e, v); return e; }
|
marci@76
|
1331 |
|
marci@259
|
1332 |
// Node head(const Edge& e) const { return gw.head(e); }
|
marci@259
|
1333 |
// Node tail(const Edge& e) const { return gw.tail(e); }
|
marci@76
|
1334 |
|
marci@174
|
1335 |
// template<typename I> Node aNode(const I& e) const {
|
marci@259
|
1336 |
// return gw.aNode(e); }
|
marci@174
|
1337 |
// template<typename I> Node bNode(const I& e) const {
|
marci@259
|
1338 |
// return gw.bNode(e); }
|
marci@76
|
1339 |
|
marci@148
|
1340 |
// //template<typename I> bool valid(const I i);
|
marci@259
|
1341 |
// //{ return gw.valid(i); }
|
marci@76
|
1342 |
|
marci@148
|
1343 |
// //template<typename I> void setInvalid(const I &i);
|
marci@259
|
1344 |
// //{ return gw.setInvalid(i); }
|
marci@76
|
1345 |
|
marci@259
|
1346 |
// Node addNode() { return gw.addNode(); }
|
marci@174
|
1347 |
// Edge addEdge(const Node& tail, const Node& head) {
|
marci@259
|
1348 |
// return gw.addEdge(tail, head); }
|
marci@76
|
1349 |
|
marci@259
|
1350 |
// template<typename I> void erase(const I& i) { gw.erase(i); }
|
marci@76
|
1351 |
|
marci@259
|
1352 |
// void clear() { gw.clear(); }
|
marci@76
|
1353 |
|
marci@148
|
1354 |
// template<typename S> class NodeMap : public Graph::NodeMap<S> { };
|
marci@148
|
1355 |
// template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
|
marci@76
|
1356 |
|
marci@148
|
1357 |
// void setGraph(Graph& _graph) { graph = &_graph; }
|
marci@148
|
1358 |
// Graph& getGraph() { return (*graph); }
|
marci@76
|
1359 |
|
marci@148
|
1360 |
// //ResGraphWrapper() : graph(0) { }
|
marci@148
|
1361 |
// ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
|
marci@148
|
1362 |
// };
|
marci@76
|
1363 |
|
alpar@105
|
1364 |
} //namespace hugo
|
marci@76
|
1365 |
|
marci@259
|
1366 |
#endif //HUGO_GRAPH_WRAPPER_H
|
marci@76
|
1367 |
|