ResGraphWrapper mods.
authormarci
Fri, 07 May 2004 06:33:02 +0000
changeset 56518787f6db0db
parent 564 f84611a14a33
child 566 14355e502338
ResGraphWrapper mods.
src/hugo/graph_wrapper.h
     1.1 --- a/src/hugo/graph_wrapper.h	Fri May 07 05:29:45 2004 +0000
     1.2 +++ b/src/hugo/graph_wrapper.h	Fri May 07 06:33:02 2004 +0000
     1.3 @@ -597,21 +597,21 @@
     1.4      class Edge : public Graph::Edge {
     1.5        friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
     1.6      protected:
     1.7 -      bool forward; //true, iff forward
     1.8 +      bool backward; //true, iff backward
     1.9  //      typename Graph::Edge e;
    1.10      public:
    1.11        Edge() { }
    1.12 -      Edge(const typename Graph::Edge& _e, bool _forward) : 
    1.13 -	Graph::Edge(_e), forward(_forward) { }
    1.14 -      Edge(const Invalid& i) : Graph::Edge(i), forward(false) { }
    1.15 +      Edge(const typename Graph::Edge& _e, bool _backward) : 
    1.16 +	Graph::Edge(_e), backward(_backward) { }
    1.17 +      Edge(const Invalid& i) : Graph::Edge(i), backward(true) { }
    1.18  //the unique invalid iterator
    1.19        friend bool operator==(const Edge& u, const Edge& v) { 
    1.20 -	return (v.forward==u.forward && 
    1.21 +	return (v.backward==u.backward && 
    1.22  		static_cast<typename Graph::Edge>(u)==
    1.23  		static_cast<typename Graph::Edge>(v));
    1.24        } 
    1.25        friend bool operator!=(const Edge& u, const Edge& v) { 
    1.26 -	return (v.forward!=u.forward || 
    1.27 +	return (v.backward!=u.backward || 
    1.28  		static_cast<typename Graph::Edge>(u)!=
    1.29  		static_cast<typename Graph::Edge>(v));
    1.30        } 
    1.31 @@ -622,19 +622,19 @@
    1.32      protected:
    1.33        typename Graph::OutEdgeIt out;
    1.34        typename Graph::InEdgeIt in;
    1.35 -      bool forward;
    1.36 +      bool backward;
    1.37      public:
    1.38        OutEdgeIt() { }
    1.39        //FIXME
    1.40  //      OutEdgeIt(const Edge& e) : Edge(e) { }
    1.41 -      OutEdgeIt(const Invalid& i) : out(i), in(i), forward(false) { }
    1.42 +      OutEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
    1.43  //the unique invalid iterator
    1.44        OutEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG, Node v) { 
    1.45 -	forward=true;
    1.46 +	backward=false;
    1.47  	resG.graph->first(out, v);
    1.48  	while( resG.graph->valid(out) && !(resG.resCap(*this)>0) ) { resG.graph->next(out); }
    1.49  	if (!resG.graph->valid(out)) {
    1.50 -	  forward=false;
    1.51 +	  backward=true;
    1.52  	  resG.graph->first(in, v);
    1.53  	  while( resG.graph->valid(in) && !(resG.resCap(*this)>0) ) { resG.graph->next(in); }
    1.54  	}
    1.55 @@ -644,10 +644,10 @@
    1.56  //	e.forward=this->forward;
    1.57  //	if (this->forward) e=out; else e=in;
    1.58  //	return e;
    1.59 -	if (this->forward) 
    1.60 -	  return Edge(out, this->forward); 
    1.61 +	if (this->backward) 
    1.62 +	  return Edge(in, this->backward); 
    1.63  	else 
    1.64 -	  return Edge(in, this->forward);
    1.65 +	  return Edge(out, this->backward);
    1.66        }
    1.67      };
    1.68  
    1.69 @@ -656,19 +656,19 @@
    1.70      protected:
    1.71        typename Graph::OutEdgeIt out;
    1.72        typename Graph::InEdgeIt in;
    1.73 -      bool forward;
    1.74 +      bool backward;
    1.75      public:
    1.76        InEdgeIt() { }
    1.77        //FIXME
    1.78  //      OutEdgeIt(const Edge& e) : Edge(e) { }
    1.79 -      InEdgeIt(const Invalid& i) : out(i), in(i), forward(false) { }
    1.80 +      InEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
    1.81  //the unique invalid iterator
    1.82        InEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG, Node v) { 
    1.83 -	forward=true;
    1.84 +	backward=false;
    1.85  	resG.graph->first(in, v);
    1.86  	while( resG.graph->valid(in) && !(resG.resCap(*this)>0) ) { resG.graph->next(in); }
    1.87  	if (!resG.graph->valid(in)) {
    1.88 -	  forward=false;
    1.89 +	  backward=true;
    1.90  	  resG.graph->first(out, v);
    1.91  	  while( resG.graph->valid(out) && !(resG.resCap(*this)>0) ) { resG.graph->next(out); }
    1.92  	}
    1.93 @@ -678,10 +678,10 @@
    1.94  //	e.forward=this->forward;
    1.95  //	if (this->forward) e=out; else e=in;
    1.96  //	return e;
    1.97 -	if (this->forward) 
    1.98 -	  return Edge(in, this->forward); 
    1.99 +	if (this->backward) 
   1.100 +	  return Edge(out, this->backward); 
   1.101  	else 
   1.102 -	  return Edge(out, this->forward);
   1.103 +	  return Edge(in, this->backward);
   1.104        }
   1.105      };
   1.106  
   1.107 @@ -689,22 +689,22 @@
   1.108        friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
   1.109      protected:
   1.110        typename Graph::EdgeIt e;
   1.111 -      bool forward;
   1.112 +      bool backward;
   1.113      public:
   1.114        EdgeIt() { }
   1.115 -      EdgeIt(const Invalid& i) : e(i), forward(false) { }
   1.116 +      EdgeIt(const Invalid& i) : e(i), backward(true) { }
   1.117        EdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG) { 
   1.118 -	forward=true;
   1.119 +	backward=false;
   1.120  	resG.graph->first(e);
   1.121  	while (resG.graph->valid(e) && !(resG.resCap(*this)>0)) resG.graph->next(e);
   1.122  	if (!resG.graph->valid(e)) {
   1.123 -	  forward=false;
   1.124 +	  backward=true;
   1.125  	  resG.graph->first(e);
   1.126  	  while (resG.graph->valid(e) && !(resG.resCap(*this)>0)) resG.graph->next(e);
   1.127  	}
   1.128        }
   1.129        operator Edge() const { 
   1.130 -	return Edge(e, this->forward);
   1.131 +	return Edge(e, this->backward);
   1.132        }
   1.133      };
   1.134  
   1.135 @@ -726,13 +726,13 @@
   1.136      using GraphWrapper<Graph>::next;
   1.137  //    NodeIt& next(NodeIt& n) const { GraphWrapper<Graph>::next(n); return n; }
   1.138      OutEdgeIt& next(OutEdgeIt& e) const { 
   1.139 -      if (e.forward) {
   1.140 +      if (!e.backward) {
   1.141  	Node v=this->graph->aNode(e.out);
   1.142  	this->graph->next(e.out);
   1.143  	while( this->graph->valid(e.out) && !(resCap(e)>0) ) { 
   1.144  	  this->graph->next(e.out); }
   1.145  	if (!this->graph->valid(e.out)) {
   1.146 -	  e.forward=false;
   1.147 +	  e.backward=true;
   1.148  	  this->graph->first(e.in, v); 
   1.149  	  while( this->graph->valid(e.in) && !(resCap(e)>0) ) { 
   1.150  	    this->graph->next(e.in); }
   1.151 @@ -746,13 +746,13 @@
   1.152      }
   1.153  //     FIXME Not tested
   1.154      InEdgeIt& next(InEdgeIt& e) const { 
   1.155 -      if (e.forward) {
   1.156 +      if (!e.backward) {
   1.157  	Node v=this->graph->aNode(e.in);
   1.158  	this->graph->next(e.in);
   1.159  	while( this->graph->valid(e.in) && !(resCap(e)>0) ) { 
   1.160  	  this->graph->next(e.in); }
   1.161  	if (!this->graph->valid(e.in)) {
   1.162 -	  e.forward=false;
   1.163 +	  e.backward=true;
   1.164  	  this->graph->first(e.out, v); 
   1.165  	  while( this->graph->valid(e.out) && !(resCap(e)>0) ) { 
   1.166  	    this->graph->next(e.out); }
   1.167 @@ -765,12 +765,12 @@
   1.168        return e;
   1.169      }
   1.170      EdgeIt& next(EdgeIt& e) const {
   1.171 -      if (e.forward) {
   1.172 +      if (!e.backward) {
   1.173  	this->graph->next(e.e);
   1.174  	while( this->graph->valid(e.e) && !(resCap(e)>0) ) { 
   1.175  	  this->graph->next(e.e); }
   1.176  	if (!this->graph->valid(e.e)) {
   1.177 -	  e.forward=false;
   1.178 +	  e.backward=true;
   1.179  	  this->graph->first(e.e); 
   1.180  	  while( this->graph->valid(e.e) && !(resCap(e)>0) ) { 
   1.181  	    this->graph->next(e.e); }
   1.182 @@ -784,22 +784,22 @@
   1.183      }
   1.184  
   1.185      Node tail(Edge e) const { 
   1.186 -      return ((e.forward) ? this->graph->tail(e) : this->graph->head(e)); }
   1.187 +      return ((!e.backward) ? this->graph->tail(e) : this->graph->head(e)); }
   1.188      Node head(Edge e) const { 
   1.189 -      return ((e.forward) ? this->graph->head(e) : this->graph->tail(e)); }
   1.190 +      return ((!e.backward) ? this->graph->head(e) : this->graph->tail(e)); }
   1.191  
   1.192      Node aNode(OutEdgeIt e) const { 
   1.193 -      return ((e.forward) ? this->graph->aNode(e.out) : 
   1.194 +      return ((!e.backward) ? this->graph->aNode(e.out) : 
   1.195  	      this->graph->aNode(e.in)); }
   1.196      Node bNode(OutEdgeIt e) const { 
   1.197 -      return ((e.forward) ? this->graph->bNode(e.out) : 
   1.198 +      return ((!e.backward) ? this->graph->bNode(e.out) : 
   1.199  	      this->graph->bNode(e.in)); }
   1.200  
   1.201      Node aNode(InEdgeIt e) const { 
   1.202 -      return ((e.forward) ? this->graph->aNode(e.in) : 
   1.203 +      return ((!e.backward) ? this->graph->aNode(e.in) : 
   1.204  	      this->graph->aNode(e.out)); }
   1.205      Node bNode(InEdgeIt e) const { 
   1.206 -      return ((e.forward) ? this->graph->bNode(e.in) : 
   1.207 +      return ((!e.backward) ? this->graph->bNode(e.in) : 
   1.208  	      this->graph->bNode(e.out)); }
   1.209  
   1.210  //    int nodeNum() const { return graph->nodeNum(); }
   1.211 @@ -816,11 +816,11 @@
   1.212  	//return e.forward ? graph->valid(e.out) : graph->valid(e.in); 
   1.213      }
   1.214  
   1.215 -    bool forward(const Edge& e) const { return e.forward; }
   1.216 -    bool backward(const Edge& e) const { return !e.forward; }
   1.217 +    bool forward(const Edge& e) const { return !e.backward; }
   1.218 +    bool backward(const Edge& e) const { return e.backward; }
   1.219  
   1.220      void augment(const Edge& e, Number a) const {
   1.221 -      if (e.forward)  
   1.222 +      if (!e.backward)  
   1.223  // 	flow->set(e.out, flow->get(e.out)+a);
   1.224  	flow->set(e, (*flow)[e]+a);
   1.225        else  
   1.226 @@ -829,7 +829,7 @@
   1.227      }
   1.228  
   1.229      Number resCap(const Edge& e) const { 
   1.230 -      if (e.forward) 
   1.231 +      if (!e.backward) 
   1.232  //	return (capacity->get(e.out)-flow->get(e.out)); 
   1.233  	return ((*capacity)[e]-(*flow)[e]); 
   1.234        else 
   1.235 @@ -854,13 +854,13 @@
   1.236        EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
   1.237        EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
   1.238        void set(Edge e, T a) { 
   1.239 -	if (e.forward) 
   1.240 +	if (!e.backward) 
   1.241  	  forward_map.set(e.out, a); 
   1.242  	else 
   1.243  	  backward_map.set(e.in, a); 
   1.244        }
   1.245        T operator[](Edge e) const { 
   1.246 -	if (e.forward) 
   1.247 +	if (!e.backward) 
   1.248  	  return forward_map[e.out]; 
   1.249  	else 
   1.250  	  return backward_map[e.in];