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