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