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) { }
140 template<typename Map, typename T> class NodeMapWrapper {
144 NodeMapWrapper(Map& _map) : map(&_map) { }
145 //template<typename T>
146 void set(Node n, T a) { map->set(n, a); }
147 //template<typename T>
148 T get(Node n) const { return map->get(n); }
151 template<typename Map, typename T> class EdgeMapWrapper {
155 EdgeMapWrapper(Map& _map) : map(&_map) { }
156 //template<typename T>
157 void set(Edge n, T a) { map->set(n, a); }
158 //template<typename T>
159 T get(Edge n) const { return map->get(n); }
163 template<typename GraphWrapper>
164 class GraphWrapperSkeleton {
169 //typedef typename GraphWrapper::BaseGraph BaseGraph;
171 // typedef typename GraphWrapper::Node Node;
172 // typedef typename GraphWrapper::NodeIt NodeIt;
174 // typedef typename GraphWrapper::Edge Edge;
175 // typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
176 // typedef typename GraphWrapper::InEdgeIt InEdgeIt;
177 // //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
178 // typedef typename GraphWrapper::EdgeIt EdgeIt;
180 typedef typename GraphWrapper::Node Node;
181 class NodeIt : public GraphWrapper::NodeIt {
184 NodeIt(const typename GraphWrapper::NodeIt& n) :
185 GraphWrapper::NodeIt(n) { }
186 NodeIt(const Invalid& i) : GraphWrapper::NodeIt(i) { }
187 NodeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) :
188 GraphWrapper::NodeIt(_G.gw) { }
190 typedef typename GraphWrapper::Edge Edge;
191 //typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
192 class OutEdgeIt : public GraphWrapper::OutEdgeIt {
195 OutEdgeIt(const typename GraphWrapper::OutEdgeIt& e) :
196 GraphWrapper::OutEdgeIt(e) { }
197 OutEdgeIt(const Invalid& i) : GraphWrapper::OutEdgeIt(i) { }
198 OutEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) :
199 GraphWrapper::OutEdgeIt(_G.gw, n) { }
201 //typedef typename GraphWrapper::InEdgeIt InEdgeIt;
202 class InEdgeIt : public GraphWrapper::InEdgeIt {
205 InEdgeIt(const typename GraphWrapper::InEdgeIt& e) :
206 GraphWrapper::InEdgeIt(e) { }
207 InEdgeIt(const Invalid& i) : GraphWrapper::InEdgeIt(i) { }
208 InEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) :
209 GraphWrapper::InEdgeIt(_G.gw, n) { }
211 //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
212 //typedef typename GraphWrapper::EdgeIt EdgeIt;
213 class EdgeIt : public GraphWrapper::EdgeIt {
216 EdgeIt(const typename GraphWrapper::EdgeIt& e) :
217 GraphWrapper::EdgeIt(e) { }
218 EdgeIt(const Invalid& i) : GraphWrapper::EdgeIt(i) { }
219 EdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) :
220 GraphWrapper::EdgeIt(_G.gw) { }
224 //GraphWrapperSkeleton() : gw() { }
225 GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
227 //void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
228 //BaseGraph& getGraph() const { return gw.getGraph(); }
230 template<typename I> I& first(I& i) const {
234 template<typename I, typename P> I& first(I& i, const P& p) const {
239 // template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
240 template<typename I> I& next(I &i) const { gw.next(i); return i; }
242 template< typename It > It first() const {
243 It e; this->first(e); return e; }
245 template< typename It > It first(const Node& v) const {
246 It e; this->first(e, v); return e; }
248 Node head(const Edge& e) const { return gw.head(e); }
249 Node tail(const Edge& e) const { return gw.tail(e); }
251 template<typename I> bool valid(const I& i) const { return gw.valid(i); }
253 //template<typename I> void setInvalid(const I &i);
254 //{ return graph->setInvalid(i); }
256 int nodeNum() const { return gw.nodeNum(); }
257 int edgeNum() const { return gw.edgeNum(); }
259 template<typename I> Node aNode(const I& e) const { return gw.aNode(e); }
260 template<typename I> Node bNode(const I& e) const { return gw.bNode(e); }
262 Node addNode() const { return gw.addNode(); }
263 Edge addEdge(const Node& tail, const Node& head) const {
264 return gw.addEdge(tail, head); }
266 template<typename I> void erase(const I& i) const { gw.erase(i); }
268 void clear() const { gw.clear(); }
270 template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
272 NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :
273 GraphWrapper::NodeMap<T>(_G.gw) { }
274 NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) :
275 GraphWrapper::NodeMap<T>(_G.gw, a) { }
278 template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
280 EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :
281 GraphWrapper::EdgeMap<T>(_G.gw) { }
282 EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) :
283 GraphWrapper::EdgeMap<T>(_G.gw, a) { }
287 // template<typename Graph>
288 // class RevGraphWrapper
294 // typedef Graph BaseGraph;
296 // typedef typename Graph::Node Node;
297 // typedef typename Graph::NodeIt NodeIt;
299 // typedef typename Graph::Edge Edge;
300 // typedef typename Graph::OutEdgeIt InEdgeIt;
301 // typedef typename Graph::InEdgeIt OutEdgeIt;
302 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
303 // typedef typename Graph::EdgeIt EdgeIt;
305 // //RevGraphWrapper() : graph(0) { }
306 // RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
308 // void setGraph(Graph& _graph) { graph = &_graph; }
309 // Graph& getGraph() const { return (*graph); }
311 // template<typename I> I& first(I& i) const { return graph->first(i); }
312 // template<typename I, typename P> I& first(I& i, const P& p) const {
313 // return graph->first(i, p); }
315 // template<typename I> I getNext(const I& i) const {
316 // return graph->getNext(i); }
317 // template<typename I> I& next(I &i) const { return graph->next(i); }
319 // template< typename It > It first() const {
320 // It e; first(e); return e; }
322 // template< typename It > It first(const Node& v) const {
323 // It e; first(e, v); return e; }
325 // Node head(const Edge& e) const { return graph->tail(e); }
326 // Node tail(const Edge& e) const { return graph->head(e); }
328 // template<typename I> bool valid(const I& i) const
329 // { return graph->valid(i); }
331 // //template<typename I> void setInvalid(const I &i);
332 // //{ return graph->setInvalid(i); }
334 // template<typename I> Node aNode(const I& e) const {
335 // return graph->aNode(e); }
336 // template<typename I> Node bNode(const I& e) const {
337 // return graph->bNode(e); }
339 // Node addNode() const { return graph->addNode(); }
340 // Edge addEdge(const Node& tail, const Node& head) const {
341 // return graph->addEdge(tail, head); }
343 // int nodeNum() const { return graph->nodeNum(); }
344 // int edgeNum() const { return graph->edgeNum(); }
346 // template<typename I> void erase(const I& i) const { graph->erase(i); }
348 // void clear() const { graph->clear(); }
350 // template<typename T> class NodeMap : public Graph::NodeMap<T> {
352 // NodeMap(const RevGraphWrapper<Graph>& _G) :
353 // Graph::NodeMap<T>(_G.getGraph()) { }
354 // NodeMap(const RevGraphWrapper<Graph>& _G, T a) :
355 // Graph::NodeMap<T>(_G.getGraph(), a) { }
358 // template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
360 // EdgeMap(const RevGraphWrapper<Graph>& _G) :
361 // Graph::EdgeMap<T>(_G.getGraph()) { }
362 // EdgeMap(const RevGraphWrapper<Graph>& _G, T a) :
363 // Graph::EdgeMap<T>(_G.getGraph(), a) { }
367 // template<typename /*Graph*/GraphWrapper
368 // /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ >
369 // class RevGraphWrapper :
370 // public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ {
375 // //typedef Graph BaseGraph;
377 // //typedef typename Graph::Node Node;
378 // //typedef typename Graph::NodeIt NodeIt;
380 // //typedef typename Graph::Edge Edge;
381 // typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::OutEdgeIt InEdgeIt;
382 // typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::InEdgeIt OutEdgeIt;
383 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
384 // //typedef typename Graph::EdgeIt EdgeIt;
386 // //RevGraphWrapper() : graph(0) { }
387 // RevGraphWrapper(GraphWrapper _gw/*BaseGraph& _graph*/) : GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/(_gw/*TrivGraphWrapper<Graph>(_graph)*/) { }
389 // //void setGraph(Graph& _graph) { graph = &_graph; }
390 // //Graph& getGraph() const { return (*graph); }
392 // //template<typename I> I& first(I& i) const { return graph->first(i); }
393 // //template<typename I, typename P> I& first(I& i, const P& p) const {
394 // // return graph->first(i, p); }
396 // //template<typename I> I getNext(const I& i) const {
397 // // return graph->getNext(i); }
398 // //template<typename I> I& next(I &i) const { return graph->next(i); }
400 // //template< typename It > It first() const {
401 // // It e; first(e); return e; }
403 // //template< typename It > It first(const Node& v) const {
404 // // It e; first(e, v); return e; }
406 // //Node head(const Edge& e) const { return graph->tail(e); }
407 // //Node tail(const Edge& e) const { return graph->head(e); }
409 // //template<typename I> bool valid(const I& i) const
410 // // { return graph->valid(i); }
412 // //template<typename I> void setInvalid(const I &i);
413 // //{ return graph->setInvalid(i); }
415 // //template<typename I> Node aNode(const I& e) const {
416 // // return graph->aNode(e); }
417 // //template<typename I> Node bNode(const I& e) const {
418 // // return graph->bNode(e); }
420 // //Node addNode() const { return graph->addNode(); }
421 // //Edge addEdge(const Node& tail, const Node& head) const {
422 // // return graph->addEdge(tail, head); }
424 // //int nodeNum() const { return graph->nodeNum(); }
425 // //int edgeNum() const { return graph->edgeNum(); }
427 // //template<typename I> void erase(const I& i) const { graph->erase(i); }
429 // //void clear() const { graph->clear(); }
431 // template<typename T> class NodeMap :
432 // public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>
435 // NodeMap(const RevGraphWrapper<GraphWrapper>& _gw) :
436 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw) { }
437 // NodeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) :
438 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw, a) { }
441 // template<typename T> class EdgeMap :
442 // public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T> {
444 // EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw) :
445 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw) { }
446 // EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) :
447 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw, a) { }
452 template<typename GraphWrapper>
453 class RevGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
455 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
456 typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
457 typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt InEdgeIt;
458 typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt OutEdgeIt;
460 RevGraphWrapper(GraphWrapper _gw) :
461 GraphWrapperSkeleton<GraphWrapper>(_gw) { }
463 Node head(const Edge& e) const
464 { return GraphWrapperSkeleton<GraphWrapper>::tail(e); }
465 Node tail(const Edge& e) const
466 { return GraphWrapperSkeleton<GraphWrapper>::head(e); }
469 //Subgraph on the same node-set and partial edge-set
470 template<typename GraphWrapper, typename EdgeFilterMap>
471 class SubGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
473 EdgeFilterMap* filter_map;
475 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
476 typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
477 typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
478 typedef typename GraphWrapperSkeleton<GraphWrapper>::EdgeIt EdgeIt;
479 typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt InEdgeIt;
480 typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OutEdgeIt;
482 SubGraphWrapper(GraphWrapper _gw, EdgeFilterMap& _filter_map) :
483 GraphWrapperSkeleton<GraphWrapper>(_gw), filter_map(&_filter_map) { }
485 template<typename I> I& first(I& i) const {
487 while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
490 template<typename I, typename P> I& first(I& i, const P& p) const {
492 while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
496 //template<typename I> I getNext(const I& i) const {
497 // return gw.getNext(i);
499 template<typename I> I& next(I &i) const {
501 while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
505 template< typename It > It first() const {
506 It e; this->first(e); return e; }
508 template< typename It > It first(const Node& v) const {
509 It e; this->first(e, v); return e; }
512 // template<typename GraphWrapper>
513 // class UndirGraphWrapper {
519 // typedef GraphWrapper BaseGraph;
521 // typedef typename GraphWrapper::Node Node;
522 // typedef typename GraphWrapper::NodeIt NodeIt;
524 // //typedef typename Graph::Edge Edge;
525 // //typedef typename Graph::OutEdgeIt OutEdgeIt;
526 // //typedef typename Graph::InEdgeIt InEdgeIt;
527 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
528 // //typedef typename Graph::EdgeIt EdgeIt;
531 // typedef typename GraphWrapper::Edge GraphEdge;
532 // typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt;
533 // typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt;
536 // //UndirGraphWrapper() : graph(0) { }
537 // UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
539 // //void setGraph(Graph& _graph) { graph = &_graph; }
540 // //Graph& getGraph() const { return (*graph); }
543 // friend class UndirGraphWrapper<GraphWrapper>;
544 // bool out_or_in; //true iff out
545 // GraphOutEdgeIt out;
548 // Edge() : out_or_in(), out(), in() { }
549 // Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
550 // operator GraphEdge() const {
551 // if (out_or_in) return(out); else return(in);
553 // friend bool operator==(const Edge& u, const Edge& v) {
555 // return (u.out_or_in && u.out==v.out);
557 // return (!u.out_or_in && u.in==v.in);
559 // friend bool operator!=(const Edge& u, const Edge& v) {
561 // return (!u.out_or_in || u.out!=v.out);
563 // return (u.out_or_in || u.in!=v.in);
567 // class OutEdgeIt : public Edge {
568 // friend class UndirGraphWrapper<GraphWrapper>;
570 // OutEdgeIt() : Edge() { }
571 // OutEdgeIt(const Invalid& i) : Edge(i) { }
572 // OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n)
575 // _G.gw.first(out, n);
576 // if (!(_G.gw.valid(out))) {
578 // _G.gw.first(in, n);
583 // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
585 // gw.first(e.out, n);
586 // if (!(gw.valid(e.out))) {
587 // e.out_or_in=false;
588 // gw.first(e.in, n);
593 // OutEdgeIt& next(OutEdgeIt& e) const {
594 // if (e.out_or_in) {
595 // Node n=gw.tail(e.out);
597 // if (!gw.valid(e.out)) {
598 // e.out_or_in=false;
599 // gw.first(e.in, n);
607 // Node aNode(const OutEdgeIt& e) const {
608 // if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
609 // Node bNode(const OutEdgeIt& e) const {
610 // if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
612 // typedef OutEdgeIt InEdgeIt;
614 // template<typename I> I& first(I& i) const { return gw.first(i); }
615 // // template<typename I, typename P> I& first(I& i, const P& p) const {
616 // // return graph->first(i, p); }
618 // template<typename I> I getNext(const I& i) const {
619 // return gw.getNext(i); }
620 // template<typename I> I& next(I &i) const { return gw.next(i); }
622 // template< typename It > It first() const {
623 // It e; first(e); return e; }
625 // template< typename It > It first(const Node& v) const {
626 // It e; first(e, v); return e; }
628 // Node head(const Edge& e) const { return gw.head(e); }
629 // Node tail(const Edge& e) const { return gw.tail(e); }
631 // template<typename I> bool valid(const I& i) const
632 // { return gw.valid(i); }
634 // //template<typename I> void setInvalid(const I &i);
635 // //{ return graph->setInvalid(i); }
637 // int nodeNum() const { return gw.nodeNum(); }
638 // int edgeNum() const { return gw.edgeNum(); }
640 // // template<typename I> Node aNode(const I& e) const {
641 // // return graph->aNode(e); }
642 // // template<typename I> Node bNode(const I& e) const {
643 // // return graph->bNode(e); }
645 // Node addNode() const { return gw.addNode(); }
646 // // FIXME: ez igy nem jo, mert nem
647 // // Edge addEdge(const Node& tail, const Node& head) const {
648 // // return graph->addEdge(tail, head); }
650 // template<typename I> void erase(const I& i) const { gw.erase(i); }
652 // void clear() const { gw.clear(); }
654 // template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
656 // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
657 // GraphWrapper::NodeMap<T>(_G.gw) { }
658 // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
659 // GraphWrapper::NodeMap<T>(_G.gw, a) { }
662 // template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> {
664 // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
665 // GraphWrapper::EdgeMap<T>(_G.gw) { }
666 // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
667 // GraphWrapper::EdgeMap<T>(_G.gw, a) { }
672 template<typename GraphWrapper>
673 class UndirGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
678 //typedef GraphWrapper BaseGraph;
680 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
681 typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
684 typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge GraphEdge;
685 typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt GraphOutEdgeIt;
686 typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt GraphInEdgeIt;
689 //UndirGraphWrapper() : graph(0) { }
690 UndirGraphWrapper(GraphWrapper _gw) :
691 GraphWrapperSkeleton<GraphWrapper>(_gw) { }
693 //UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
695 //void setGraph(Graph& _graph) { graph = &_graph; }
696 //Graph& getGraph() const { return (*graph); }
699 friend class UndirGraphWrapper<GraphWrapper>;
700 bool out_or_in; //true iff out
704 Edge() : out_or_in(), out(), in() { }
705 Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
706 operator GraphEdge() const {
707 if (out_or_in) return(out); else return(in);
710 //2 edges are equal if they "refer" to the same physical edge
712 friend bool operator==(const Edge& u, const Edge& v) {
714 if (u.out_or_in) return (u.out==v.out); else return (u.out==v.in);
715 //return (u.out_or_in && u.out==v.out);
717 if (u.out_or_in) return (u.out==v.in); else return (u.in==v.in);
718 //return (!u.out_or_in && u.in==v.in);
720 friend bool operator!=(const Edge& u, const Edge& v) {
722 if (u.out_or_in) return (u.out!=v.out); else return (u.out!=v.in);
723 //return (!u.out_or_in || u.out!=v.out);
725 if (u.out_or_in) return (u.out!=v.in); else return (u.in!=v.in);
726 //return (u.out_or_in || u.in!=v.in);
730 class OutEdgeIt : public Edge {
731 friend class UndirGraphWrapper<GraphWrapper>;
733 OutEdgeIt() : Edge() { }
734 OutEdgeIt(const Invalid& i) : Edge(i) { }
735 OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n)
737 out_or_in=true; _G.gw.first(out, n);
738 if (!(_G.gw.valid(out))) { out_or_in=false; _G.gw.first(in, n); }
742 typedef OutEdgeIt InEdgeIt;
744 class EdgeIt : public Edge {
745 friend class UndirGraphWrapper<GraphWrapper>;
749 EdgeIt() : Edge() { }
750 EdgeIt(const Invalid& i) : Edge(i) { }
751 EdgeIt(const UndirGraphWrapper<GraphWrapper>& _G)
756 if (_G.valid(v)) _G.gw.first(out); else out=INVALID;
757 while (_G.valid(v) && !_G.gw.valid(out)) {
759 if (_G.valid(v)) _G.gw.first(out);
764 OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
765 e.out_or_in=true; gw.first(e.out, n);
766 if (!(gw.valid(e.out))) { e.out_or_in=false; gw.first(e.in, n); }
770 EdgeIt& first(EdgeIt& e) const {
774 if (valid(e.v)) gw.first(e.out, e.v); else e.out=INVALID;
775 while (valid(e.v) && !gw.valid(e.out)) {
777 if (valid(e.v)) gw.first(e.out, e.v);
782 template<typename I> I& first(I& i) const { gw.first(i); return i; }
783 template<typename I, typename P> I& first(I& i, const P& p) const {
784 gw.first(i, p); return i; }
786 OutEdgeIt& next(OutEdgeIt& e) const {
788 Node n=gw.tail(e.out);
790 if (!gw.valid(e.out)) { e.out_or_in=false; gw.first(e.in, n); }
797 EdgeIt& next(EdgeIt& e) const {
800 while (valid(e.v) && !gw.valid(e.out)) {
802 if (valid(e.v)) gw.first(e.out, e.v);
807 template<typename I> I& next(I &i) const { return gw.next(i); }
808 // template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
810 template< typename It > It first() const {
811 It e; first(e); return e; }
813 template< typename It > It first(const Node& v) const {
814 It e; first(e, v); return e; }
816 // Node head(const Edge& e) const { return gw.head(e); }
817 // Node tail(const Edge& e) const { return gw.tail(e); }
819 // template<typename I> bool valid(const I& i) const
820 // { return gw.valid(i); }
822 // int nodeNum() const { return gw.nodeNum(); }
823 // int edgeNum() const { return gw.edgeNum(); }
825 // template<typename I> Node aNode(const I& e) const {
826 // return graph->aNode(e); }
827 // template<typename I> Node bNode(const I& e) const {
828 // return graph->bNode(e); }
830 Node aNode(const OutEdgeIt& e) const {
831 if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
832 Node bNode(const OutEdgeIt& e) const {
833 if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
835 // Node addNode() const { return gw.addNode(); }
837 // FIXME: ez igy nem jo, mert nem
838 // Edge addEdge(const Node& tail, const Node& head) const {
839 // return graph->addEdge(tail, head); }
841 // template<typename I> void erase(const I& i) const { gw.erase(i); }
843 // void clear() const { gw.clear(); }
845 // template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
847 // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
848 // GraphWrapper::NodeMap<T>(_G.gw) { }
849 // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
850 // GraphWrapper::NodeMap<T>(_G.gw, a) { }
853 // template<typename T> class EdgeMap :
854 // public GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T> {
856 // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) :
857 // GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T>(_G.gw) { }
858 // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) :
859 // GraphWrapper::EdgeMap<T>(_G.gw, a) { }
867 // template<typename Graph>
868 // class SymGraphWrapper
873 // typedef Graph BaseGraph;
875 // typedef typename Graph::Node Node;
876 // typedef typename Graph::Edge Edge;
878 // typedef typename Graph::NodeIt NodeIt;
880 // //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
881 // //iranyitatlant, ami van
882 // //mert csak 1 dolgot lehet be typedef-elni
883 // typedef typename Graph::OutEdgeIt SymEdgeIt;
884 // //typedef typename Graph::InEdgeIt SymEdgeIt;
885 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
886 // typedef typename Graph::EdgeIt EdgeIt;
888 // int nodeNum() const { return graph->nodeNum(); }
889 // int edgeNum() const { return graph->edgeNum(); }
891 // template<typename I> I& first(I& i) const { return graph->first(i); }
892 // template<typename I, typename P> I& first(I& i, const P& p) const {
893 // return graph->first(i, p); }
894 // //template<typename I> I next(const I i); { return graph->goNext(i); }
895 // //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
897 // template< typename It > It first() const {
898 // It e; first(e); return e; }
900 // template< typename It > It first(Node v) const {
901 // It e; first(e, v); return e; }
903 // Node head(const Edge& e) const { return graph->head(e); }
904 // Node tail(const Edge& e) const { return graph->tail(e); }
906 // template<typename I> Node aNode(const I& e) const {
907 // return graph->aNode(e); }
908 // template<typename I> Node bNode(const I& e) const {
909 // return graph->bNode(e); }
911 // //template<typename I> bool valid(const I i);
912 // //{ return graph->valid(i); }
914 // //template<typename I> void setInvalid(const I &i);
915 // //{ return graph->setInvalid(i); }
917 // Node addNode() { return graph->addNode(); }
918 // Edge addEdge(const Node& tail, const Node& head) {
919 // return graph->addEdge(tail, head); }
921 // template<typename I> void erase(const I& i) { graph->erase(i); }
923 // void clear() { graph->clear(); }
925 // template<typename T> class NodeMap : public Graph::NodeMap<T> { };
926 // template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
928 // void setGraph(Graph& _graph) { graph = &_graph; }
929 // Graph& getGraph() { return (*graph); }
931 // //SymGraphWrapper() : graph(0) { }
932 // SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
936 template<typename GraphWrapper, typename Number, typename FlowMap, typename CapacityMap>
937 class ResGraphWrapper : public GraphWrapperSkeleton<GraphWrapper>{
939 //typedef Graph BaseGraph;
940 //typedef TrivGraphWrapper<const Graph> GraphWrapper;
941 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
942 typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
944 typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OldOutEdgeIt;
945 typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt OldInEdgeIt;
947 //const Graph* graph;
950 const CapacityMap* capacity;
953 ResGraphWrapper(const GraphWrapper& _gw, FlowMap& _flow,
954 const CapacityMap& _capacity) :
955 GraphWrapperSkeleton<GraphWrapper>(_gw),
956 flow(&_flow), capacity(&_capacity) { }
958 //void setGraph(const Graph& _graph) { graph = &_graph; }
959 //const Graph& getGraph() const { return (*graph); }
964 friend class OutEdgeIt;
967 friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
969 bool out_or_in; //true, iff out
973 Edge() : out_or_in(true) { }
974 Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
975 // bool valid() const {
976 // return out_or_in && out.valid() || in.valid(); }
977 friend bool operator==(const Edge& u, const Edge& v) {
979 return (u.out_or_in && u.out==v.out);
981 return (!u.out_or_in && u.in==v.in);
983 friend bool operator!=(const Edge& u, const Edge& v) {
985 return (!u.out_or_in || u.out!=v.out);
987 return (u.out_or_in || u.in!=v.in);
992 class OutEdgeIt : public Edge {
993 friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
997 OutEdgeIt(const Edge& e) : Edge(e) { }
998 OutEdgeIt(const Invalid& i) : Edge(i) { }
1000 OutEdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() {
1001 resG.gw.first(out, v);
1002 while( resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }
1003 if (!resG.gw.valid(out)) {
1005 resG.gw.first(in, v);
1006 while( resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }
1010 // OutEdgeIt& operator++() {
1012 // Node v=/*resG->*/G->aNode(out);
1014 // while( out.valid() && !(Edge::resCap()>0) ) { ++out; }
1015 // if (!out.valid()) {
1018 // while( in.valid() && !(Edge::resCap()>0) ) { ++in; }
1022 // while( in.valid() && !(Edge::resCap()>0) ) { ++in; }
1028 //FIXME This is just for having InEdgeIt
1029 typedef void InEdgeIt;
1031 class EdgeIt : public Edge {
1032 friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
1036 //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }
1037 EdgeIt(const Invalid& i) : Edge(i) { }
1038 EdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG) : Edge() {
1040 if (resG.gw.valid(v)) resG.gw.first(out, v); else out=INVALID;
1041 while (resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }
1042 while (resG.gw.valid(v) && !resG.gw.valid(out)) {
1044 if (resG.gw.valid(v)) resG.gw.first(out, v);
1045 while (resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }
1047 if (!resG.gw.valid(out)) {
1050 if (resG.gw.valid(v)) resG.gw.first(in, v); else in=INVALID;
1051 while (resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }
1052 while (resG.gw.valid(v) && !resG.gw.valid(in)) {
1054 if (resG.gw.valid(v)) resG.gw.first(in, v);
1055 while (resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }
1059 // EdgeIt& operator++() {
1062 // while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
1063 // while (v.valid() && !out.valid()) {
1065 // if (v.valid()) G->first(out, v);
1066 // while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
1068 // if (!out.valid()) {
1071 // if (v.valid()) G->first(in, v); else in=OldInEdgeIt();
1072 // while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
1073 // while (v.valid() && !in.valid()) {
1075 // if (v.valid()) G->first(in, v);
1076 // while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
1081 // while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
1082 // while (v.valid() && !in.valid()) {
1084 // if (v.valid()) G->first(in, v);
1085 // while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
1092 NodeIt& first(NodeIt& v) const { gw.first(v); return v; }
1093 OutEdgeIt& first(OutEdgeIt& e, Node v) const {
1094 e=OutEdgeIt(*this, v);
1097 EdgeIt& first(EdgeIt& e) const {
1102 NodeIt& next(NodeIt& n) const { return gw.next(n); }
1104 OutEdgeIt& next(OutEdgeIt& e) const {
1106 Node v=gw.aNode(e.out);
1108 while( gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }
1109 if (!gw.valid(e.out)) {
1112 while( gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
1116 while( gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
1121 EdgeIt& next(EdgeIt& e) const {
1124 while (gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }
1125 while (gw.valid(e.v) && !gw.valid(e.out)) {
1127 if (gw.valid(e.v)) gw.first(e.out, e.v);
1128 while (gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }
1130 if (!gw.valid(e.out)) {
1133 if (gw.valid(e.v)) gw.first(e.in, e.v); else e.in=INVALID;
1134 while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
1135 while (gw.valid(e.v) && !gw.valid(e.in)) {
1137 if (gw.valid(e.v)) gw.first(e.in, e.v);
1138 while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
1143 while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
1144 while (gw.valid(e.v) && !gw.valid(e.in)) {
1146 if (gw.valid(e.v)) gw.first(e.in, e.v);
1147 while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
1154 template< typename It >
1161 template< typename It >
1162 It first(Node v) const {
1168 Node tail(Edge e) const {
1169 return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); }
1170 Node head(Edge e) const {
1171 return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); }
1173 Node aNode(OutEdgeIt e) const {
1174 return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); }
1175 Node bNode(OutEdgeIt e) const {
1176 return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); }
1178 int nodeNum() const { return gw.nodeNum(); }
1180 //int edgeNum() const { return gw.edgeNum(); }
1183 int id(Node v) const { return gw.id(v); }
1185 bool valid(Node n) const { return gw.valid(n); }
1186 bool valid(Edge e) const {
1187 return e.out_or_in ? gw.valid(e.out) : gw.valid(e.in); }
1189 void augment(const Edge& e, Number a) const {
1191 flow->set(e.out, flow->get(e.out)+a);
1193 flow->set(e.in, flow->get(e.in)-a);
1196 Number resCap(const Edge& e) const {
1198 return (capacity->get(e.out)-flow->get(e.out));
1200 return (flow->get(e.in));
1203 Number resCap(OldOutEdgeIt out) const {
1204 return (capacity->get(out)-flow->get(out));
1207 Number resCap(OldInEdgeIt in) const {
1208 return (flow->get(in));
1211 // template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> {
1213 // NodeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G)
1214 // : GraphWrapper::NodeMap<T>(_G.gw) { }
1215 // NodeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G,
1216 // T a) : GraphWrapper::NodeMap<T>(_G.gw, a) { }
1219 // template <typename T>
1221 // typename Graph::NodeMap<T> node_map;
1223 // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { }
1224 // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { }
1225 // void set(Node nit, T a) { node_map.set(nit, a); }
1226 // T get(Node nit) const { return node_map.get(nit); }
1229 template <typename T>
1231 typename GraphWrapper::EdgeMap<T> forward_map, backward_map;
1233 EdgeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.gw), backward_map(_G.gw) { }
1234 EdgeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.gw, a), backward_map(_G.gw, a) { }
1235 void set(Edge e, T a) {
1237 forward_map.set(e.out, a);
1239 backward_map.set(e.in, a);
1243 return forward_map.get(e.out);
1245 return backward_map.get(e.in);
1250 //Subgraph on the same node-set and partial edge-set
1251 template<typename GraphWrapper, typename FirstOutEdgesMap>
1252 class ErasingFirstGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
1254 FirstOutEdgesMap* first_out_edges;
1256 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
1257 typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
1258 typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
1259 typedef typename GraphWrapperSkeleton<GraphWrapper>::EdgeIt EdgeIt;
1260 typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt InEdgeIt;
1261 typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OutEdgeIt;
1263 ErasingFirstGraphWrapper(GraphWrapper _gw, FirstOutEdgesMap& _first_out_edges) :
1264 GraphWrapperSkeleton<GraphWrapper>(_gw), first_out_edges(&_first_out_edges) { }
1266 template<typename I> I& first(I& i) const {
1268 //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
1271 OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
1272 e=first_out_edges->get(n);
1275 template<typename I, typename P> I& first(I& i, const P& p) const {
1277 //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
1281 //template<typename I> I getNext(const I& i) const {
1282 // return gw.getNext(i);
1284 template<typename I> I& next(I &i) const {
1286 //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
1290 template< typename It > It first() const {
1291 It e; this->first(e); return e; }
1293 template< typename It > It first(const Node& v) const {
1294 It e; this->first(e, v); return e; }
1296 void erase(const OutEdgeIt& e) const {
1299 first_out_edges->set(this->tail(e), f);
1303 // template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
1304 // class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
1306 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
1307 // //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
1309 // ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow,
1310 // const CapacityMap& _capacity) :
1311 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity),
1312 // first_out_edges(*this) /*, dist(*this)*/ {
1313 // for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) {
1315 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
1316 // first_out_edges.set(n, e);
1320 // //void setGraph(Graph& _graph) { graph = &_graph; }
1321 // //Graph& getGraph() const { return (*graph); }
1323 // //TrivGraphWrapper() : graph(0) { }
1324 // //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { }
1326 // //typedef Graph BaseGraph;
1328 // //typedef typename Graph::Node Node;
1329 // //typedef typename Graph::NodeIt NodeIt;
1331 // //typedef typename Graph::Edge Edge;
1332 // //typedef typename Graph::OutEdgeIt OutEdgeIt;
1333 // //typedef typename Graph::InEdgeIt InEdgeIt;
1334 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
1335 // //typedef typename Graph::EdgeIt EdgeIt;
1337 // typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
1338 // typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
1340 // typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
1341 // typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
1342 // //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
1343 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
1344 // //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
1346 // NodeIt& first(NodeIt& n) const {
1347 // return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
1350 // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
1351 // e=first_out_edges.get(n);
1355 // //ROSSZ template<typename I> I& first(I& i) const { return first(i); }
1356 // //ROSSZ template<typename I, typename P> I& first(I& i, const P& p) const {
1357 // // return first(i, p); }
1359 // //template<typename I> I getNext(const I& i) const {
1360 // // return gw.getNext(i); }
1361 // //template<typename I> I& next(I &i) const { return gw.next(i); }
1363 // template< typename It > It first() const {
1364 // It e; first(e); return e; }
1366 // template< typename It > It first(const Node& v) const {
1367 // It e; first(e, v); return e; }
1369 // //Node head(const Edge& e) const { return gw.head(e); }
1370 // //Node tail(const Edge& e) const { return gw.tail(e); }
1372 // //template<typename I> bool valid(const I& i) const
1373 // // { return gw.valid(i); }
1375 // //int nodeNum() const { return gw.nodeNum(); }
1376 // //int edgeNum() const { return gw.edgeNum(); }
1378 // //template<typename I> Node aNode(const I& e) const {
1379 // // return gw.aNode(e); }
1380 // //template<typename I> Node bNode(const I& e) const {
1381 // // return gw.bNode(e); }
1383 // //Node addNode() const { return gw.addNode(); }
1384 // //Edge addEdge(const Node& tail, const Node& head) const {
1385 // // return gw.addEdge(tail, head); }
1387 // //void erase(const OutEdgeIt& e) {
1388 // // first_out_edge(this->tail(e))=e;
1390 // void erase(const Edge& e) {
1393 // first_out_edges.set(this->tail(e), f);
1395 // //template<typename I> void erase(const I& i) const { gw.erase(i); }
1397 // //void clear() const { gw.clear(); }
1399 // template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
1401 // NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
1402 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
1403 // NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
1404 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
1407 // template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
1409 // EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
1410 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
1411 // EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
1412 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
1416 // template<typename GraphWrapper>
1417 // class FilterGraphWrapper {
1420 // template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
1421 // class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
1426 // //typedef Graph BaseGraph;
1428 // typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
1429 // typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
1431 // typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
1432 // typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
1433 // //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
1434 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
1435 // typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
1437 // //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
1440 // FilterGraphWrapper(const Graph& _G, FlowMap& _flow,
1441 // const CapacityMap& _capacity) :
1442 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, gw.nodeNum()) {
1445 // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
1446 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
1447 // while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e))))
1448 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1452 // NodeIt& next(NodeIt& e) const {
1453 // return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1456 // OutEdgeIt& next(OutEdgeIt& e) const {
1457 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1458 // while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e))))
1459 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
1463 // NodeIt& first(NodeIt& n) const {
1464 // return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
1467 // void erase(const Edge& e) {
1469 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
1470 // while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f))))
1471 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
1472 // first_out_edges.set(this->tail(e), f);
1475 // //TrivGraphWrapper() : graph(0) { }
1476 // //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
1478 // //void setGraph(Graph& _graph) { graph = &_graph; }
1479 // //Graph& getGraph() const { return (*graph); }
1481 // //template<typename I> I& first(I& i) const { return gw.first(i); }
1482 // //template<typename I, typename P> I& first(I& i, const P& p) const {
1483 // // return gw.first(i, p); }
1485 // //template<typename I> I getNext(const I& i) const {
1486 // // return gw.getNext(i); }
1487 // //template<typename I> I& next(I &i) const { return gw.next(i); }
1489 // template< typename It > It first() const {
1490 // It e; first(e); return e; }
1492 // template< typename It > It first(const Node& v) const {
1493 // It e; first(e, v); return e; }
1495 // //Node head(const Edge& e) const { return gw.head(e); }
1496 // //Node tail(const Edge& e) const { return gw.tail(e); }
1498 // //template<typename I> bool valid(const I& i) const
1499 // // { return gw.valid(i); }
1501 // //template<typename I> void setInvalid(const I &i);
1502 // //{ return gw.setInvalid(i); }
1504 // //int nodeNum() const { return gw.nodeNum(); }
1505 // //int edgeNum() const { return gw.edgeNum(); }
1507 // //template<typename I> Node aNode(const I& e) const {
1508 // // return gw.aNode(e); }
1509 // //template<typename I> Node bNode(const I& e) const {
1510 // // return gw.bNode(e); }
1512 // //Node addNode() const { return gw.addNode(); }
1513 // //Edge addEdge(const Node& tail, const Node& head) const {
1514 // // return gw.addEdge(tail, head); }
1516 // //template<typename I> void erase(const I& i) const { gw.erase(i); }
1518 // //void clear() const { gw.clear(); }
1520 // template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
1522 // NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
1523 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
1524 // NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
1525 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
1528 // template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
1530 // EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
1531 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
1532 // EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
1533 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
1537 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
1543 // // FIXME: comparison should be made better!!!
1544 // template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
1545 // class ResGraphWrapper
1550 // typedef Graph BaseGraph;
1552 // typedef typename Graph::Node Node;
1553 // typedef typename Graph::Edge Edge;
1555 // typedef typename Graph::NodeIt NodeIt;
1557 // class OutEdgeIt {
1561 // typename Graph::OutEdgeIt o;
1562 // typename Graph::InEdgeIt i;
1568 // typename Graph::OutEdgeIt o;
1569 // typename Graph::InEdgeIt i;
1571 // typedef typename Graph::SymEdgeIt SymEdgeIt;
1572 // typedef typename Graph::EdgeIt EdgeIt;
1574 // int nodeNum() const { return gw.nodeNum(); }
1575 // int edgeNum() const { return gw.edgeNum(); }
1577 // Node& first(Node& n) const { return gw.first(n); }
1579 // // Edge and SymEdge is missing!!!!
1580 // // Edge <-> In/OutEdgeIt conversion is missing!!!!
1583 // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const
1587 // while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
1589 // if(!gw.valid(e.o)) {
1591 // while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
1597 // OutEdgeIt &goNext(OutEdgeIt &e)
1599 // if(gw.valid(e.o)) {
1600 // while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
1602 // if(gw.valid(e.o)) return e;
1603 // else gw.first(e.i,e.n);
1606 // while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
1611 // OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
1613 // //bool valid(const OutEdgeIt e) { return gw.valid(e.o)||gw.valid(e.i);}
1616 // InEdgeIt& first(InEdgeIt& e, const Node& n) const
1620 // while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
1622 // if(!gw.valid(e.i)) {
1624 // while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
1630 // InEdgeIt &goNext(InEdgeIt &e)
1632 // if(gw.valid(e.i)) {
1633 // while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
1635 // if(gw.valid(e.i)) return e;
1636 // else gw.first(e.o,e.n);
1639 // while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
1644 // InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
1646 // //bool valid(const InEdgeIt e) { return gw.valid(e.i)||gw.valid(e.o);}
1648 // //template<typename I> I &goNext(I &i); { return gw.goNext(i); }
1649 // //template<typename I> I next(const I i); { return gw.goNext(i); }
1651 // template< typename It > It first() const {
1652 // It e; first(e); return e; }
1654 // template< typename It > It first(Node v) const {
1655 // It e; first(e, v); return e; }
1657 // Node head(const Edge& e) const { return gw.head(e); }
1658 // Node tail(const Edge& e) const { return gw.tail(e); }
1660 // template<typename I> Node aNode(const I& e) const {
1661 // return gw.aNode(e); }
1662 // template<typename I> Node bNode(const I& e) const {
1663 // return gw.bNode(e); }
1665 // //template<typename I> bool valid(const I i);
1666 // //{ return gw.valid(i); }
1668 // //template<typename I> void setInvalid(const I &i);
1669 // //{ return gw.setInvalid(i); }
1671 // Node addNode() { return gw.addNode(); }
1672 // Edge addEdge(const Node& tail, const Node& head) {
1673 // return gw.addEdge(tail, head); }
1675 // template<typename I> void erase(const I& i) { gw.erase(i); }
1677 // void clear() { gw.clear(); }
1679 // template<typename S> class NodeMap : public Graph::NodeMap<S> { };
1680 // template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
1682 // void setGraph(Graph& _graph) { graph = &_graph; }
1683 // Graph& getGraph() { return (*graph); }
1685 // //ResGraphWrapper() : graph(0) { }
1686 // ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
1691 #endif //HUGO_GRAPH_WRAPPER_H