595 typedef typename GraphWrapper<Graph>::Node Node; |
595 typedef typename GraphWrapper<Graph>::Node Node; |
596 typedef typename GraphWrapper<Graph>::NodeIt NodeIt; |
596 typedef typename GraphWrapper<Graph>::NodeIt NodeIt; |
597 class Edge : public Graph::Edge { |
597 class Edge : public Graph::Edge { |
598 friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>; |
598 friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>; |
599 protected: |
599 protected: |
600 bool forward; //true, iff forward |
600 bool backward; //true, iff backward |
601 // typename Graph::Edge e; |
601 // typename Graph::Edge e; |
602 public: |
602 public: |
603 Edge() { } |
603 Edge() { } |
604 Edge(const typename Graph::Edge& _e, bool _forward) : |
604 Edge(const typename Graph::Edge& _e, bool _backward) : |
605 Graph::Edge(_e), forward(_forward) { } |
605 Graph::Edge(_e), backward(_backward) { } |
606 Edge(const Invalid& i) : Graph::Edge(i), forward(false) { } |
606 Edge(const Invalid& i) : Graph::Edge(i), backward(true) { } |
607 //the unique invalid iterator |
607 //the unique invalid iterator |
608 friend bool operator==(const Edge& u, const Edge& v) { |
608 friend bool operator==(const Edge& u, const Edge& v) { |
609 return (v.forward==u.forward && |
609 return (v.backward==u.backward && |
610 static_cast<typename Graph::Edge>(u)== |
610 static_cast<typename Graph::Edge>(u)== |
611 static_cast<typename Graph::Edge>(v)); |
611 static_cast<typename Graph::Edge>(v)); |
612 } |
612 } |
613 friend bool operator!=(const Edge& u, const Edge& v) { |
613 friend bool operator!=(const Edge& u, const Edge& v) { |
614 return (v.forward!=u.forward || |
614 return (v.backward!=u.backward || |
615 static_cast<typename Graph::Edge>(u)!= |
615 static_cast<typename Graph::Edge>(u)!= |
616 static_cast<typename Graph::Edge>(v)); |
616 static_cast<typename Graph::Edge>(v)); |
617 } |
617 } |
618 }; |
618 }; |
619 |
619 |
620 class OutEdgeIt { |
620 class OutEdgeIt { |
621 friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>; |
621 friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>; |
622 protected: |
622 protected: |
623 typename Graph::OutEdgeIt out; |
623 typename Graph::OutEdgeIt out; |
624 typename Graph::InEdgeIt in; |
624 typename Graph::InEdgeIt in; |
625 bool forward; |
625 bool backward; |
626 public: |
626 public: |
627 OutEdgeIt() { } |
627 OutEdgeIt() { } |
628 //FIXME |
628 //FIXME |
629 // OutEdgeIt(const Edge& e) : Edge(e) { } |
629 // OutEdgeIt(const Edge& e) : Edge(e) { } |
630 OutEdgeIt(const Invalid& i) : out(i), in(i), forward(false) { } |
630 OutEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { } |
631 //the unique invalid iterator |
631 //the unique invalid iterator |
632 OutEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG, Node v) { |
632 OutEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG, Node v) { |
633 forward=true; |
633 backward=false; |
634 resG.graph->first(out, v); |
634 resG.graph->first(out, v); |
635 while( resG.graph->valid(out) && !(resG.resCap(*this)>0) ) { resG.graph->next(out); } |
635 while( resG.graph->valid(out) && !(resG.resCap(*this)>0) ) { resG.graph->next(out); } |
636 if (!resG.graph->valid(out)) { |
636 if (!resG.graph->valid(out)) { |
637 forward=false; |
637 backward=true; |
638 resG.graph->first(in, v); |
638 resG.graph->first(in, v); |
639 while( resG.graph->valid(in) && !(resG.resCap(*this)>0) ) { resG.graph->next(in); } |
639 while( resG.graph->valid(in) && !(resG.resCap(*this)>0) ) { resG.graph->next(in); } |
640 } |
640 } |
641 } |
641 } |
642 operator Edge() const { |
642 operator Edge() const { |
643 // Edge e; |
643 // Edge e; |
644 // e.forward=this->forward; |
644 // e.forward=this->forward; |
645 // if (this->forward) e=out; else e=in; |
645 // if (this->forward) e=out; else e=in; |
646 // return e; |
646 // return e; |
647 if (this->forward) |
647 if (this->backward) |
648 return Edge(out, this->forward); |
648 return Edge(in, this->backward); |
649 else |
649 else |
650 return Edge(in, this->forward); |
650 return Edge(out, this->backward); |
651 } |
651 } |
652 }; |
652 }; |
653 |
653 |
654 class InEdgeIt { |
654 class InEdgeIt { |
655 friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>; |
655 friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>; |
656 protected: |
656 protected: |
657 typename Graph::OutEdgeIt out; |
657 typename Graph::OutEdgeIt out; |
658 typename Graph::InEdgeIt in; |
658 typename Graph::InEdgeIt in; |
659 bool forward; |
659 bool backward; |
660 public: |
660 public: |
661 InEdgeIt() { } |
661 InEdgeIt() { } |
662 //FIXME |
662 //FIXME |
663 // OutEdgeIt(const Edge& e) : Edge(e) { } |
663 // OutEdgeIt(const Edge& e) : Edge(e) { } |
664 InEdgeIt(const Invalid& i) : out(i), in(i), forward(false) { } |
664 InEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { } |
665 //the unique invalid iterator |
665 //the unique invalid iterator |
666 InEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG, Node v) { |
666 InEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG, Node v) { |
667 forward=true; |
667 backward=false; |
668 resG.graph->first(in, v); |
668 resG.graph->first(in, v); |
669 while( resG.graph->valid(in) && !(resG.resCap(*this)>0) ) { resG.graph->next(in); } |
669 while( resG.graph->valid(in) && !(resG.resCap(*this)>0) ) { resG.graph->next(in); } |
670 if (!resG.graph->valid(in)) { |
670 if (!resG.graph->valid(in)) { |
671 forward=false; |
671 backward=true; |
672 resG.graph->first(out, v); |
672 resG.graph->first(out, v); |
673 while( resG.graph->valid(out) && !(resG.resCap(*this)>0) ) { resG.graph->next(out); } |
673 while( resG.graph->valid(out) && !(resG.resCap(*this)>0) ) { resG.graph->next(out); } |
674 } |
674 } |
675 } |
675 } |
676 operator Edge() const { |
676 operator Edge() const { |
677 // Edge e; |
677 // Edge e; |
678 // e.forward=this->forward; |
678 // e.forward=this->forward; |
679 // if (this->forward) e=out; else e=in; |
679 // if (this->forward) e=out; else e=in; |
680 // return e; |
680 // return e; |
681 if (this->forward) |
681 if (this->backward) |
682 return Edge(in, this->forward); |
682 return Edge(out, this->backward); |
683 else |
683 else |
684 return Edge(out, this->forward); |
684 return Edge(in, this->backward); |
685 } |
685 } |
686 }; |
686 }; |
687 |
687 |
688 class EdgeIt { |
688 class EdgeIt { |
689 friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>; |
689 friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>; |
690 protected: |
690 protected: |
691 typename Graph::EdgeIt e; |
691 typename Graph::EdgeIt e; |
692 bool forward; |
692 bool backward; |
693 public: |
693 public: |
694 EdgeIt() { } |
694 EdgeIt() { } |
695 EdgeIt(const Invalid& i) : e(i), forward(false) { } |
695 EdgeIt(const Invalid& i) : e(i), backward(true) { } |
696 EdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG) { |
696 EdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG) { |
697 forward=true; |
697 backward=false; |
698 resG.graph->first(e); |
698 resG.graph->first(e); |
699 while (resG.graph->valid(e) && !(resG.resCap(*this)>0)) resG.graph->next(e); |
699 while (resG.graph->valid(e) && !(resG.resCap(*this)>0)) resG.graph->next(e); |
700 if (!resG.graph->valid(e)) { |
700 if (!resG.graph->valid(e)) { |
701 forward=false; |
701 backward=true; |
702 resG.graph->first(e); |
702 resG.graph->first(e); |
703 while (resG.graph->valid(e) && !(resG.resCap(*this)>0)) resG.graph->next(e); |
703 while (resG.graph->valid(e) && !(resG.resCap(*this)>0)) resG.graph->next(e); |
704 } |
704 } |
705 } |
705 } |
706 operator Edge() const { |
706 operator Edge() const { |
707 return Edge(e, this->forward); |
707 return Edge(e, this->backward); |
708 } |
708 } |
709 }; |
709 }; |
710 |
710 |
711 using GraphWrapper<Graph>::first; |
711 using GraphWrapper<Graph>::first; |
712 // NodeIt& first(NodeIt& i) const { |
712 // NodeIt& first(NodeIt& i) const { |
782 } |
782 } |
783 return e; |
783 return e; |
784 } |
784 } |
785 |
785 |
786 Node tail(Edge e) const { |
786 Node tail(Edge e) const { |
787 return ((e.forward) ? this->graph->tail(e) : this->graph->head(e)); } |
787 return ((!e.backward) ? this->graph->tail(e) : this->graph->head(e)); } |
788 Node head(Edge e) const { |
788 Node head(Edge e) const { |
789 return ((e.forward) ? this->graph->head(e) : this->graph->tail(e)); } |
789 return ((!e.backward) ? this->graph->head(e) : this->graph->tail(e)); } |
790 |
790 |
791 Node aNode(OutEdgeIt e) const { |
791 Node aNode(OutEdgeIt e) const { |
792 return ((e.forward) ? this->graph->aNode(e.out) : |
792 return ((!e.backward) ? this->graph->aNode(e.out) : |
793 this->graph->aNode(e.in)); } |
793 this->graph->aNode(e.in)); } |
794 Node bNode(OutEdgeIt e) const { |
794 Node bNode(OutEdgeIt e) const { |
795 return ((e.forward) ? this->graph->bNode(e.out) : |
795 return ((!e.backward) ? this->graph->bNode(e.out) : |
796 this->graph->bNode(e.in)); } |
796 this->graph->bNode(e.in)); } |
797 |
797 |
798 Node aNode(InEdgeIt e) const { |
798 Node aNode(InEdgeIt e) const { |
799 return ((e.forward) ? this->graph->aNode(e.in) : |
799 return ((!e.backward) ? this->graph->aNode(e.in) : |
800 this->graph->aNode(e.out)); } |
800 this->graph->aNode(e.out)); } |
801 Node bNode(InEdgeIt e) const { |
801 Node bNode(InEdgeIt e) const { |
802 return ((e.forward) ? this->graph->bNode(e.in) : |
802 return ((!e.backward) ? this->graph->bNode(e.in) : |
803 this->graph->bNode(e.out)); } |
803 this->graph->bNode(e.out)); } |
804 |
804 |
805 // int nodeNum() const { return graph->nodeNum(); } |
805 // int nodeNum() const { return graph->nodeNum(); } |
806 //FIXME |
806 //FIXME |
807 void edgeNum() const { } |
807 void edgeNum() const { } |
852 typename Graph::template EdgeMap<T> forward_map, backward_map; |
852 typename Graph::template EdgeMap<T> forward_map, backward_map; |
853 public: |
853 public: |
854 EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { } |
854 EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { } |
855 EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { } |
855 EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { } |
856 void set(Edge e, T a) { |
856 void set(Edge e, T a) { |
857 if (e.forward) |
857 if (!e.backward) |
858 forward_map.set(e.out, a); |
858 forward_map.set(e.out, a); |
859 else |
859 else |
860 backward_map.set(e.in, a); |
860 backward_map.set(e.in, a); |
861 } |
861 } |
862 T operator[](Edge e) const { |
862 T operator[](Edge e) const { |
863 if (e.forward) |
863 if (!e.backward) |
864 return forward_map[e.out]; |
864 return forward_map[e.out]; |
865 else |
865 else |
866 return backward_map[e.in]; |
866 return backward_map[e.in]; |
867 } |
867 } |
868 // T get(Edge e) const { |
868 // T get(Edge e) const { |