2 #ifndef HUGO_GRAPH_WRAPPER_H
3 #define HUGO_GRAPH_WRAPPER_H
9 template<typename Graph>
10 class TrivGraphWrapper {
15 typedef Graph BaseGraph;
17 typedef typename Graph::Node Node;
18 class NodeIt : public Graph::NodeIt {
21 NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { }
22 NodeIt(const Invalid& i) : Graph::NodeIt(i) { }
23 NodeIt(const TrivGraphWrapper<Graph>& _G) :
24 Graph::NodeIt(*(_G.graph)) { }
26 typedef typename Graph::Edge Edge;
27 //typedef typename Graph::OutEdgeIt OutEdgeIt;
28 class OutEdgeIt : public Graph::OutEdgeIt {
31 OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { }
32 OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { }
33 OutEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) :
34 Graph::OutEdgeIt(*(_G.graph), n) { }
36 //typedef typename Graph::InEdgeIt InEdgeIt;
37 class InEdgeIt : public Graph::InEdgeIt {
40 InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { }
41 InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { }
42 InEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) :
43 Graph::InEdgeIt(*(_G.graph), n) { }
45 //typedef typename Graph::SymEdgeIt SymEdgeIt;
46 //typedef typename Graph::EdgeIt EdgeIt;
47 class EdgeIt : public Graph::EdgeIt {
50 EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { }
51 EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { }
52 EdgeIt(const TrivGraphWrapper<Graph>& _G) :
53 Graph::EdgeIt(*(_G.graph)) { }
56 //TrivGraphWrapper() : graph(0) { }
57 TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
59 // void setGraph(Graph& _graph) { graph = &_graph; }
60 // Graph& getGraph() const { return (*graph); }
62 NodeIt& first(NodeIt& i) const {
66 EdgeIt& first(EdgeIt& i) const {
70 // template<typename I> I& first(I& i) const {
71 // //return graph->first(i);
75 OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
76 i=OutEdgeIt(*this, p);
79 InEdgeIt& first(InEdgeIt& i, const Node& p) const {
83 // template<typename I, typename P> I& first(I& i, const P& p) const {
84 // //return graph->first(i, p);
89 // template<typename I> I getNext(const I& i) const {
90 // return graph->getNext(i); }
91 template<typename I> I& next(I &i) const { graph->next(i); return i; }
93 template< typename It > It first() const {
94 It e; first(e); return e; }
96 template< typename It > It first(const Node& v) const {
97 It e; first(e, v); return e; }
99 Node head(const Edge& e) const { return graph->head(e); }
100 Node tail(const Edge& e) const { return graph->tail(e); }
102 template<typename I> bool valid(const I& i) const
103 { return graph->valid(i); }
105 //template<typename I> void setInvalid(const I &i);
106 //{ return graph->setInvalid(i); }
108 int nodeNum() const { return graph->nodeNum(); }
109 int edgeNum() const { return graph->edgeNum(); }
111 template<typename I> Node aNode(const I& e) const {
112 return graph->aNode(e); }
113 template<typename I> Node bNode(const I& e) const {
114 return graph->bNode(e); }
116 Node addNode() const { return graph->addNode(); }
117 Edge addEdge(const Node& tail, const Node& head) const {
118 return graph->addEdge(tail, head); }
120 template<typename I> void erase(const I& i) const { graph->erase(i); }
122 void clear() const { graph->clear(); }
124 template<typename T> class NodeMap : public Graph::NodeMap<T> {
126 NodeMap(const TrivGraphWrapper<Graph>& _G) :
127 Graph::NodeMap<T>(*(_G.graph)) { }
128 NodeMap(const TrivGraphWrapper<Graph>& _G, T a) :
129 Graph::NodeMap<T>(*(_G.graph), a) { }
132 template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
134 EdgeMap(const TrivGraphWrapper<Graph>& _G) :
135 Graph::EdgeMap<T>(*(_G.graph)) { }
136 EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) :
137 Graph::EdgeMap<T>(*(_G.graph), a) { }
141 template<typename GraphWrapper>
142 class GraphWrapperSkeleton {
147 //typedef typename GraphWrapper::BaseGraph BaseGraph;
149 // typedef typename GraphWrapper::Node Node;
150 // typedef typename GraphWrapper::NodeIt NodeIt;
152 // typedef typename GraphWrapper::Edge Edge;
153 // typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
154 // typedef typename GraphWrapper::InEdgeIt InEdgeIt;
155 // //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
156 // typedef typename GraphWrapper::EdgeIt EdgeIt;
158 typedef typename GraphWrapper::Node Node;
159 class NodeIt : public GraphWrapper::NodeIt {
162 NodeIt(const typename GraphWrapper::NodeIt& n) :
163 GraphWrapper::NodeIt(n) { }
164 NodeIt(const Invalid& i) : GraphWrapper::NodeIt(i) { }
165 NodeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) :
166 GraphWrapper::NodeIt(_G.gw) { }
168 typedef typename GraphWrapper::Edge Edge;
169 //typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
170 class OutEdgeIt : public GraphWrapper::OutEdgeIt {
173 OutEdgeIt(const typename GraphWrapper::OutEdgeIt& e) :
174 GraphWrapper::OutEdgeIt(e) { }
175 OutEdgeIt(const Invalid& i) : GraphWrapper::OutEdgeIt(i) { }
176 OutEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) :
177 GraphWrapper::OutEdgeIt(_G.gw, n) { }
179 //typedef typename GraphWrapper::InEdgeIt InEdgeIt;
180 class InEdgeIt : public GraphWrapper::InEdgeIt {
183 InEdgeIt(const typename GraphWrapper::InEdgeIt& e) :
184 GraphWrapper::InEdgeIt(e) { }
185 InEdgeIt(const Invalid& i) : GraphWrapper::InEdgeIt(i) { }
186 InEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) :
187 GraphWrapper::InEdgeIt(_G.gw, n) { }
189 //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
190 //typedef typename GraphWrapper::EdgeIt EdgeIt;
191 class EdgeIt : public GraphWrapper::EdgeIt {
194 EdgeIt(const typename GraphWrapper::EdgeIt& e) :
195 GraphWrapper::EdgeIt(e) { }
196 EdgeIt(const Invalid& i) : GraphWrapper::EdgeIt(i) { }
197 EdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) :
198 GraphWrapper::EdgeIt(_G.gw) { }
202 //GraphWrapperSkeleton() : gw() { }
203 GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
205 //void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
206 //BaseGraph& getGraph() const { return gw.getGraph(); }
208 template<typename I> I& first(I& i) const {
212 template<typename I, typename P> I& first(I& i, const P& p) const {
217 // template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
218 template<typename I> I& next(I &i) const { gw.next(i); return i; }
220 template< typename It > It first() const {
221 It e; this->first(e); return e; }
223 template< typename It > It first(const Node& v) const {
224 It e; this->first(e, v); return e; }
226 Node head(const Edge& e) const { return gw.head(e); }
227 Node tail(const Edge& e) const { return gw.tail(e); }
229 template<typename I> bool valid(const I& i) const { return gw.valid(i); }
231 //template<typename I> void setInvalid(const I &i);
232 //{ return graph->setInvalid(i); }
234 int nodeNum() const { return gw.nodeNum(); }
235 int edgeNum() const { return gw.edgeNum(); }
237 template<typename I> Node aNode(const I& e) const { return gw.aNode(e); }
238 template<typename I> Node bNode(const I& e) const { return gw.bNode(e); }
240 Node addNode() const { return gw.addNode(); }
241 Edge addEdge(const Node& tail, const Node& head) const {
242 return gw.addEdge(tail, head); }
244 template<typename I> void erase(const I& i) const { gw.erase(i); }
246 void clear() const { gw.clear(); }
248 template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
250 NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :
251 GraphWrapper::NodeMap<T>(_G.gw) { }
252 NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) :
253 GraphWrapper::NodeMap<T>(_G.gw, a) { }
256 template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
258 EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :
259 GraphWrapper::EdgeMap<T>(_G.gw) { }
260 EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) :
261 GraphWrapper::EdgeMap<T>(_G.gw, a) { }
265 // template<typename Graph>
266 // class RevGraphWrapper
272 // typedef Graph BaseGraph;
274 // typedef typename Graph::Node Node;
275 // typedef typename Graph::NodeIt NodeIt;
277 // typedef typename Graph::Edge Edge;
278 // typedef typename Graph::OutEdgeIt InEdgeIt;
279 // typedef typename Graph::InEdgeIt OutEdgeIt;
280 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
281 // typedef typename Graph::EdgeIt EdgeIt;
283 // //RevGraphWrapper() : graph(0) { }
284 // RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
286 // void setGraph(Graph& _graph) { graph = &_graph; }
287 // Graph& getGraph() const { return (*graph); }
289 // template<typename I> I& first(I& i) const { return graph->first(i); }
290 // template<typename I, typename P> I& first(I& i, const P& p) const {
291 // return graph->first(i, p); }
293 // template<typename I> I getNext(const I& i) const {
294 // return graph->getNext(i); }
295 // template<typename I> I& next(I &i) const { return graph->next(i); }
297 // template< typename It > It first() const {
298 // It e; first(e); return e; }
300 // template< typename It > It first(const Node& v) const {
301 // It e; first(e, v); return e; }
303 // Node head(const Edge& e) const { return graph->tail(e); }
304 // Node tail(const Edge& e) const { return graph->head(e); }
306 // template<typename I> bool valid(const I& i) const
307 // { return graph->valid(i); }
309 // //template<typename I> void setInvalid(const I &i);
310 // //{ return graph->setInvalid(i); }
312 // template<typename I> Node aNode(const I& e) const {
313 // return graph->aNode(e); }
314 // template<typename I> Node bNode(const I& e) const {
315 // return graph->bNode(e); }
317 // Node addNode() const { return graph->addNode(); }
318 // Edge addEdge(const Node& tail, const Node& head) const {
319 // return graph->addEdge(tail, head); }
321 // int nodeNum() const { return graph->nodeNum(); }
322 // int edgeNum() const { return graph->edgeNum(); }
324 // template<typename I> void erase(const I& i) const { graph->erase(i); }
326 // void clear() const { graph->clear(); }
328 // template<typename T> class NodeMap : public Graph::NodeMap<T> {
330 // NodeMap(const RevGraphWrapper<Graph>& _G) :
331 // Graph::NodeMap<T>(_G.getGraph()) { }
332 // NodeMap(const RevGraphWrapper<Graph>& _G, T a) :
333 // Graph::NodeMap<T>(_G.getGraph(), a) { }
336 // template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
338 // EdgeMap(const RevGraphWrapper<Graph>& _G) :
339 // Graph::EdgeMap<T>(_G.getGraph()) { }
340 // EdgeMap(const RevGraphWrapper<Graph>& _G, T a) :
341 // Graph::EdgeMap<T>(_G.getGraph(), a) { }
345 // template<typename /*Graph*/GraphWrapper
346 // /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ >
347 // class RevGraphWrapper :
348 // public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ {
353 // //typedef Graph BaseGraph;
355 // //typedef typename Graph::Node Node;
356 // //typedef typename Graph::NodeIt NodeIt;
358 // //typedef typename Graph::Edge Edge;
359 // typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::OutEdgeIt InEdgeIt;
360 // typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::InEdgeIt OutEdgeIt;
361 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
362 // //typedef typename Graph::EdgeIt EdgeIt;
364 // //RevGraphWrapper() : graph(0) { }
365 // RevGraphWrapper(GraphWrapper _gw/*BaseGraph& _graph*/) : GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/(_gw/*TrivGraphWrapper<Graph>(_graph)*/) { }
367 // //void setGraph(Graph& _graph) { graph = &_graph; }
368 // //Graph& getGraph() const { return (*graph); }
370 // //template<typename I> I& first(I& i) const { return graph->first(i); }
371 // //template<typename I, typename P> I& first(I& i, const P& p) const {
372 // // return graph->first(i, p); }
374 // //template<typename I> I getNext(const I& i) const {
375 // // return graph->getNext(i); }
376 // //template<typename I> I& next(I &i) const { return graph->next(i); }
378 // //template< typename It > It first() const {
379 // // It e; first(e); return e; }
381 // //template< typename It > It first(const Node& v) const {
382 // // It e; first(e, v); return e; }
384 // //Node head(const Edge& e) const { return graph->tail(e); }
385 // //Node tail(const Edge& e) const { return graph->head(e); }
387 // //template<typename I> bool valid(const I& i) const
388 // // { return graph->valid(i); }
390 // //template<typename I> void setInvalid(const I &i);
391 // //{ return graph->setInvalid(i); }
393 // //template<typename I> Node aNode(const I& e) const {
394 // // return graph->aNode(e); }
395 // //template<typename I> Node bNode(const I& e) const {
396 // // return graph->bNode(e); }
398 // //Node addNode() const { return graph->addNode(); }
399 // //Edge addEdge(const Node& tail, const Node& head) const {
400 // // return graph->addEdge(tail, head); }
402 // //int nodeNum() const { return graph->nodeNum(); }
403 // //int edgeNum() const { return graph->edgeNum(); }
405 // //template<typename I> void erase(const I& i) const { graph->erase(i); }
407 // //void clear() const { graph->clear(); }
409 // template<typename T> class NodeMap :
410 // public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>
413 // NodeMap(const RevGraphWrapper<GraphWrapper>& _gw) :
414 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw) { }
415 // NodeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) :
416 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw, a) { }
419 // template<typename T> class EdgeMap :
420 // public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T> {
422 // EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw) :
423 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw) { }
424 // EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) :
425 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw, a) { }
430 template<typename GraphWrapper>
431 class RevGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
433 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
434 typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
435 typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt InEdgeIt;
436 typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt OutEdgeIt;
438 RevGraphWrapper(GraphWrapper _gw) :
439 GraphWrapperSkeleton<GraphWrapper>(_gw) { }
441 Node head(const Edge& e) const
442 { return GraphWrapperSkeleton<GraphWrapper>::tail(e); }
443 Node tail(const Edge& e) const
444 { return GraphWrapperSkeleton<GraphWrapper>::head(e); }
447 //Subgraph on the same node-set and partial edge-set
448 template<typename GraphWrapper, typename EdgeFilterMap>
449 class SubGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
451 EdgeFilterMap* filter_map;
453 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
454 typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
455 typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
456 typedef typename GraphWrapperSkeleton<GraphWrapper>::EdgeIt EdgeIt;
457 typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt InEdgeIt;
458 typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OutEdgeIt;
460 SubGraphWrapper(GraphWrapper _gw, EdgeFilterMap& _filter_map) :
461 GraphWrapperSkeleton<GraphWrapper>(_gw), filter_map(&_filter_map) { }
463 template<typename I> I& first(I& i) const {
465 while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
468 template<typename I, typename P> I& first(I& i, const P& p) const {
470 while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
474 //template<typename I> I getNext(const I& i) const {
475 // return gw.getNext(i);
477 template<typename I> I& next(I &i) const {
479 while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
483 template< typename It > It first() const {
484 It e; this->first(e); return e; }
486 template< typename It > It first(const Node& v) const {
487 It e; this->first(e, v); return e; }
490 // template<typename GraphWrapper>
491 // class UndirGraphWrapper {
497 // typedef GraphWrapper BaseGraph;
499 // typedef typename GraphWrapper::Node Node;
500 // typedef typename GraphWrapper::NodeIt NodeIt;
502 // //typedef typename Graph::Edge Edge;
503 // //typedef typename Graph::OutEdgeIt OutEdgeIt;
504 // //typedef typename Graph::InEdgeIt InEdgeIt;
505 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
506 // //typedef typename Graph::EdgeIt EdgeIt;
509 // typedef typename GraphWrapper::Edge GraphEdge;
510 // typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt;
511 // typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt;
514 // //UndirGraphWrapper() : graph(0) { }
515 // UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
517 // //void setGraph(Graph& _graph) { graph = &_graph; }
518 // //Graph& getGraph() const { return (*graph); }
521 // friend class UndirGraphWrapper<GraphWrapper>;
522 // bool out_or_in; //true iff out
523 // GraphOutEdgeIt out;
526 // Edge() : out_or_in(), out(), in() { }
527 // Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
528 // operator GraphEdge() const {
529 // if (out_or_in) return(out); else return(in);
531 // friend bool operator==(const Edge& u, const Edge& v) {
533 // return (u.out_or_in && u.out==v.out);
535 // return (!u.out_or_in && u.in==v.in);
537 // friend bool operator!=(const Edge& u, const Edge& v) {
539 // return (!u.out_or_in || u.out!=v.out);
541 // return (u.out_or_in || u.in!=v.in);
545 // class OutEdgeIt : public Edge {
546 // friend class UndirGraphWrapper<GraphWrapper>;
548 // OutEdgeIt() : Edge() { }
549 // OutEdgeIt(const Invalid& i) : Edge(i) { }
550 // OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n)
553 // _G.gw.first(out, n);
554 // if (!(_G.gw.valid(out))) {
556 // _G.gw.first(in, n);
561 // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
563 // gw.first(e.out, n);
564 // if (!(gw.valid(e.out))) {
565 // e.out_or_in=false;
566 // gw.first(e.in, n);
571 // OutEdgeIt& next(OutEdgeIt& e) const {
572 // if (e.out_or_in) {
573 // Node n=gw.tail(e.out);
575 // if (!gw.valid(e.out)) {
576 // e.out_or_in=false;
577 // gw.first(e.in, n);
585 // Node aNode(const OutEdgeIt& e) const {
586 // if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
587 // Node bNode(const OutEdgeIt& e) const {
588 // if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
590 // typedef OutEdgeIt InEdgeIt;
592 // template<typename I> I& first(I& i) const { return gw.first(i); }
593 // // template<typename I, typename P> I& first(I& i, const P& p) const {
594 // // return graph->first(i, p); }
596 // template<typename I> I getNext(const I& i) const {
597 // return gw.getNext(i); }
598 // template<typename I> I& next(I &i) const { return gw.next(i); }
600 // template< typename It > It first() const {
601 // It e; first(e); return e; }
603 // template< typename It > It first(const Node& v) const {
604 // It e; first(e, v); return e; }
606 // Node head(const Edge& e) const { return gw.head(e); }
607 // Node tail(const Edge& e) const { return gw.tail(e); }
609 // template<typename I> bool valid(const I& i) const
610 // { return gw.valid(i); }
612 // //template<typename I> void setInvalid(const I &i);
613 // //{ return graph->setInvalid(i); }
615 // int nodeNum() const { return gw.nodeNum(); }
616 // int edgeNum() const { return gw.edgeNum(); }
618 // // template<typename I> Node aNode(const I& e) const {
619 // // return graph->aNode(e); }
620 // // template<typename I> Node bNode(const I& e) const {
621 // // return graph->bNode(e); }
623 // Node addNode() const { return gw.addNode(); }
624 // // FIXME: ez igy nem jo, mert nem
625 // // Edge addEdge(const Node& tail, const Node& head) const {
626 // // return graph->addEdge(tail, head); }
628 // template<typename I> void erase(const I& i) const { gw.erase(i); }
630 // void clear() const { gw.clear(); }
632 // template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
634 // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
635 // GraphWrapper::NodeMap<T>(_G.gw) { }
636 // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
637 // GraphWrapper::NodeMap<T>(_G.gw, a) { }
640 // template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
642 // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
643 // GraphWrapper::EdgeMap<T>(_G.gw) { }
644 // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
645 // GraphWrapper::EdgeMap<T>(_G.gw, a) { }
650 template<typename GraphWrapper>
651 class UndirGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
656 //typedef GraphWrapper BaseGraph;
658 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
659 typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
662 typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge GraphEdge;
663 typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt GraphOutEdgeIt;
664 typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt GraphInEdgeIt;
667 //UndirGraphWrapper() : graph(0) { }
668 UndirGraphWrapper(GraphWrapper _gw) :
669 GraphWrapperSkeleton<GraphWrapper>(_gw) { }
671 //UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
673 //void setGraph(Graph& _graph) { graph = &_graph; }
674 //Graph& getGraph() const { return (*graph); }
677 friend class UndirGraphWrapper<GraphWrapper>;
678 bool out_or_in; //true iff out
682 Edge() : out_or_in(), out(), in() { }
683 Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
684 operator GraphEdge() const {
685 if (out_or_in) return(out); else return(in);
688 //2 edges are equal if they "refer" to the same physical edge
690 friend bool operator==(const Edge& u, const Edge& v) {
692 if (u.out_or_in) return (u.out==v.out); else return (u.out==v.in);
693 //return (u.out_or_in && u.out==v.out);
695 if (u.out_or_in) return (u.out==v.in); else return (u.in==v.in);
696 //return (!u.out_or_in && u.in==v.in);
698 friend bool operator!=(const Edge& u, const Edge& v) {
700 if (u.out_or_in) return (u.out!=v.out); else return (u.out!=v.in);
701 //return (!u.out_or_in || u.out!=v.out);
703 if (u.out_or_in) return (u.out!=v.in); else return (u.in!=v.in);
704 //return (u.out_or_in || u.in!=v.in);
708 class OutEdgeIt : public Edge {
709 friend class UndirGraphWrapper<GraphWrapper>;
711 OutEdgeIt() : Edge() { }
712 OutEdgeIt(const Invalid& i) : Edge(i) { }
713 OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n)
715 out_or_in=true; _G.gw.first(out, n);
716 if (!(_G.gw.valid(out))) { out_or_in=false; _G.gw.first(in, n); }
720 typedef OutEdgeIt InEdgeIt;
722 class EdgeIt : public Edge {
723 friend class UndirGraphWrapper<GraphWrapper>;
727 EdgeIt() : Edge() { }
728 EdgeIt(const Invalid& i) : Edge(i) { }
729 EdgeIt(const UndirGraphWrapper<GraphWrapper>& _G)
734 if (_G.valid(v)) _G.gw.first(out); else out=INVALID;
735 while (_G.valid(v) && !_G.gw.valid(out)) {
737 if (_G.valid(v)) _G.gw.first(out);
742 OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
743 e.out_or_in=true; gw.first(e.out, n);
744 if (!(gw.valid(e.out))) { e.out_or_in=false; gw.first(e.in, n); }
748 EdgeIt& first(EdgeIt& e) const {
752 if (valid(e.v)) gw.first(e.out, e.v); else e.out=INVALID;
753 while (valid(e.v) && !gw.valid(e.out)) {
755 if (valid(e.v)) gw.first(e.out, e.v);
760 template<typename I> I& first(I& i) const { gw.first(i); return i; }
761 template<typename I, typename P> I& first(I& i, const P& p) const {
762 graph->first(i, p); return i; }
764 OutEdgeIt& next(OutEdgeIt& e) const {
766 Node n=gw.tail(e.out);
768 if (!gw.valid(e.out)) { e.out_or_in=false; gw.first(e.in, n); }
775 EdgeIt& next(EdgeIt& e) const {
778 while (valid(e.v) && !gw.valid(e.out)) {
780 if (valid(e.v)) gw.first(e.out, e.v);
785 template<typename I> I& next(I &i) const { return gw.next(i); }
786 // template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
788 template< typename It > It first() const {
789 It e; first(e); return e; }
791 template< typename It > It first(const Node& v) const {
792 It e; first(e, v); return e; }
794 // Node head(const Edge& e) const { return gw.head(e); }
795 // Node tail(const Edge& e) const { return gw.tail(e); }
797 // template<typename I> bool valid(const I& i) const
798 // { return gw.valid(i); }
800 // int nodeNum() const { return gw.nodeNum(); }
801 // int edgeNum() const { return gw.edgeNum(); }
803 // template<typename I> Node aNode(const I& e) const {
804 // return graph->aNode(e); }
805 // template<typename I> Node bNode(const I& e) const {
806 // return graph->bNode(e); }
808 Node aNode(const OutEdgeIt& e) const {
809 if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
810 Node bNode(const OutEdgeIt& e) const {
811 if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
813 // Node addNode() const { return gw.addNode(); }
815 // FIXME: ez igy nem jo, mert nem
816 // Edge addEdge(const Node& tail, const Node& head) const {
817 // return graph->addEdge(tail, head); }
819 // template<typename I> void erase(const I& i) const { gw.erase(i); }
821 // void clear() const { gw.clear(); }
823 // template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
825 // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
826 // GraphWrapper::NodeMap<T>(_G.gw) { }
827 // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
828 // GraphWrapper::NodeMap<T>(_G.gw, a) { }
831 // template<typename T> class EdgeMap :
832 // public GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T> {
834 // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
835 // GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T>(_G.gw) { }
836 // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
837 // GraphWrapper::EdgeMap<T>(_G.gw, a) { }
845 // template<typename Graph>
846 // class SymGraphWrapper
851 // typedef Graph BaseGraph;
853 // typedef typename Graph::Node Node;
854 // typedef typename Graph::Edge Edge;
856 // typedef typename Graph::NodeIt NodeIt;
858 // //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
859 // //iranyitatlant, ami van
860 // //mert csak 1 dolgot lehet be typedef-elni
861 // typedef typename Graph::OutEdgeIt SymEdgeIt;
862 // //typedef typename Graph::InEdgeIt SymEdgeIt;
863 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
864 // typedef typename Graph::EdgeIt EdgeIt;
866 // int nodeNum() const { return graph->nodeNum(); }
867 // int edgeNum() const { return graph->edgeNum(); }
869 // template<typename I> I& first(I& i) const { return graph->first(i); }
870 // template<typename I, typename P> I& first(I& i, const P& p) const {
871 // return graph->first(i, p); }
872 // //template<typename I> I next(const I i); { return graph->goNext(i); }
873 // //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
875 // template< typename It > It first() const {
876 // It e; first(e); return e; }
878 // template< typename It > It first(Node v) const {
879 // It e; first(e, v); return e; }
881 // Node head(const Edge& e) const { return graph->head(e); }
882 // Node tail(const Edge& e) const { return graph->tail(e); }
884 // template<typename I> Node aNode(const I& e) const {
885 // return graph->aNode(e); }
886 // template<typename I> Node bNode(const I& e) const {
887 // return graph->bNode(e); }
889 // //template<typename I> bool valid(const I i);
890 // //{ return graph->valid(i); }
892 // //template<typename I> void setInvalid(const I &i);
893 // //{ return graph->setInvalid(i); }
895 // Node addNode() { return graph->addNode(); }
896 // Edge addEdge(const Node& tail, const Node& head) {
897 // return graph->addEdge(tail, head); }
899 // template<typename I> void erase(const I& i) { graph->erase(i); }
901 // void clear() { graph->clear(); }
903 // template<typename T> class NodeMap : public Graph::NodeMap<T> { };
904 // template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
906 // void setGraph(Graph& _graph) { graph = &_graph; }
907 // Graph& getGraph() { return (*graph); }
909 // //SymGraphWrapper() : graph(0) { }
910 // SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
914 template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
915 class ResGraphWrapper {
917 //typedef Graph BaseGraph;
918 typedef TrivGraphWrapper<const Graph> GraphWrapper;
919 typedef typename GraphWrapper::Node Node;
920 typedef typename GraphWrapper::NodeIt NodeIt;
922 typedef typename GraphWrapper::OutEdgeIt OldOutEdgeIt;
923 typedef typename GraphWrapper::InEdgeIt OldInEdgeIt;
925 //const Graph* graph;
928 const CapacityMap* capacity;
931 ResGraphWrapper(const Graph& _G, FlowMap& _flow,
932 const CapacityMap& _capacity) :
933 gw(_G), flow(&_flow), capacity(&_capacity) { }
935 //void setGraph(const Graph& _graph) { graph = &_graph; }
936 //const Graph& getGraph() const { return (*graph); }
941 friend class OutEdgeIt;
944 friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
946 bool out_or_in; //true, iff out
950 Edge() : out_or_in(true) { }
951 Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
952 // bool valid() const {
953 // return out_or_in && out.valid() || in.valid(); }
954 friend bool operator==(const Edge& u, const Edge& v) {
956 return (u.out_or_in && u.out==v.out);
958 return (!u.out_or_in && u.in==v.in);
960 friend bool operator!=(const Edge& u, const Edge& v) {
962 return (!u.out_or_in || u.out!=v.out);
964 return (u.out_or_in || u.in!=v.in);
969 class OutEdgeIt : public Edge {
970 friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
974 OutEdgeIt(const Edge& e) : Edge(e) { }
975 OutEdgeIt(const Invalid& i) : Edge(i) { }
977 OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() {
978 resG.gw.first(out, v);
979 while( resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); }
980 if (!resG.gw.valid(out)) {
982 resG.gw.first(in, v);
983 while( resG.gw.valid(in) && !(resG.free(in)>0) ) { resG.gw.next(in); }
987 // OutEdgeIt& operator++() {
989 // Node v=/*resG->*/G->aNode(out);
991 // while( out.valid() && !(Edge::free()>0) ) { ++out; }
992 // if (!out.valid()) {
995 // while( in.valid() && !(Edge::free()>0) ) { ++in; }
999 // while( in.valid() && !(Edge::free()>0) ) { ++in; }
1005 //FIXME This is just for having InEdgeIt
1006 typedef void InEdgeIt;
1008 class EdgeIt : public Edge {
1009 friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
1013 //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }
1014 EdgeIt(const Invalid& i) : Edge(i) { }
1015 EdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) : Edge() {
1017 if (resG.gw.valid(v)) resG.gw.first(out, v); else out=/*OldOutEdgeIt*/(INVALID);
1018 while (resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); }
1019 while (resG.gw.valid(v) && !resG.gw.valid(out)) {
1021 if (resG.gw.valid(v)) resG.gw.first(out, v);
1022 while (resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); }
1024 if (!resG.gw.valid(out)) {
1027 if (resG.gw.valid(v)) resG.gw.first(in, v); else in=/*OldInEdgeIt*/(INVALID);
1028 while (resG.gw.valid(in) && !(resG.free(in)>0) ) { resG.gw.next(in); }
1029 while (resG.gw.valid(v) && !resG.gw.valid(in)) {
1031 if (resG.gw.valid(v)) resG.gw.first(in, v);
1032 while (resG.gw.valid(in) && !(resG.free(in)>0) ) { resG.gw.next(in); }
1036 // EdgeIt& operator++() {
1039 // while (out.valid() && !(Edge::free()>0) ) { ++out; }
1040 // while (v.valid() && !out.valid()) {
1042 // if (v.valid()) G->first(out, v);
1043 // while (out.valid() && !(Edge::free()>0) ) { ++out; }
1045 // if (!out.valid()) {
1048 // if (v.valid()) G->first(in, v); else in=OldInEdgeIt();
1049 // while (in.valid() && !(Edge::free()>0) ) { ++in; }
1050 // while (v.valid() && !in.valid()) {
1052 // if (v.valid()) G->first(in, v);
1053 // while (in.valid() && !(Edge::free()>0) ) { ++in; }
1058 // while (in.valid() && !(Edge::free()>0) ) { ++in; }
1059 // while (v.valid() && !in.valid()) {
1061 // if (v.valid()) G->first(in, v);
1062 // while (in.valid() && !(Edge::free()>0) ) { ++in; }
1069 NodeIt& first(NodeIt& v) const { return gw.first(v); }
1070 OutEdgeIt& first(OutEdgeIt& e, Node v) const {
1071 e=OutEdgeIt(*this, v);
1074 EdgeIt& first(EdgeIt& e) const {
1079 NodeIt& next(NodeIt& n) const { return gw.next(n); }
1081 OutEdgeIt& next(OutEdgeIt& e) const {
1083 Node v=gw.aNode(e.out);
1085 while( gw.valid(e.out) && !(free(e.out)>0) ) { gw.next(e.out); }
1086 if (!gw.valid(e.out)) {
1089 while( gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); }
1093 while( gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); }
1098 EdgeIt& next(EdgeIt& e) const {
1101 while (gw.valid(e.out) && !(free(e.out)>0) ) { gw.next(e.out); }
1102 while (gw.valid(e.v) && !gw.valid(e.out)) {
1104 if (gw.valid(e.v)) gw.first(e.out, e.v);
1105 while (gw.valid(e.out) && !(free(e.out)>0) ) { gw.next(e.out); }
1107 if (!gw.valid(e.out)) {
1110 if (gw.valid(e.v)) gw.first(e.in, e.v); else e.in=/*OldInEdgeIt*/(INVALID);
1111 while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); }
1112 while (gw.valid(e.v) && !gw.valid(e.in)) {
1114 if (gw.valid(e.v)) gw.first(e.in, e.v);
1115 while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); }
1120 while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); }
1121 while (gw.valid(e.v) && !gw.valid(e.in)) {
1123 if (gw.valid(e.v)) gw.first(e.in, e.v);
1124 while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); }
1131 template< typename It >
1138 template< typename It >
1139 It first(Node v) const {
1145 Node tail(Edge e) const {
1146 return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); }
1147 Node head(Edge e) const {
1148 return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); }
1150 Node aNode(OutEdgeIt e) const {
1151 return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); }
1152 Node bNode(OutEdgeIt e) const {
1153 return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); }
1155 int nodeNum() const { return gw.nodeNum(); }
1157 //int edgeNum() const { return gw.edgeNum(); }
1160 int id(Node v) const { return gw.id(v); }
1162 bool valid(Node n) const { return gw.valid(n); }
1163 bool valid(Edge e) const {
1164 return e.out_or_in ? gw.valid(e.out) : gw.valid(e.in); }
1166 void augment(const Edge& e, Number a) const {
1168 flow->set(e.out, flow->get(e.out)+a);
1170 flow->set(e.in, flow->get(e.in)-a);
1173 Number free(const Edge& e) const {
1175 return (capacity->get(e.out)-flow->get(e.out));
1177 return (flow->get(e.in));
1180 Number free(OldOutEdgeIt out) const {
1181 return (capacity->get(out)-flow->get(out));
1184 Number free(OldInEdgeIt in) const {
1185 return (flow->get(in));
1188 template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
1190 NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G)
1191 : GraphWrapper::NodeMap<T>(_G.gw) { }
1192 NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G,
1193 T a) : GraphWrapper::NodeMap<T>(_G.gw, a) { }
1196 // template <typename T>
1198 // typename Graph::NodeMap<T> node_map;
1200 // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { }
1201 // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { }
1202 // void set(Node nit, T a) { node_map.set(nit, a); }
1203 // T get(Node nit) const { return node_map.get(nit); }
1206 template <typename T>
1208 typename GraphWrapper::EdgeMap<T> forward_map, backward_map;
1210 EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.gw), backward_map(_G.gw) { }
1211 EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.gw, a), backward_map(_G.gw, a) { }
1212 void set(Edge e, T a) {
1214 forward_map.set(e.out, a);
1216 backward_map.set(e.in, a);
1220 return forward_map.get(e.out);
1222 return backward_map.get(e.in);
1227 template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
1228 class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
1230 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
1231 //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
1233 ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow,
1234 const CapacityMap& _capacity) :
1235 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity),
1236 first_out_edges(*this) /*, dist(*this)*/ {
1237 for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) {
1239 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
1240 first_out_edges.set(n, e);
1244 //void setGraph(Graph& _graph) { graph = &_graph; }
1245 //Graph& getGraph() const { return (*graph); }
1247 //TrivGraphWrapper() : graph(0) { }
1248 //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { }
1250 //typedef Graph BaseGraph;
1252 //typedef typename Graph::Node Node;
1253 //typedef typename Graph::NodeIt NodeIt;
1255 //typedef typename Graph::Edge Edge;
1256 //typedef typename Graph::OutEdgeIt OutEdgeIt;
1257 //typedef typename Graph::InEdgeIt InEdgeIt;
1258 //typedef typename Graph::SymEdgeIt SymEdgeIt;
1259 //typedef typename Graph::EdgeIt EdgeIt;
1261 typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
1262 typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
1264 typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
1265 typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
1266 //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
1267 //typedef typename Graph::SymEdgeIt SymEdgeIt;
1268 //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
1270 NodeIt& first(NodeIt& n) const {
1271 return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
1274 OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
1275 e=first_out_edges.get(n);
1279 //ROSSZ template<typename I> I& first(I& i) const { return first(i); }
1280 //ROSSZ template<typename I, typename P> I& first(I& i, const P& p) const {
1281 // return first(i, p); }
1283 //template<typename I> I getNext(const I& i) const {
1284 // return gw.getNext(i); }
1285 //template<typename I> I& next(I &i) const { return gw.next(i); }
1287 template< typename It > It first() const {
1288 It e; first(e); return e; }
1290 template< typename It > It first(const Node& v) const {
1291 It e; first(e, v); return e; }
1293 //Node head(const Edge& e) const { return gw.head(e); }
1294 //Node tail(const Edge& e) const { return gw.tail(e); }
1296 //template<typename I> bool valid(const I& i) const
1297 // { return gw.valid(i); }
1299 //int nodeNum() const { return gw.nodeNum(); }
1300 //int edgeNum() const { return gw.edgeNum(); }
1302 //template<typename I> Node aNode(const I& e) const {
1303 // return gw.aNode(e); }
1304 //template<typename I> Node bNode(const I& e) const {
1305 // return gw.bNode(e); }
1307 //Node addNode() const { return gw.addNode(); }
1308 //Edge addEdge(const Node& tail, const Node& head) const {
1309 // return gw.addEdge(tail, head); }
1311 //void erase(const OutEdgeIt& e) {
1312 // first_out_edge(this->tail(e))=e;
1314 void erase(const Edge& e) {
1317 first_out_edges.set(this->tail(e), f);
1319 //template<typename I> void erase(const I& i) const { gw.erase(i); }
1321 //void clear() const { gw.clear(); }
1323 template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
1325 NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
1326 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
1327 NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
1328 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
1331 template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
1333 EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
1334 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
1335 EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
1336 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
1340 template<typename GraphWrapper>
1341 class FilterGraphWrapper {
1344 template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
1345 class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
1350 //typedef Graph BaseGraph;
1352 typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
1353 typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
1355 typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
1356 typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
1357 //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
1358 //typedef typename Graph::SymEdgeIt SymEdgeIt;
1359 typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
1361 //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
1364 FilterGraphWrapper(const Graph& _G, FlowMap& _flow,
1365 const CapacityMap& _capacity) :
1366 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, gw.nodeNum()) {
1369 OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
1370 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
1371 while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e))))
1372 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1376 NodeIt& next(NodeIt& e) const {
1377 return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1380 OutEdgeIt& next(OutEdgeIt& e) const {
1381 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1382 while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e))))
1383 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1387 NodeIt& first(NodeIt& n) const {
1388 return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
1391 void erase(const Edge& e) {
1393 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
1394 while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f))))
1395 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
1396 first_out_edges.set(this->tail(e), f);
1399 //TrivGraphWrapper() : graph(0) { }
1400 //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
1402 //void setGraph(Graph& _graph) { graph = &_graph; }
1403 //Graph& getGraph() const { return (*graph); }
1405 //template<typename I> I& first(I& i) const { return gw.first(i); }
1406 //template<typename I, typename P> I& first(I& i, const P& p) const {
1407 // return gw.first(i, p); }
1409 //template<typename I> I getNext(const I& i) const {
1410 // return gw.getNext(i); }
1411 //template<typename I> I& next(I &i) const { return gw.next(i); }
1413 template< typename It > It first() const {
1414 It e; first(e); return e; }
1416 template< typename It > It first(const Node& v) const {
1417 It e; first(e, v); return e; }
1419 //Node head(const Edge& e) const { return gw.head(e); }
1420 //Node tail(const Edge& e) const { return gw.tail(e); }
1422 //template<typename I> bool valid(const I& i) const
1423 // { return gw.valid(i); }
1425 //template<typename I> void setInvalid(const I &i);
1426 //{ return gw.setInvalid(i); }
1428 //int nodeNum() const { return gw.nodeNum(); }
1429 //int edgeNum() const { return gw.edgeNum(); }
1431 //template<typename I> Node aNode(const I& e) const {
1432 // return gw.aNode(e); }
1433 //template<typename I> Node bNode(const I& e) const {
1434 // return gw.bNode(e); }
1436 //Node addNode() const { return gw.addNode(); }
1437 //Edge addEdge(const Node& tail, const Node& head) const {
1438 // return gw.addEdge(tail, head); }
1440 //template<typename I> void erase(const I& i) const { gw.erase(i); }
1442 //void clear() const { gw.clear(); }
1444 template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
1446 NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
1447 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
1448 NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
1449 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
1452 template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
1454 EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
1455 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
1456 EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
1457 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
1461 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
1467 // // FIXME: comparison should be made better!!!
1468 // template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
1469 // class ResGraphWrapper
1474 // typedef Graph BaseGraph;
1476 // typedef typename Graph::Node Node;
1477 // typedef typename Graph::Edge Edge;
1479 // typedef typename Graph::NodeIt NodeIt;
1481 // class OutEdgeIt {
1485 // typename Graph::OutEdgeIt o;
1486 // typename Graph::InEdgeIt i;
1492 // typename Graph::OutEdgeIt o;
1493 // typename Graph::InEdgeIt i;
1495 // typedef typename Graph::SymEdgeIt SymEdgeIt;
1496 // typedef typename Graph::EdgeIt EdgeIt;
1498 // int nodeNum() const { return gw.nodeNum(); }
1499 // int edgeNum() const { return gw.edgeNum(); }
1501 // Node& first(Node& n) const { return gw.first(n); }
1503 // // Edge and SymEdge is missing!!!!
1504 // // Edge <-> In/OutEdgeIt conversion is missing!!!!
1507 // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const
1511 // while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
1513 // if(!gw.valid(e.o)) {
1515 // while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
1521 // OutEdgeIt &goNext(OutEdgeIt &e)
1523 // if(gw.valid(e.o)) {
1524 // while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
1526 // if(gw.valid(e.o)) return e;
1527 // else gw.first(e.i,e.n);
1530 // while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
1535 // OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
1537 // //bool valid(const OutEdgeIt e) { return gw.valid(e.o)||gw.valid(e.i);}
1540 // InEdgeIt& first(InEdgeIt& e, const Node& n) const
1544 // while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
1546 // if(!gw.valid(e.i)) {
1548 // while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
1554 // InEdgeIt &goNext(InEdgeIt &e)
1556 // if(gw.valid(e.i)) {
1557 // while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
1559 // if(gw.valid(e.i)) return e;
1560 // else gw.first(e.o,e.n);
1563 // while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
1568 // InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
1570 // //bool valid(const InEdgeIt e) { return gw.valid(e.i)||gw.valid(e.o);}
1572 // //template<typename I> I &goNext(I &i); { return gw.goNext(i); }
1573 // //template<typename I> I next(const I i); { return gw.goNext(i); }
1575 // template< typename It > It first() const {
1576 // It e; first(e); return e; }
1578 // template< typename It > It first(Node v) const {
1579 // It e; first(e, v); return e; }
1581 // Node head(const Edge& e) const { return gw.head(e); }
1582 // Node tail(const Edge& e) const { return gw.tail(e); }
1584 // template<typename I> Node aNode(const I& e) const {
1585 // return gw.aNode(e); }
1586 // template<typename I> Node bNode(const I& e) const {
1587 // return gw.bNode(e); }
1589 // //template<typename I> bool valid(const I i);
1590 // //{ return gw.valid(i); }
1592 // //template<typename I> void setInvalid(const I &i);
1593 // //{ return gw.setInvalid(i); }
1595 // Node addNode() { return gw.addNode(); }
1596 // Edge addEdge(const Node& tail, const Node& head) {
1597 // return gw.addEdge(tail, head); }
1599 // template<typename I> void erase(const I& i) { gw.erase(i); }
1601 // void clear() { gw.clear(); }
1603 // template<typename S> class NodeMap : public Graph::NodeMap<S> { };
1604 // template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
1606 // void setGraph(Graph& _graph) { graph = &_graph; }
1607 // Graph& getGraph() { return (*graph); }
1609 // //ResGraphWrapper() : graph(0) { }
1610 // ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
1615 #endif //HUGO_GRAPH_WRAPPER_H