One more experimental study about dereferation vs optimization
authormarci
Sat, 03 Apr 2004 17:26:46 +0000
changeset 2813fefabfd00b7
parent 280 19f3943521ab
child 282 7f85e99502db
One more experimental study about dereferation vs optimization
src/work/marci/experiment/bfs_iterator.h
src/work/marci/experiment/bfs_iterator_1.h
src/work/marci/experiment/deref_vs_optimization
src/work/marci/experiment/deref_vs_optimization_lenyeg
src/work/marci/experiment/edmonds_karp.h
src/work/marci/experiment/edmonds_karp_1.h
src/work/marci/experiment/edmonds_karp_demo.cc
src/work/marci/experiment/edmonds_karp_demo_1.cc
src/work/marci/experiment/graph_wrapper.h
src/work/marci/experiment/graph_wrapper_1.h
src/work/marci/experiment/iterator_bfs_demo.cc
src/work/marci/experiment/iterator_bfs_demo_1.cc
src/work/marci/experiment/list_graph.h
src/work/marci/experiment/makefile
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/work/marci/experiment/bfs_iterator.h	Sat Apr 03 17:26:46 2004 +0000
     1.3 @@ -0,0 +1,841 @@
     1.4 +// -*- c++ -*-
     1.5 +#ifndef HUGO_BFS_ITERATOR_H
     1.6 +#define HUGO_BFS_ITERATOR_H
     1.7 +
     1.8 +#include <queue>
     1.9 +#include <stack>
    1.10 +#include <utility>
    1.11 +#include <graph_wrapper.h>
    1.12 +
    1.13 +namespace hugo {
    1.14 +
    1.15 +//   template <typename Graph>
    1.16 +//   struct bfs {
    1.17 +//     typedef typename Graph::Node Node;
    1.18 +//     typedef typename Graph::Edge Edge;
    1.19 +//     typedef typename Graph::NodeIt NodeIt;
    1.20 +//     typedef typename Graph::OutEdgeIt OutEdgeIt;
    1.21 +//     Graph& G;
    1.22 +//     Node s;
    1.23 +//     typename Graph::NodeMap<bool> reached;
    1.24 +//     typename Graph::NodeMap<Edge> pred;
    1.25 +//     typename Graph::NodeMap<int> dist;
    1.26 +//     std::queue<Node> bfs_queue;
    1.27 +//     bfs(Graph& _G, Node _s) : G(_G), s(_s), reached(_G), pred(_G), dist(_G) { 
    1.28 +//       bfs_queue.push(s); 
    1.29 +//       for(NodeIt i=G.template first<NodeIt>(); i.valid(); ++i) 
    1.30 +// 	reached.set(i, false);
    1.31 +//       reached.set(s, true);
    1.32 +//       dist.set(s, 0); 
    1.33 +//     }
    1.34 +    
    1.35 +//     void run() {
    1.36 +//       while (!bfs_queue.empty()) {
    1.37 +// 	Node v=bfs_queue.front();
    1.38 +// 	OutEdgeIt e=G.template first<OutEdgeIt>(v);
    1.39 +// 	bfs_queue.pop();
    1.40 +// 	for( ; e.valid(); ++e) {
    1.41 +// 	  Node w=G.bNode(e);
    1.42 +// 	  std::cout << "scan node " << G.id(w) << " from node " << G.id(v) << std::endl;
    1.43 +// 	  if (!reached.get(w)) {
    1.44 +// 	    std::cout << G.id(w) << " is newly reached :-)" << std::endl;
    1.45 +// 	    bfs_queue.push(w);
    1.46 +// 	    dist.set(w, dist.get(v)+1);
    1.47 +// 	    pred.set(w, e);
    1.48 +// 	    reached.set(w, true);
    1.49 +// 	  } else {
    1.50 +// 	    std::cout << G.id(w) << " is already reached" << std::endl;
    1.51 +// 	  }
    1.52 +// 	}
    1.53 +//       }
    1.54 +//     }
    1.55 +//   };
    1.56 +
    1.57 +//   template <typename Graph> 
    1.58 +//   struct bfs_visitor {
    1.59 +//     typedef typename Graph::Node Node;
    1.60 +//     typedef typename Graph::Edge Edge;
    1.61 +//     typedef typename Graph::OutEdgeIt OutEdgeIt;
    1.62 +//     Graph& G;
    1.63 +//     bfs_visitor(Graph& _G) : G(_G) { }
    1.64 +//     void at_previously_reached(OutEdgeIt& e) { 
    1.65 +//       //Node v=G.aNode(e);
    1.66 +//       Node w=G.bNode(e);
    1.67 +//       std::cout << G.id(w) << " is already reached" << std::endl;
    1.68 +//    }
    1.69 +//     void at_newly_reached(OutEdgeIt& e) { 
    1.70 +//       //Node v=G.aNode(e);
    1.71 +//       Node w=G.bNode(e);
    1.72 +//       std::cout << G.id(w) << " is newly reached :-)" << std::endl;
    1.73 +//     }
    1.74 +//   };
    1.75 +
    1.76 +//   template <typename Graph, typename ReachedMap, typename visitor_type>
    1.77 +//   struct bfs_iterator {
    1.78 +//     typedef typename Graph::Node Node;
    1.79 +//     typedef typename Graph::Edge Edge;
    1.80 +//     typedef typename Graph::OutEdgeIt OutEdgeIt;
    1.81 +//     Graph& G;
    1.82 +//     std::queue<OutEdgeIt>& bfs_queue;
    1.83 +//     ReachedMap& reached;
    1.84 +//     visitor_type& visitor;
    1.85 +//     void process() {
    1.86 +//       while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
    1.87 +//       if (bfs_queue.empty()) return;
    1.88 +//       OutEdgeIt e=bfs_queue.front();
    1.89 +//       //Node v=G.aNode(e);
    1.90 +//       Node w=G.bNode(e);
    1.91 +//       if (!reached.get(w)) {
    1.92 +// 	visitor.at_newly_reached(e);
    1.93 +// 	bfs_queue.push(G.template first<OutEdgeIt>(w));
    1.94 +// 	reached.set(w, true);
    1.95 +//       } else {
    1.96 +// 	visitor.at_previously_reached(e);
    1.97 +//       }
    1.98 +//     }
    1.99 +//     bfs_iterator(Graph& _G, std::queue<OutEdgeIt>& _bfs_queue, ReachedMap& _reached, visitor_type& _visitor) : G(_G), bfs_queue(_bfs_queue), reached(_reached), visitor(_visitor) { 
   1.100 +//       //while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   1.101 +//       valid();
   1.102 +//     }
   1.103 +//     bfs_iterator<Graph, ReachedMap, visitor_type>& operator++() { 
   1.104 +//       //while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   1.105 +//       //if (bfs_queue.empty()) return *this;
   1.106 +//       if (!valid()) return *this;
   1.107 +//       ++(bfs_queue.front());
   1.108 +//       //while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   1.109 +//       valid();
   1.110 +//       return *this;
   1.111 +//     }
   1.112 +//     //void next() { 
   1.113 +//     //  while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   1.114 +//     //  if (bfs_queue.empty()) return;
   1.115 +//     //  ++(bfs_queue.front());
   1.116 +//     //  while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   1.117 +//     //}
   1.118 +//     bool valid() { 
   1.119 +//       while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   1.120 +//       if (bfs_queue.empty()) return false; else return true;
   1.121 +//     }
   1.122 +//     //bool finished() { 
   1.123 +//     //  while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   1.124 +//     //  if (bfs_queue.empty()) return true; else return false;
   1.125 +//     //}
   1.126 +//     operator Edge () { return bfs_queue.front(); }
   1.127 +
   1.128 +//   };
   1.129 +
   1.130 +//   template <typename Graph, typename ReachedMap>
   1.131 +//   struct bfs_iterator1 {
   1.132 +//     typedef typename Graph::Node Node;
   1.133 +//     typedef typename Graph::Edge Edge;
   1.134 +//     typedef typename Graph::OutEdgeIt OutEdgeIt;
   1.135 +//     Graph& G;
   1.136 +//     std::queue<OutEdgeIt>& bfs_queue;
   1.137 +//     ReachedMap& reached;
   1.138 +//     bool _newly_reached;
   1.139 +//     bfs_iterator1(Graph& _G, std::queue<OutEdgeIt>& _bfs_queue, ReachedMap& _reached) : G(_G), bfs_queue(_bfs_queue), reached(_reached) { 
   1.140 +//       valid();
   1.141 +//       if (!bfs_queue.empty() && bfs_queue.front().valid()) { 
   1.142 +// 	OutEdgeIt e=bfs_queue.front();
   1.143 +// 	Node w=G.bNode(e);
   1.144 +// 	if (!reached.get(w)) {
   1.145 +// 	  bfs_queue.push(G.template first<OutEdgeIt>(w));
   1.146 +// 	  reached.set(w, true);
   1.147 +// 	  _newly_reached=true;
   1.148 +// 	} else {
   1.149 +// 	  _newly_reached=false;
   1.150 +// 	}
   1.151 +//       }
   1.152 +//     }
   1.153 +//     bfs_iterator1<Graph, ReachedMap>& operator++() { 
   1.154 +//       if (!valid()) return *this;
   1.155 +//       ++(bfs_queue.front());
   1.156 +//       valid();
   1.157 +//       if (!bfs_queue.empty() && bfs_queue.front().valid()) { 
   1.158 +// 	OutEdgeIt e=bfs_queue.front();
   1.159 +// 	Node w=G.bNode(e);
   1.160 +// 	if (!reached.get(w)) {
   1.161 +// 	  bfs_queue.push(G.template first<OutEdgeIt>(w));
   1.162 +// 	  reached.set(w, true);
   1.163 +// 	  _newly_reached=true;
   1.164 +// 	} else {
   1.165 +// 	  _newly_reached=false;
   1.166 +// 	}
   1.167 +//       }
   1.168 +//       return *this;
   1.169 +//     }
   1.170 +//     bool valid() { 
   1.171 +//       while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   1.172 +//       if (bfs_queue.empty()) return false; else return true;
   1.173 +//     }
   1.174 +//     operator OutEdgeIt() { return bfs_queue.front(); }
   1.175 +//     //ize
   1.176 +//     bool newly_reached() { return _newly_reached; }
   1.177 +
   1.178 +//   };
   1.179 +
   1.180 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   1.181 +//   struct BfsIterator {
   1.182 +//     typedef typename Graph::Node Node;
   1.183 +//     Graph& G;
   1.184 +//     std::queue<OutEdgeIt>& bfs_queue;
   1.185 +//     ReachedMap& reached;
   1.186 +//     bool b_node_newly_reached;
   1.187 +//     OutEdgeIt actual_edge;
   1.188 +//     BfsIterator(Graph& _G, 
   1.189 +// 		std::queue<OutEdgeIt>& _bfs_queue, 
   1.190 +// 		ReachedMap& _reached) : 
   1.191 +//       G(_G), bfs_queue(_bfs_queue), reached(_reached) { 
   1.192 +//       actual_edge=bfs_queue.front();
   1.193 +//       if (actual_edge.valid()) { 
   1.194 +// 	Node w=G.bNode(actual_edge);
   1.195 +// 	if (!reached.get(w)) {
   1.196 +// 	  bfs_queue.push(G.firstOutEdge(w));
   1.197 +// 	  reached.set(w, true);
   1.198 +// 	  b_node_newly_reached=true;
   1.199 +// 	} else {
   1.200 +// 	  b_node_newly_reached=false;
   1.201 +// 	}
   1.202 +//       }
   1.203 +//     }
   1.204 +//     BfsIterator<Graph, OutEdgeIt, ReachedMap>& 
   1.205 +//     operator++() { 
   1.206 +//       if (bfs_queue.front().valid()) { 
   1.207 +// 	++(bfs_queue.front());
   1.208 +// 	actual_edge=bfs_queue.front();
   1.209 +// 	if (actual_edge.valid()) {
   1.210 +// 	  Node w=G.bNode(actual_edge);
   1.211 +// 	  if (!reached.get(w)) {
   1.212 +// 	    bfs_queue.push(G.firstOutEdge(w));
   1.213 +// 	    reached.set(w, true);
   1.214 +// 	    b_node_newly_reached=true;
   1.215 +// 	  } else {
   1.216 +// 	    b_node_newly_reached=false;
   1.217 +// 	  }
   1.218 +// 	}
   1.219 +//       } else {
   1.220 +// 	bfs_queue.pop(); 
   1.221 +// 	actual_edge=bfs_queue.front();
   1.222 +// 	if (actual_edge.valid()) {
   1.223 +// 	  Node w=G.bNode(actual_edge);
   1.224 +// 	  if (!reached.get(w)) {
   1.225 +// 	    bfs_queue.push(G.firstOutEdge(w));
   1.226 +// 	    reached.set(w, true);
   1.227 +// 	    b_node_newly_reached=true;
   1.228 +// 	  } else {
   1.229 +// 	    b_node_newly_reached=false;
   1.230 +// 	  }
   1.231 +// 	}
   1.232 +//       }
   1.233 +//       return *this;
   1.234 +//     }
   1.235 +//     bool finished() { return bfs_queue.empty(); }
   1.236 +//     operator OutEdgeIt () { return actual_edge; }
   1.237 +//     bool bNodeIsNewlyReached() { return b_node_newly_reached; }
   1.238 +//     bool aNodeIsExamined() { return !(actual_edge.valid()); }
   1.239 +//   };
   1.240 +
   1.241 +
   1.242 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   1.243 +//   struct DfsIterator {
   1.244 +//     typedef typename Graph::Node Node;
   1.245 +//     Graph& G;
   1.246 +//     std::stack<OutEdgeIt>& bfs_queue;
   1.247 +//     ReachedMap& reached;
   1.248 +//     bool b_node_newly_reached;
   1.249 +//     OutEdgeIt actual_edge;
   1.250 +//     DfsIterator(Graph& _G, 
   1.251 +// 		std::stack<OutEdgeIt>& _bfs_queue, 
   1.252 +// 		ReachedMap& _reached) : 
   1.253 +//       G(_G), bfs_queue(_bfs_queue), reached(_reached) { 
   1.254 +//       actual_edge=bfs_queue.top();
   1.255 +//       if (actual_edge.valid()) { 
   1.256 +// 	Node w=G.bNode(actual_edge);
   1.257 +// 	if (!reached.get(w)) {
   1.258 +// 	  bfs_queue.push(G.firstOutEdge(w));
   1.259 +// 	  reached.set(w, true);
   1.260 +// 	  b_node_newly_reached=true;
   1.261 +// 	} else {
   1.262 +// 	  ++(bfs_queue.top());
   1.263 +// 	  b_node_newly_reached=false;
   1.264 +// 	}
   1.265 +//       } else {
   1.266 +// 	bfs_queue.pop();
   1.267 +//       }
   1.268 +//     }
   1.269 +//     DfsIterator<Graph, OutEdgeIt, ReachedMap>& 
   1.270 +//     operator++() { 
   1.271 +//       actual_edge=bfs_queue.top();
   1.272 +//       if (actual_edge.valid()) { 
   1.273 +// 	Node w=G.bNode(actual_edge);
   1.274 +// 	if (!reached.get(w)) {
   1.275 +// 	  bfs_queue.push(G.firstOutEdge(w));
   1.276 +// 	  reached.set(w, true);
   1.277 +// 	  b_node_newly_reached=true;
   1.278 +// 	} else {
   1.279 +// 	  ++(bfs_queue.top());
   1.280 +// 	  b_node_newly_reached=false;
   1.281 +// 	}
   1.282 +//       } else {
   1.283 +// 	bfs_queue.pop();
   1.284 +//       }
   1.285 +//       return *this;
   1.286 +//     }
   1.287 +//     bool finished() { return bfs_queue.empty(); }
   1.288 +//     operator OutEdgeIt () { return actual_edge; }
   1.289 +//     bool bNodeIsNewlyReached() { return b_node_newly_reached; }
   1.290 +//     bool aNodeIsExamined() { return !(actual_edge.valid()); }
   1.291 +//   };
   1.292 +
   1.293 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   1.294 +//   struct BfsIterator1 {
   1.295 +//     typedef typename Graph::Node Node;
   1.296 +//     Graph& G;
   1.297 +//     std::queue<OutEdgeIt>& bfs_queue;
   1.298 +//     ReachedMap& reached;
   1.299 +//     bool b_node_newly_reached;
   1.300 +//     OutEdgeIt actual_edge;
   1.301 +//     BfsIterator1(Graph& _G, 
   1.302 +// 		std::queue<OutEdgeIt>& _bfs_queue, 
   1.303 +// 		ReachedMap& _reached) : 
   1.304 +//       G(_G), bfs_queue(_bfs_queue), reached(_reached) { 
   1.305 +//       actual_edge=bfs_queue.front();
   1.306 +//       if (actual_edge.valid()) { 
   1.307 +//       	Node w=G.bNode(actual_edge);
   1.308 +// 	if (!reached.get(w)) {
   1.309 +// 	  bfs_queue.push(OutEdgeIt(G, w));
   1.310 +// 	  reached.set(w, true);
   1.311 +// 	  b_node_newly_reached=true;
   1.312 +// 	} else {
   1.313 +// 	  b_node_newly_reached=false;
   1.314 +// 	}
   1.315 +//       }
   1.316 +//     }
   1.317 +//     void next() { 
   1.318 +//       if (bfs_queue.front().valid()) { 
   1.319 +// 	++(bfs_queue.front());
   1.320 +// 	actual_edge=bfs_queue.front();
   1.321 +// 	if (actual_edge.valid()) {
   1.322 +// 	  Node w=G.bNode(actual_edge);
   1.323 +// 	  if (!reached.get(w)) {
   1.324 +// 	    bfs_queue.push(OutEdgeIt(G, w));
   1.325 +// 	    reached.set(w, true);
   1.326 +// 	    b_node_newly_reached=true;
   1.327 +// 	  } else {
   1.328 +// 	    b_node_newly_reached=false;
   1.329 +// 	  }
   1.330 +// 	}
   1.331 +//       } else {
   1.332 +// 	bfs_queue.pop(); 
   1.333 +// 	actual_edge=bfs_queue.front();
   1.334 +// 	if (actual_edge.valid()) {
   1.335 +// 	  Node w=G.bNode(actual_edge);
   1.336 +// 	  if (!reached.get(w)) {
   1.337 +// 	    bfs_queue.push(OutEdgeIt(G, w));
   1.338 +// 	    reached.set(w, true);
   1.339 +// 	    b_node_newly_reached=true;
   1.340 +// 	  } else {
   1.341 +// 	    b_node_newly_reached=false;
   1.342 +// 	  }
   1.343 +// 	}
   1.344 +//       }
   1.345 +//       //return *this;
   1.346 +//     }
   1.347 +//     bool finished() { return bfs_queue.empty(); }
   1.348 +//     operator OutEdgeIt () { return actual_edge; }
   1.349 +//     bool bNodeIsNewlyReached() { return b_node_newly_reached; }
   1.350 +//     bool aNodeIsExamined() { return !(actual_edge.valid()); }
   1.351 +//   };
   1.352 +
   1.353 +
   1.354 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   1.355 +//   struct DfsIterator1 {
   1.356 +//     typedef typename Graph::Node Node;
   1.357 +//     Graph& G;
   1.358 +//     std::stack<OutEdgeIt>& bfs_queue;
   1.359 +//     ReachedMap& reached;
   1.360 +//     bool b_node_newly_reached;
   1.361 +//     OutEdgeIt actual_edge;
   1.362 +//     DfsIterator1(Graph& _G, 
   1.363 +// 		std::stack<OutEdgeIt>& _bfs_queue, 
   1.364 +// 		ReachedMap& _reached) : 
   1.365 +//       G(_G), bfs_queue(_bfs_queue), reached(_reached) { 
   1.366 +//       //actual_edge=bfs_queue.top();
   1.367 +//       //if (actual_edge.valid()) { 
   1.368 +//       //	Node w=G.bNode(actual_edge);
   1.369 +//       //if (!reached.get(w)) {
   1.370 +//       //  bfs_queue.push(OutEdgeIt(G, w));
   1.371 +//       //  reached.set(w, true);
   1.372 +//       //  b_node_newly_reached=true;
   1.373 +//       //} else {
   1.374 +//       //  ++(bfs_queue.top());
   1.375 +//       //  b_node_newly_reached=false;
   1.376 +//       //}
   1.377 +//       //} else {
   1.378 +//       //	bfs_queue.pop();
   1.379 +//       //}
   1.380 +//     }
   1.381 +//     void next() { 
   1.382 +//       actual_edge=bfs_queue.top();
   1.383 +//       if (actual_edge.valid()) { 
   1.384 +// 	Node w=G.bNode(actual_edge);
   1.385 +// 	if (!reached.get(w)) {
   1.386 +// 	  bfs_queue.push(OutEdgeIt(G, w));
   1.387 +// 	  reached.set(w, true);
   1.388 +// 	  b_node_newly_reached=true;
   1.389 +// 	} else {
   1.390 +// 	  ++(bfs_queue.top());
   1.391 +// 	  b_node_newly_reached=false;
   1.392 +// 	}
   1.393 +//       } else {
   1.394 +// 	bfs_queue.pop();
   1.395 +//       }
   1.396 +//       //return *this;
   1.397 +//     }
   1.398 +//     bool finished() { return bfs_queue.empty(); }
   1.399 +//     operator OutEdgeIt () { return actual_edge; }
   1.400 +//     bool bNodeIsNewlyReached() { return b_node_newly_reached; }
   1.401 +//     bool aNodeIsLeaved() { return !(actual_edge.valid()); }
   1.402 +//   };
   1.403 +
   1.404 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   1.405 +//   class BfsIterator2 {
   1.406 +//     typedef typename Graph::Node Node;
   1.407 +//     const Graph& G;
   1.408 +//     std::queue<OutEdgeIt> bfs_queue;
   1.409 +//     ReachedMap reached;
   1.410 +//     bool b_node_newly_reached;
   1.411 +//     OutEdgeIt actual_edge;
   1.412 +//   public:
   1.413 +//     BfsIterator2(const Graph& _G) : G(_G), reached(G, false) { }
   1.414 +//     void pushAndSetReached(Node s) { 
   1.415 +//       reached.set(s, true);
   1.416 +//       if (bfs_queue.empty()) {
   1.417 +// 	bfs_queue.push(G.template first<OutEdgeIt>(s));
   1.418 +// 	actual_edge=bfs_queue.front();
   1.419 +// 	if (actual_edge.valid()) { 
   1.420 +// 	  Node w=G.bNode(actual_edge);
   1.421 +// 	  if (!reached.get(w)) {
   1.422 +// 	    bfs_queue.push(G.template first<OutEdgeIt>(w));
   1.423 +// 	    reached.set(w, true);
   1.424 +// 	    b_node_newly_reached=true;
   1.425 +// 	  } else {
   1.426 +// 	    b_node_newly_reached=false;
   1.427 +// 	  }
   1.428 +// 	} //else {
   1.429 +// 	//}
   1.430 +//       } else {
   1.431 +// 	bfs_queue.push(G.template first<OutEdgeIt>(s));
   1.432 +//       }
   1.433 +//     }
   1.434 +//     BfsIterator2<Graph, OutEdgeIt, ReachedMap>& 
   1.435 +//     operator++() { 
   1.436 +//       if (bfs_queue.front().valid()) { 
   1.437 +// 	++(bfs_queue.front());
   1.438 +// 	actual_edge=bfs_queue.front();
   1.439 +// 	if (actual_edge.valid()) {
   1.440 +// 	  Node w=G.bNode(actual_edge);
   1.441 +// 	  if (!reached.get(w)) {
   1.442 +// 	    bfs_queue.push(G.template first<OutEdgeIt>(w));
   1.443 +// 	    reached.set(w, true);
   1.444 +// 	    b_node_newly_reached=true;
   1.445 +// 	  } else {
   1.446 +// 	    b_node_newly_reached=false;
   1.447 +// 	  }
   1.448 +// 	}
   1.449 +//       } else {
   1.450 +// 	bfs_queue.pop(); 
   1.451 +// 	if (!bfs_queue.empty()) {
   1.452 +// 	  actual_edge=bfs_queue.front();
   1.453 +// 	  if (actual_edge.valid()) {
   1.454 +// 	    Node w=G.bNode(actual_edge);
   1.455 +// 	    if (!reached.get(w)) {
   1.456 +// 	      bfs_queue.push(G.template first<OutEdgeIt>(w));
   1.457 +// 	      reached.set(w, true);
   1.458 +// 	      b_node_newly_reached=true;
   1.459 +// 	    } else {
   1.460 +// 	      b_node_newly_reached=false;
   1.461 +// 	    }
   1.462 +// 	  }
   1.463 +// 	}
   1.464 +//       }
   1.465 +//       return *this;
   1.466 +//     }
   1.467 +//     bool finished() const { return bfs_queue.empty(); }
   1.468 +//     operator OutEdgeIt () const { return actual_edge; }
   1.469 +//     bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   1.470 +//     bool isANodeExamined() const { return !(actual_edge.valid()); }
   1.471 +//     const ReachedMap& getReachedMap() const { return reached; }
   1.472 +//     const std::queue<OutEdgeIt>& getBfsQueue() const { return bfs_queue; }
   1.473 +//  };
   1.474 +
   1.475 +
   1.476 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   1.477 +//   class BfsIterator3 {
   1.478 +//     typedef typename Graph::Node Node;
   1.479 +//     const Graph& G;
   1.480 +//     std::queue< std::pair<Node, OutEdgeIt> > bfs_queue;
   1.481 +//     ReachedMap reached;
   1.482 +//     bool b_node_newly_reached;
   1.483 +//     OutEdgeIt actual_edge;
   1.484 +//   public:
   1.485 +//     BfsIterator3(const Graph& _G) : G(_G), reached(G, false) { }
   1.486 +//     void pushAndSetReached(Node s) { 
   1.487 +//       reached.set(s, true);
   1.488 +//       if (bfs_queue.empty()) {
   1.489 +// 	bfs_queue.push(std::pair<Node, OutEdgeIt>(s, G.template first<OutEdgeIt>(s)));
   1.490 +// 	actual_edge=bfs_queue.front().second;
   1.491 +// 	if (actual_edge.valid()) { 
   1.492 +// 	  Node w=G.bNode(actual_edge);
   1.493 +// 	  if (!reached.get(w)) {
   1.494 +// 	    bfs_queue.push(std::pair<Node, OutEdgeIt>(w, G.template first<OutEdgeIt>(w)));
   1.495 +// 	    reached.set(w, true);
   1.496 +// 	    b_node_newly_reached=true;
   1.497 +// 	  } else {
   1.498 +// 	    b_node_newly_reached=false;
   1.499 +// 	  }
   1.500 +// 	} //else {
   1.501 +// 	//}
   1.502 +//       } else {
   1.503 +// 	bfs_queue.push(std::pair<Node, OutEdgeIt>(s, G.template first<OutEdgeIt>(s)));
   1.504 +//       }
   1.505 +//     }
   1.506 +//     BfsIterator3<Graph, OutEdgeIt, ReachedMap>& 
   1.507 +//     operator++() { 
   1.508 +//       if (bfs_queue.front().second.valid()) { 
   1.509 +// 	++(bfs_queue.front().second);
   1.510 +// 	actual_edge=bfs_queue.front().second;
   1.511 +// 	if (actual_edge.valid()) {
   1.512 +// 	  Node w=G.bNode(actual_edge);
   1.513 +// 	  if (!reached.get(w)) {
   1.514 +// 	    bfs_queue.push(std::pair<Node, OutEdgeIt>(w, G.template first<OutEdgeIt>(w)));
   1.515 +// 	    reached.set(w, true);
   1.516 +// 	    b_node_newly_reached=true;
   1.517 +// 	  } else {
   1.518 +// 	    b_node_newly_reached=false;
   1.519 +// 	  }
   1.520 +// 	}
   1.521 +//       } else {
   1.522 +// 	bfs_queue.pop(); 
   1.523 +// 	if (!bfs_queue.empty()) {
   1.524 +// 	  actual_edge=bfs_queue.front().second;
   1.525 +// 	  if (actual_edge.valid()) {
   1.526 +// 	    Node w=G.bNode(actual_edge);
   1.527 +// 	    if (!reached.get(w)) {
   1.528 +// 	      bfs_queue.push(std::pair<Node, OutEdgeIt>(w, G.template first<OutEdgeIt>(w)));
   1.529 +// 	      reached.set(w, true);
   1.530 +// 	      b_node_newly_reached=true;
   1.531 +// 	    } else {
   1.532 +// 	      b_node_newly_reached=false;
   1.533 +// 	    }
   1.534 +// 	  }
   1.535 +// 	}
   1.536 +//       }
   1.537 +//       return *this;
   1.538 +//     }
   1.539 +//     bool finished() const { return bfs_queue.empty(); }
   1.540 +//     operator OutEdgeIt () const { return actual_edge; }
   1.541 +//     bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   1.542 +//     bool isANodeExamined() const { return !(actual_edge.valid()); }
   1.543 +//     Node aNode() const { return bfs_queue.front().first; }
   1.544 +//     Node bNode() const { return G.bNode(actual_edge); }
   1.545 +//     const ReachedMap& getReachedMap() const { return reached; }
   1.546 +//     //const std::queue< std::pair<Node, OutEdgeIt> >& getBfsQueue() const { return bfs_queue; }
   1.547 +//  };
   1.548 +
   1.549 +
   1.550 +//   template <typename Graph, typename OutEdgeIt, 
   1.551 +// 	    typename ReachedMap/*=typename Graph::NodeMap<bool>*/ >
   1.552 +//   class BfsIterator4 {
   1.553 +//     typedef typename Graph::Node Node;
   1.554 +//     const Graph& G;
   1.555 +//     std::queue<Node> bfs_queue;
   1.556 +//     ReachedMap& reached;
   1.557 +//     bool b_node_newly_reached;
   1.558 +//     OutEdgeIt actual_edge;
   1.559 +//     bool own_reached_map;
   1.560 +//   public:
   1.561 +//     BfsIterator4(const Graph& _G, ReachedMap& _reached) : 
   1.562 +//       G(_G), reached(_reached), 
   1.563 +//       own_reached_map(false) { }
   1.564 +//     BfsIterator4(const Graph& _G) : 
   1.565 +//       G(_G), reached(*(new ReachedMap(G /*, false*/))), 
   1.566 +//       own_reached_map(true) { }
   1.567 +//     ~BfsIterator4() { if (own_reached_map) delete &reached; }
   1.568 +//     void pushAndSetReached(Node s) { 
   1.569 +//       //std::cout << "mimi" << &reached << std::endl;
   1.570 +//       reached.set(s, true);
   1.571 +//       //std::cout << "mumus" << std::endl;
   1.572 +//       if (bfs_queue.empty()) {
   1.573 +// 	//std::cout << "bibi1" << std::endl;
   1.574 +// 	bfs_queue.push(s);
   1.575 +// 	//std::cout << "zizi" << std::endl;
   1.576 +// 	G./*getF*/first(actual_edge, s);
   1.577 +// 	//std::cout << "kiki" << std::endl;
   1.578 +// 	if (G.valid(actual_edge)/*.valid()*/) { 
   1.579 +// 	  Node w=G.bNode(actual_edge);
   1.580 +// 	  if (!reached.get(w)) {
   1.581 +// 	    bfs_queue.push(w);
   1.582 +// 	    reached.set(w, true);
   1.583 +// 	    b_node_newly_reached=true;
   1.584 +// 	  } else {
   1.585 +// 	    b_node_newly_reached=false;
   1.586 +// 	  }
   1.587 +// 	} 
   1.588 +//       } else {
   1.589 +// 	//std::cout << "bibi2" << std::endl;
   1.590 +// 	bfs_queue.push(s);
   1.591 +//       }
   1.592 +//     }
   1.593 +//     BfsIterator4<Graph, OutEdgeIt, ReachedMap>& 
   1.594 +//     operator++() { 
   1.595 +//       if (G.valid(actual_edge)/*.valid()*/) { 
   1.596 +// 	/*++*/G.next(actual_edge);
   1.597 +// 	if (G.valid(actual_edge)/*.valid()*/) {
   1.598 +// 	  Node w=G.bNode(actual_edge);
   1.599 +// 	  if (!reached.get(w)) {
   1.600 +// 	    bfs_queue.push(w);
   1.601 +// 	    reached.set(w, true);
   1.602 +// 	    b_node_newly_reached=true;
   1.603 +// 	  } else {
   1.604 +// 	    b_node_newly_reached=false;
   1.605 +// 	  }
   1.606 +// 	}
   1.607 +//       } else {
   1.608 +// 	bfs_queue.pop(); 
   1.609 +// 	if (!bfs_queue.empty()) {
   1.610 +// 	  G./*getF*/first(actual_edge, bfs_queue.front());
   1.611 +// 	  if (G.valid(actual_edge)/*.valid()*/) {
   1.612 +// 	    Node w=G.bNode(actual_edge);
   1.613 +// 	    if (!reached.get(w)) {
   1.614 +// 	      bfs_queue.push(w);
   1.615 +// 	      reached.set(w, true);
   1.616 +// 	      b_node_newly_reached=true;
   1.617 +// 	    } else {
   1.618 +// 	      b_node_newly_reached=false;
   1.619 +// 	    }
   1.620 +// 	  }
   1.621 +// 	}
   1.622 +//       }
   1.623 +//       return *this;
   1.624 +//     }
   1.625 +//     bool finished() const { return bfs_queue.empty(); }
   1.626 +//     operator OutEdgeIt () const { return actual_edge; }
   1.627 +//     bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   1.628 +//     bool isANodeExamined() const { return !(G.valid(actual_edge)/*.valid()*/); }
   1.629 +//     Node aNode() const { return bfs_queue.front(); }
   1.630 +//     Node bNode() const { return G.bNode(actual_edge); }
   1.631 +//     const ReachedMap& getReachedMap() const { return reached; }
   1.632 +//     const std::queue<Node>& getBfsQueue() const { return bfs_queue; }
   1.633 +//  };  
   1.634 +
   1.635 +
   1.636 +  template <typename GraphWrapper, /*typename OutEdgeIt,*/ 
   1.637 +	    typename ReachedMap/*=typename GraphWrapper::NodeMap<bool>*/ >
   1.638 +  class BfsIterator5 {
   1.639 +    typedef typename GraphWrapper::Node Node;
   1.640 +    typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
   1.641 +    GraphWrapper G;
   1.642 +    std::queue<Node> bfs_queue;
   1.643 +    ReachedMap& reached;
   1.644 +    bool b_node_newly_reached;
   1.645 +    OutEdgeIt actual_edge;
   1.646 +    bool own_reached_map;
   1.647 +  public:
   1.648 +    BfsIterator5(const GraphWrapper& _G, ReachedMap& _reached) : 
   1.649 +      G(_G), reached(_reached), 
   1.650 +      own_reached_map(false) { }
   1.651 +    BfsIterator5(const GraphWrapper& _G) : 
   1.652 +      G(_G), reached(*(new ReachedMap(G /*, false*/))), 
   1.653 +      own_reached_map(true) { }
   1.654 +//     BfsIterator5(const typename GraphWrapper::BaseGraph& _G, 
   1.655 +// 		 ReachedMap& _reached) : 
   1.656 +//       G(_G), reached(_reached), 
   1.657 +//       own_reached_map(false) { }
   1.658 +//     BfsIterator5(const typename GraphWrapper::BaseGraph& _G) : 
   1.659 +//       G(_G), reached(*(new ReachedMap(G /*, false*/))), 
   1.660 +//       own_reached_map(true) { }
   1.661 +    ~BfsIterator5() { if (own_reached_map) delete &reached; }
   1.662 +    void pushAndSetReached(Node s) { 
   1.663 +      reached.set(s, true);
   1.664 +      if (bfs_queue.empty()) {
   1.665 +	bfs_queue.push(s);
   1.666 +	G./*getF*/first(actual_edge, s);
   1.667 +	if (G.valid(actual_edge)/*.valid()*/) { 
   1.668 +	  Node w=G.bNode(actual_edge);
   1.669 +	  if (!reached.get(w)) {
   1.670 +	    bfs_queue.push(w);
   1.671 +	    reached.set(w, true);
   1.672 +	    b_node_newly_reached=true;
   1.673 +	  } else {
   1.674 +	    b_node_newly_reached=false;
   1.675 +	  }
   1.676 +	} 
   1.677 +      } else {
   1.678 +	bfs_queue.push(s);
   1.679 +      }
   1.680 +    }
   1.681 +    BfsIterator5<GraphWrapper, /*OutEdgeIt,*/ ReachedMap>& 
   1.682 +    operator++() { 
   1.683 +      if (G.valid(actual_edge)/*.valid()*/) { 
   1.684 +	/*++*/G.next(actual_edge);
   1.685 +	if (G.valid(actual_edge)/*.valid()*/) {
   1.686 +	  Node w=G.bNode(actual_edge);
   1.687 +	  if (!reached.get(w)) {
   1.688 +	    bfs_queue.push(w);
   1.689 +	    reached.set(w, true);
   1.690 +	    b_node_newly_reached=true;
   1.691 +	  } else {
   1.692 +	    b_node_newly_reached=false;
   1.693 +	  }
   1.694 +	}
   1.695 +      } else {
   1.696 +	bfs_queue.pop(); 
   1.697 +	if (!bfs_queue.empty()) {
   1.698 +	  G./*getF*/first(actual_edge, bfs_queue.front());
   1.699 +	  if (G.valid(actual_edge)/*.valid()*/) {
   1.700 +	    Node w=G.bNode(actual_edge);
   1.701 +	    if (!reached.get(w)) {
   1.702 +	      bfs_queue.push(w);
   1.703 +	      reached.set(w, true);
   1.704 +	      b_node_newly_reached=true;
   1.705 +	    } else {
   1.706 +	      b_node_newly_reached=false;
   1.707 +	    }
   1.708 +	  }
   1.709 +	}
   1.710 +      }
   1.711 +      return *this;
   1.712 +    }
   1.713 +    bool finished() const { return bfs_queue.empty(); }
   1.714 +    operator OutEdgeIt () const { return actual_edge; }
   1.715 +    bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   1.716 +    bool isANodeExamined() const { return !(G.valid(actual_edge)/*.valid()*/); }
   1.717 +    Node aNode() const { return bfs_queue.front(); }
   1.718 +    Node bNode() const { return G.bNode(actual_edge); }
   1.719 +    const ReachedMap& getReachedMap() const { return reached; }
   1.720 +    const std::queue<Node>& getBfsQueue() const { return bfs_queue; }
   1.721 +  };  
   1.722 +
   1.723 +//   template <typename Graph, typename OutEdgeIt, 
   1.724 +// 	    typename ReachedMap/*=typename Graph::NodeMap<bool>*/ >
   1.725 +//   class DfsIterator4 {
   1.726 +//     typedef typename Graph::Node Node;
   1.727 +//     const Graph& G;
   1.728 +//     std::stack<OutEdgeIt> dfs_stack;
   1.729 +//     bool b_node_newly_reached;
   1.730 +//     OutEdgeIt actual_edge;
   1.731 +//     Node actual_node;
   1.732 +//     ReachedMap& reached;
   1.733 +//     bool own_reached_map;
   1.734 +//   public:
   1.735 +//     DfsIterator4(const Graph& _G, ReachedMap& _reached) : 
   1.736 +//       G(_G), reached(_reached), 
   1.737 +//       own_reached_map(false) { }
   1.738 +//     DfsIterator4(const Graph& _G) : 
   1.739 +//       G(_G), reached(*(new ReachedMap(G /*, false*/))), 
   1.740 +//       own_reached_map(true) { }
   1.741 +//     ~DfsIterator4() { if (own_reached_map) delete &reached; }
   1.742 +//     void pushAndSetReached(Node s) { 
   1.743 +//       actual_node=s;
   1.744 +//       reached.set(s, true);
   1.745 +//       dfs_stack.push(G.template first<OutEdgeIt>(s)); 
   1.746 +//     }
   1.747 +//     DfsIterator4<Graph, OutEdgeIt, ReachedMap>& 
   1.748 +//     operator++() { 
   1.749 +//       actual_edge=dfs_stack.top();
   1.750 +//       //actual_node=G.aNode(actual_edge);
   1.751 +//       if (G.valid(actual_edge)/*.valid()*/) { 
   1.752 +// 	Node w=G.bNode(actual_edge);
   1.753 +// 	actual_node=w;
   1.754 +// 	if (!reached.get(w)) {
   1.755 +// 	  dfs_stack.push(G.template first<OutEdgeIt>(w));
   1.756 +// 	  reached.set(w, true);
   1.757 +// 	  b_node_newly_reached=true;
   1.758 +// 	} else {
   1.759 +// 	  actual_node=G.aNode(actual_edge);
   1.760 +// 	  /*++*/G.next(dfs_stack.top());
   1.761 +// 	  b_node_newly_reached=false;
   1.762 +// 	}
   1.763 +//       } else {
   1.764 +// 	//actual_node=G.aNode(dfs_stack.top());
   1.765 +// 	dfs_stack.pop();
   1.766 +//       }
   1.767 +//       return *this;
   1.768 +//     }
   1.769 +//     bool finished() const { return dfs_stack.empty(); }
   1.770 +//     operator OutEdgeIt () const { return actual_edge; }
   1.771 +//     bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   1.772 +//     bool isANodeExamined() const { return !(G.valid(actual_edge)/*.valid()*/); }
   1.773 +//     Node aNode() const { return actual_node; /*FIXME*/}
   1.774 +//     Node bNode() const { return G.bNode(actual_edge); }
   1.775 +//     const ReachedMap& getReachedMap() const { return reached; }
   1.776 +//     const std::stack<OutEdgeIt>& getDfsStack() const { return dfs_stack; }
   1.777 +//   };
   1.778 +
   1.779 +  template <typename GraphWrapper, /*typename OutEdgeIt,*/ 
   1.780 +	    typename ReachedMap/*=typename GraphWrapper::NodeMap<bool>*/ >
   1.781 +  class DfsIterator5 {
   1.782 +    typedef typename GraphWrapper::Node Node;
   1.783 +    typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
   1.784 +    GraphWrapper G;
   1.785 +    std::stack<OutEdgeIt> dfs_stack;
   1.786 +    bool b_node_newly_reached;
   1.787 +    OutEdgeIt actual_edge;
   1.788 +    Node actual_node;
   1.789 +    ReachedMap& reached;
   1.790 +    bool own_reached_map;
   1.791 +  public:
   1.792 +    DfsIterator5(const GraphWrapper& _G, ReachedMap& _reached) : 
   1.793 +      G(_G), reached(_reached), 
   1.794 +      own_reached_map(false) { }
   1.795 +    DfsIterator5(const GraphWrapper& _G) : 
   1.796 +      G(_G), reached(*(new ReachedMap(G /*, false*/))), 
   1.797 +      own_reached_map(true) { }
   1.798 +    ~DfsIterator5() { if (own_reached_map) delete &reached; }
   1.799 +    void pushAndSetReached(Node s) { 
   1.800 +      actual_node=s;
   1.801 +      reached.set(s, true);
   1.802 +      OutEdgeIt e;
   1.803 +      G.first(e, s);
   1.804 +      dfs_stack.push(e); 
   1.805 +    }
   1.806 +    DfsIterator5<GraphWrapper, /*OutEdgeIt,*/ ReachedMap>& 
   1.807 +    operator++() { 
   1.808 +      actual_edge=dfs_stack.top();
   1.809 +      //actual_node=G.aNode(actual_edge);
   1.810 +      if (G.valid(actual_edge)/*.valid()*/) { 
   1.811 +	Node w=G.bNode(actual_edge);
   1.812 +	actual_node=w;
   1.813 +	if (!reached.get(w)) {
   1.814 +	  OutEdgeIt e;
   1.815 +	  G.first(e, w);
   1.816 +	  dfs_stack.push(e);
   1.817 +	  reached.set(w, true);
   1.818 +	  b_node_newly_reached=true;
   1.819 +	} else {
   1.820 +	  actual_node=G.aNode(actual_edge);
   1.821 +	  /*++*/G.next(dfs_stack.top());
   1.822 +	  b_node_newly_reached=false;
   1.823 +	}
   1.824 +      } else {
   1.825 +	//actual_node=G.aNode(dfs_stack.top());
   1.826 +	dfs_stack.pop();
   1.827 +      }
   1.828 +      return *this;
   1.829 +    }
   1.830 +    bool finished() const { return dfs_stack.empty(); }
   1.831 +    operator OutEdgeIt () const { return actual_edge; }
   1.832 +    bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   1.833 +    bool isANodeExamined() const { return !(G.valid(actual_edge)/*.valid()*/); }
   1.834 +    Node aNode() const { return actual_node; /*FIXME*/}
   1.835 +    Node bNode() const { return G.bNode(actual_edge); }
   1.836 +    const ReachedMap& getReachedMap() const { return reached; }
   1.837 +    const std::stack<OutEdgeIt>& getDfsStack() const { return dfs_stack; }
   1.838 +  };
   1.839 +
   1.840 +
   1.841 +
   1.842 +} // namespace hugo
   1.843 +
   1.844 +#endif //HUGO_BFS_ITERATOR_H
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/work/marci/experiment/bfs_iterator_1.h	Sat Apr 03 17:26:46 2004 +0000
     2.3 @@ -0,0 +1,841 @@
     2.4 +// -*- c++ -*-
     2.5 +#ifndef HUGO_BFS_ITERATOR_H
     2.6 +#define HUGO_BFS_ITERATOR_H
     2.7 +
     2.8 +#include <queue>
     2.9 +#include <stack>
    2.10 +#include <utility>
    2.11 +#include <graph_wrapper_1.h>
    2.12 +
    2.13 +namespace hugo {
    2.14 +
    2.15 +//   template <typename Graph>
    2.16 +//   struct bfs {
    2.17 +//     typedef typename Graph::Node Node;
    2.18 +//     typedef typename Graph::Edge Edge;
    2.19 +//     typedef typename Graph::NodeIt NodeIt;
    2.20 +//     typedef typename Graph::OutEdgeIt OutEdgeIt;
    2.21 +//     Graph& G;
    2.22 +//     Node s;
    2.23 +//     typename Graph::NodeMap<bool> reached;
    2.24 +//     typename Graph::NodeMap<Edge> pred;
    2.25 +//     typename Graph::NodeMap<int> dist;
    2.26 +//     std::queue<Node> bfs_queue;
    2.27 +//     bfs(Graph& _G, Node _s) : G(_G), s(_s), reached(_G), pred(_G), dist(_G) { 
    2.28 +//       bfs_queue.push(s); 
    2.29 +//       for(NodeIt i=G.template first<NodeIt>(); i.valid(); ++i) 
    2.30 +// 	reached.set(i, false);
    2.31 +//       reached.set(s, true);
    2.32 +//       dist.set(s, 0); 
    2.33 +//     }
    2.34 +    
    2.35 +//     void run() {
    2.36 +//       while (!bfs_queue.empty()) {
    2.37 +// 	Node v=bfs_queue.front();
    2.38 +// 	OutEdgeIt e=G.template first<OutEdgeIt>(v);
    2.39 +// 	bfs_queue.pop();
    2.40 +// 	for( ; e.valid(); ++e) {
    2.41 +// 	  Node w=G.bNode(e);
    2.42 +// 	  std::cout << "scan node " << G.id(w) << " from node " << G.id(v) << std::endl;
    2.43 +// 	  if (!reached.get(w)) {
    2.44 +// 	    std::cout << G.id(w) << " is newly reached :-)" << std::endl;
    2.45 +// 	    bfs_queue.push(w);
    2.46 +// 	    dist.set(w, dist.get(v)+1);
    2.47 +// 	    pred.set(w, e);
    2.48 +// 	    reached.set(w, true);
    2.49 +// 	  } else {
    2.50 +// 	    std::cout << G.id(w) << " is already reached" << std::endl;
    2.51 +// 	  }
    2.52 +// 	}
    2.53 +//       }
    2.54 +//     }
    2.55 +//   };
    2.56 +
    2.57 +//   template <typename Graph> 
    2.58 +//   struct bfs_visitor {
    2.59 +//     typedef typename Graph::Node Node;
    2.60 +//     typedef typename Graph::Edge Edge;
    2.61 +//     typedef typename Graph::OutEdgeIt OutEdgeIt;
    2.62 +//     Graph& G;
    2.63 +//     bfs_visitor(Graph& _G) : G(_G) { }
    2.64 +//     void at_previously_reached(OutEdgeIt& e) { 
    2.65 +//       //Node v=G.aNode(e);
    2.66 +//       Node w=G.bNode(e);
    2.67 +//       std::cout << G.id(w) << " is already reached" << std::endl;
    2.68 +//    }
    2.69 +//     void at_newly_reached(OutEdgeIt& e) { 
    2.70 +//       //Node v=G.aNode(e);
    2.71 +//       Node w=G.bNode(e);
    2.72 +//       std::cout << G.id(w) << " is newly reached :-)" << std::endl;
    2.73 +//     }
    2.74 +//   };
    2.75 +
    2.76 +//   template <typename Graph, typename ReachedMap, typename visitor_type>
    2.77 +//   struct bfs_iterator {
    2.78 +//     typedef typename Graph::Node Node;
    2.79 +//     typedef typename Graph::Edge Edge;
    2.80 +//     typedef typename Graph::OutEdgeIt OutEdgeIt;
    2.81 +//     Graph& G;
    2.82 +//     std::queue<OutEdgeIt>& bfs_queue;
    2.83 +//     ReachedMap& reached;
    2.84 +//     visitor_type& visitor;
    2.85 +//     void process() {
    2.86 +//       while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
    2.87 +//       if (bfs_queue.empty()) return;
    2.88 +//       OutEdgeIt e=bfs_queue.front();
    2.89 +//       //Node v=G.aNode(e);
    2.90 +//       Node w=G.bNode(e);
    2.91 +//       if (!reached.get(w)) {
    2.92 +// 	visitor.at_newly_reached(e);
    2.93 +// 	bfs_queue.push(G.template first<OutEdgeIt>(w));
    2.94 +// 	reached.set(w, true);
    2.95 +//       } else {
    2.96 +// 	visitor.at_previously_reached(e);
    2.97 +//       }
    2.98 +//     }
    2.99 +//     bfs_iterator(Graph& _G, std::queue<OutEdgeIt>& _bfs_queue, ReachedMap& _reached, visitor_type& _visitor) : G(_G), bfs_queue(_bfs_queue), reached(_reached), visitor(_visitor) { 
   2.100 +//       //while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   2.101 +//       valid();
   2.102 +//     }
   2.103 +//     bfs_iterator<Graph, ReachedMap, visitor_type>& operator++() { 
   2.104 +//       //while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   2.105 +//       //if (bfs_queue.empty()) return *this;
   2.106 +//       if (!valid()) return *this;
   2.107 +//       ++(bfs_queue.front());
   2.108 +//       //while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   2.109 +//       valid();
   2.110 +//       return *this;
   2.111 +//     }
   2.112 +//     //void next() { 
   2.113 +//     //  while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   2.114 +//     //  if (bfs_queue.empty()) return;
   2.115 +//     //  ++(bfs_queue.front());
   2.116 +//     //  while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   2.117 +//     //}
   2.118 +//     bool valid() { 
   2.119 +//       while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   2.120 +//       if (bfs_queue.empty()) return false; else return true;
   2.121 +//     }
   2.122 +//     //bool finished() { 
   2.123 +//     //  while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   2.124 +//     //  if (bfs_queue.empty()) return true; else return false;
   2.125 +//     //}
   2.126 +//     operator Edge () { return bfs_queue.front(); }
   2.127 +
   2.128 +//   };
   2.129 +
   2.130 +//   template <typename Graph, typename ReachedMap>
   2.131 +//   struct bfs_iterator1 {
   2.132 +//     typedef typename Graph::Node Node;
   2.133 +//     typedef typename Graph::Edge Edge;
   2.134 +//     typedef typename Graph::OutEdgeIt OutEdgeIt;
   2.135 +//     Graph& G;
   2.136 +//     std::queue<OutEdgeIt>& bfs_queue;
   2.137 +//     ReachedMap& reached;
   2.138 +//     bool _newly_reached;
   2.139 +//     bfs_iterator1(Graph& _G, std::queue<OutEdgeIt>& _bfs_queue, ReachedMap& _reached) : G(_G), bfs_queue(_bfs_queue), reached(_reached) { 
   2.140 +//       valid();
   2.141 +//       if (!bfs_queue.empty() && bfs_queue.front().valid()) { 
   2.142 +// 	OutEdgeIt e=bfs_queue.front();
   2.143 +// 	Node w=G.bNode(e);
   2.144 +// 	if (!reached.get(w)) {
   2.145 +// 	  bfs_queue.push(G.template first<OutEdgeIt>(w));
   2.146 +// 	  reached.set(w, true);
   2.147 +// 	  _newly_reached=true;
   2.148 +// 	} else {
   2.149 +// 	  _newly_reached=false;
   2.150 +// 	}
   2.151 +//       }
   2.152 +//     }
   2.153 +//     bfs_iterator1<Graph, ReachedMap>& operator++() { 
   2.154 +//       if (!valid()) return *this;
   2.155 +//       ++(bfs_queue.front());
   2.156 +//       valid();
   2.157 +//       if (!bfs_queue.empty() && bfs_queue.front().valid()) { 
   2.158 +// 	OutEdgeIt e=bfs_queue.front();
   2.159 +// 	Node w=G.bNode(e);
   2.160 +// 	if (!reached.get(w)) {
   2.161 +// 	  bfs_queue.push(G.template first<OutEdgeIt>(w));
   2.162 +// 	  reached.set(w, true);
   2.163 +// 	  _newly_reached=true;
   2.164 +// 	} else {
   2.165 +// 	  _newly_reached=false;
   2.166 +// 	}
   2.167 +//       }
   2.168 +//       return *this;
   2.169 +//     }
   2.170 +//     bool valid() { 
   2.171 +//       while ( !bfs_queue.empty() && !bfs_queue.front().valid() ) { bfs_queue.pop(); } 
   2.172 +//       if (bfs_queue.empty()) return false; else return true;
   2.173 +//     }
   2.174 +//     operator OutEdgeIt() { return bfs_queue.front(); }
   2.175 +//     //ize
   2.176 +//     bool newly_reached() { return _newly_reached; }
   2.177 +
   2.178 +//   };
   2.179 +
   2.180 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   2.181 +//   struct BfsIterator {
   2.182 +//     typedef typename Graph::Node Node;
   2.183 +//     Graph& G;
   2.184 +//     std::queue<OutEdgeIt>& bfs_queue;
   2.185 +//     ReachedMap& reached;
   2.186 +//     bool b_node_newly_reached;
   2.187 +//     OutEdgeIt actual_edge;
   2.188 +//     BfsIterator(Graph& _G, 
   2.189 +// 		std::queue<OutEdgeIt>& _bfs_queue, 
   2.190 +// 		ReachedMap& _reached) : 
   2.191 +//       G(_G), bfs_queue(_bfs_queue), reached(_reached) { 
   2.192 +//       actual_edge=bfs_queue.front();
   2.193 +//       if (actual_edge.valid()) { 
   2.194 +// 	Node w=G.bNode(actual_edge);
   2.195 +// 	if (!reached.get(w)) {
   2.196 +// 	  bfs_queue.push(G.firstOutEdge(w));
   2.197 +// 	  reached.set(w, true);
   2.198 +// 	  b_node_newly_reached=true;
   2.199 +// 	} else {
   2.200 +// 	  b_node_newly_reached=false;
   2.201 +// 	}
   2.202 +//       }
   2.203 +//     }
   2.204 +//     BfsIterator<Graph, OutEdgeIt, ReachedMap>& 
   2.205 +//     operator++() { 
   2.206 +//       if (bfs_queue.front().valid()) { 
   2.207 +// 	++(bfs_queue.front());
   2.208 +// 	actual_edge=bfs_queue.front();
   2.209 +// 	if (actual_edge.valid()) {
   2.210 +// 	  Node w=G.bNode(actual_edge);
   2.211 +// 	  if (!reached.get(w)) {
   2.212 +// 	    bfs_queue.push(G.firstOutEdge(w));
   2.213 +// 	    reached.set(w, true);
   2.214 +// 	    b_node_newly_reached=true;
   2.215 +// 	  } else {
   2.216 +// 	    b_node_newly_reached=false;
   2.217 +// 	  }
   2.218 +// 	}
   2.219 +//       } else {
   2.220 +// 	bfs_queue.pop(); 
   2.221 +// 	actual_edge=bfs_queue.front();
   2.222 +// 	if (actual_edge.valid()) {
   2.223 +// 	  Node w=G.bNode(actual_edge);
   2.224 +// 	  if (!reached.get(w)) {
   2.225 +// 	    bfs_queue.push(G.firstOutEdge(w));
   2.226 +// 	    reached.set(w, true);
   2.227 +// 	    b_node_newly_reached=true;
   2.228 +// 	  } else {
   2.229 +// 	    b_node_newly_reached=false;
   2.230 +// 	  }
   2.231 +// 	}
   2.232 +//       }
   2.233 +//       return *this;
   2.234 +//     }
   2.235 +//     bool finished() { return bfs_queue.empty(); }
   2.236 +//     operator OutEdgeIt () { return actual_edge; }
   2.237 +//     bool bNodeIsNewlyReached() { return b_node_newly_reached; }
   2.238 +//     bool aNodeIsExamined() { return !(actual_edge.valid()); }
   2.239 +//   };
   2.240 +
   2.241 +
   2.242 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   2.243 +//   struct DfsIterator {
   2.244 +//     typedef typename Graph::Node Node;
   2.245 +//     Graph& G;
   2.246 +//     std::stack<OutEdgeIt>& bfs_queue;
   2.247 +//     ReachedMap& reached;
   2.248 +//     bool b_node_newly_reached;
   2.249 +//     OutEdgeIt actual_edge;
   2.250 +//     DfsIterator(Graph& _G, 
   2.251 +// 		std::stack<OutEdgeIt>& _bfs_queue, 
   2.252 +// 		ReachedMap& _reached) : 
   2.253 +//       G(_G), bfs_queue(_bfs_queue), reached(_reached) { 
   2.254 +//       actual_edge=bfs_queue.top();
   2.255 +//       if (actual_edge.valid()) { 
   2.256 +// 	Node w=G.bNode(actual_edge);
   2.257 +// 	if (!reached.get(w)) {
   2.258 +// 	  bfs_queue.push(G.firstOutEdge(w));
   2.259 +// 	  reached.set(w, true);
   2.260 +// 	  b_node_newly_reached=true;
   2.261 +// 	} else {
   2.262 +// 	  ++(bfs_queue.top());
   2.263 +// 	  b_node_newly_reached=false;
   2.264 +// 	}
   2.265 +//       } else {
   2.266 +// 	bfs_queue.pop();
   2.267 +//       }
   2.268 +//     }
   2.269 +//     DfsIterator<Graph, OutEdgeIt, ReachedMap>& 
   2.270 +//     operator++() { 
   2.271 +//       actual_edge=bfs_queue.top();
   2.272 +//       if (actual_edge.valid()) { 
   2.273 +// 	Node w=G.bNode(actual_edge);
   2.274 +// 	if (!reached.get(w)) {
   2.275 +// 	  bfs_queue.push(G.firstOutEdge(w));
   2.276 +// 	  reached.set(w, true);
   2.277 +// 	  b_node_newly_reached=true;
   2.278 +// 	} else {
   2.279 +// 	  ++(bfs_queue.top());
   2.280 +// 	  b_node_newly_reached=false;
   2.281 +// 	}
   2.282 +//       } else {
   2.283 +// 	bfs_queue.pop();
   2.284 +//       }
   2.285 +//       return *this;
   2.286 +//     }
   2.287 +//     bool finished() { return bfs_queue.empty(); }
   2.288 +//     operator OutEdgeIt () { return actual_edge; }
   2.289 +//     bool bNodeIsNewlyReached() { return b_node_newly_reached; }
   2.290 +//     bool aNodeIsExamined() { return !(actual_edge.valid()); }
   2.291 +//   };
   2.292 +
   2.293 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   2.294 +//   struct BfsIterator1 {
   2.295 +//     typedef typename Graph::Node Node;
   2.296 +//     Graph& G;
   2.297 +//     std::queue<OutEdgeIt>& bfs_queue;
   2.298 +//     ReachedMap& reached;
   2.299 +//     bool b_node_newly_reached;
   2.300 +//     OutEdgeIt actual_edge;
   2.301 +//     BfsIterator1(Graph& _G, 
   2.302 +// 		std::queue<OutEdgeIt>& _bfs_queue, 
   2.303 +// 		ReachedMap& _reached) : 
   2.304 +//       G(_G), bfs_queue(_bfs_queue), reached(_reached) { 
   2.305 +//       actual_edge=bfs_queue.front();
   2.306 +//       if (actual_edge.valid()) { 
   2.307 +//       	Node w=G.bNode(actual_edge);
   2.308 +// 	if (!reached.get(w)) {
   2.309 +// 	  bfs_queue.push(OutEdgeIt(G, w));
   2.310 +// 	  reached.set(w, true);
   2.311 +// 	  b_node_newly_reached=true;
   2.312 +// 	} else {
   2.313 +// 	  b_node_newly_reached=false;
   2.314 +// 	}
   2.315 +//       }
   2.316 +//     }
   2.317 +//     void next() { 
   2.318 +//       if (bfs_queue.front().valid()) { 
   2.319 +// 	++(bfs_queue.front());
   2.320 +// 	actual_edge=bfs_queue.front();
   2.321 +// 	if (actual_edge.valid()) {
   2.322 +// 	  Node w=G.bNode(actual_edge);
   2.323 +// 	  if (!reached.get(w)) {
   2.324 +// 	    bfs_queue.push(OutEdgeIt(G, w));
   2.325 +// 	    reached.set(w, true);
   2.326 +// 	    b_node_newly_reached=true;
   2.327 +// 	  } else {
   2.328 +// 	    b_node_newly_reached=false;
   2.329 +// 	  }
   2.330 +// 	}
   2.331 +//       } else {
   2.332 +// 	bfs_queue.pop(); 
   2.333 +// 	actual_edge=bfs_queue.front();
   2.334 +// 	if (actual_edge.valid()) {
   2.335 +// 	  Node w=G.bNode(actual_edge);
   2.336 +// 	  if (!reached.get(w)) {
   2.337 +// 	    bfs_queue.push(OutEdgeIt(G, w));
   2.338 +// 	    reached.set(w, true);
   2.339 +// 	    b_node_newly_reached=true;
   2.340 +// 	  } else {
   2.341 +// 	    b_node_newly_reached=false;
   2.342 +// 	  }
   2.343 +// 	}
   2.344 +//       }
   2.345 +//       //return *this;
   2.346 +//     }
   2.347 +//     bool finished() { return bfs_queue.empty(); }
   2.348 +//     operator OutEdgeIt () { return actual_edge; }
   2.349 +//     bool bNodeIsNewlyReached() { return b_node_newly_reached; }
   2.350 +//     bool aNodeIsExamined() { return !(actual_edge.valid()); }
   2.351 +//   };
   2.352 +
   2.353 +
   2.354 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   2.355 +//   struct DfsIterator1 {
   2.356 +//     typedef typename Graph::Node Node;
   2.357 +//     Graph& G;
   2.358 +//     std::stack<OutEdgeIt>& bfs_queue;
   2.359 +//     ReachedMap& reached;
   2.360 +//     bool b_node_newly_reached;
   2.361 +//     OutEdgeIt actual_edge;
   2.362 +//     DfsIterator1(Graph& _G, 
   2.363 +// 		std::stack<OutEdgeIt>& _bfs_queue, 
   2.364 +// 		ReachedMap& _reached) : 
   2.365 +//       G(_G), bfs_queue(_bfs_queue), reached(_reached) { 
   2.366 +//       //actual_edge=bfs_queue.top();
   2.367 +//       //if (actual_edge.valid()) { 
   2.368 +//       //	Node w=G.bNode(actual_edge);
   2.369 +//       //if (!reached.get(w)) {
   2.370 +//       //  bfs_queue.push(OutEdgeIt(G, w));
   2.371 +//       //  reached.set(w, true);
   2.372 +//       //  b_node_newly_reached=true;
   2.373 +//       //} else {
   2.374 +//       //  ++(bfs_queue.top());
   2.375 +//       //  b_node_newly_reached=false;
   2.376 +//       //}
   2.377 +//       //} else {
   2.378 +//       //	bfs_queue.pop();
   2.379 +//       //}
   2.380 +//     }
   2.381 +//     void next() { 
   2.382 +//       actual_edge=bfs_queue.top();
   2.383 +//       if (actual_edge.valid()) { 
   2.384 +// 	Node w=G.bNode(actual_edge);
   2.385 +// 	if (!reached.get(w)) {
   2.386 +// 	  bfs_queue.push(OutEdgeIt(G, w));
   2.387 +// 	  reached.set(w, true);
   2.388 +// 	  b_node_newly_reached=true;
   2.389 +// 	} else {
   2.390 +// 	  ++(bfs_queue.top());
   2.391 +// 	  b_node_newly_reached=false;
   2.392 +// 	}
   2.393 +//       } else {
   2.394 +// 	bfs_queue.pop();
   2.395 +//       }
   2.396 +//       //return *this;
   2.397 +//     }
   2.398 +//     bool finished() { return bfs_queue.empty(); }
   2.399 +//     operator OutEdgeIt () { return actual_edge; }
   2.400 +//     bool bNodeIsNewlyReached() { return b_node_newly_reached; }
   2.401 +//     bool aNodeIsLeaved() { return !(actual_edge.valid()); }
   2.402 +//   };
   2.403 +
   2.404 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   2.405 +//   class BfsIterator2 {
   2.406 +//     typedef typename Graph::Node Node;
   2.407 +//     const Graph& G;
   2.408 +//     std::queue<OutEdgeIt> bfs_queue;
   2.409 +//     ReachedMap reached;
   2.410 +//     bool b_node_newly_reached;
   2.411 +//     OutEdgeIt actual_edge;
   2.412 +//   public:
   2.413 +//     BfsIterator2(const Graph& _G) : G(_G), reached(G, false) { }
   2.414 +//     void pushAndSetReached(Node s) { 
   2.415 +//       reached.set(s, true);
   2.416 +//       if (bfs_queue.empty()) {
   2.417 +// 	bfs_queue.push(G.template first<OutEdgeIt>(s));
   2.418 +// 	actual_edge=bfs_queue.front();
   2.419 +// 	if (actual_edge.valid()) { 
   2.420 +// 	  Node w=G.bNode(actual_edge);
   2.421 +// 	  if (!reached.get(w)) {
   2.422 +// 	    bfs_queue.push(G.template first<OutEdgeIt>(w));
   2.423 +// 	    reached.set(w, true);
   2.424 +// 	    b_node_newly_reached=true;
   2.425 +// 	  } else {
   2.426 +// 	    b_node_newly_reached=false;
   2.427 +// 	  }
   2.428 +// 	} //else {
   2.429 +// 	//}
   2.430 +//       } else {
   2.431 +// 	bfs_queue.push(G.template first<OutEdgeIt>(s));
   2.432 +//       }
   2.433 +//     }
   2.434 +//     BfsIterator2<Graph, OutEdgeIt, ReachedMap>& 
   2.435 +//     operator++() { 
   2.436 +//       if (bfs_queue.front().valid()) { 
   2.437 +// 	++(bfs_queue.front());
   2.438 +// 	actual_edge=bfs_queue.front();
   2.439 +// 	if (actual_edge.valid()) {
   2.440 +// 	  Node w=G.bNode(actual_edge);
   2.441 +// 	  if (!reached.get(w)) {
   2.442 +// 	    bfs_queue.push(G.template first<OutEdgeIt>(w));
   2.443 +// 	    reached.set(w, true);
   2.444 +// 	    b_node_newly_reached=true;
   2.445 +// 	  } else {
   2.446 +// 	    b_node_newly_reached=false;
   2.447 +// 	  }
   2.448 +// 	}
   2.449 +//       } else {
   2.450 +// 	bfs_queue.pop(); 
   2.451 +// 	if (!bfs_queue.empty()) {
   2.452 +// 	  actual_edge=bfs_queue.front();
   2.453 +// 	  if (actual_edge.valid()) {
   2.454 +// 	    Node w=G.bNode(actual_edge);
   2.455 +// 	    if (!reached.get(w)) {
   2.456 +// 	      bfs_queue.push(G.template first<OutEdgeIt>(w));
   2.457 +// 	      reached.set(w, true);
   2.458 +// 	      b_node_newly_reached=true;
   2.459 +// 	    } else {
   2.460 +// 	      b_node_newly_reached=false;
   2.461 +// 	    }
   2.462 +// 	  }
   2.463 +// 	}
   2.464 +//       }
   2.465 +//       return *this;
   2.466 +//     }
   2.467 +//     bool finished() const { return bfs_queue.empty(); }
   2.468 +//     operator OutEdgeIt () const { return actual_edge; }
   2.469 +//     bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   2.470 +//     bool isANodeExamined() const { return !(actual_edge.valid()); }
   2.471 +//     const ReachedMap& getReachedMap() const { return reached; }
   2.472 +//     const std::queue<OutEdgeIt>& getBfsQueue() const { return bfs_queue; }
   2.473 +//  };
   2.474 +
   2.475 +
   2.476 +//   template <typename Graph, typename OutEdgeIt, typename ReachedMap>
   2.477 +//   class BfsIterator3 {
   2.478 +//     typedef typename Graph::Node Node;
   2.479 +//     const Graph& G;
   2.480 +//     std::queue< std::pair<Node, OutEdgeIt> > bfs_queue;
   2.481 +//     ReachedMap reached;
   2.482 +//     bool b_node_newly_reached;
   2.483 +//     OutEdgeIt actual_edge;
   2.484 +//   public:
   2.485 +//     BfsIterator3(const Graph& _G) : G(_G), reached(G, false) { }
   2.486 +//     void pushAndSetReached(Node s) { 
   2.487 +//       reached.set(s, true);
   2.488 +//       if (bfs_queue.empty()) {
   2.489 +// 	bfs_queue.push(std::pair<Node, OutEdgeIt>(s, G.template first<OutEdgeIt>(s)));
   2.490 +// 	actual_edge=bfs_queue.front().second;
   2.491 +// 	if (actual_edge.valid()) { 
   2.492 +// 	  Node w=G.bNode(actual_edge);
   2.493 +// 	  if (!reached.get(w)) {
   2.494 +// 	    bfs_queue.push(std::pair<Node, OutEdgeIt>(w, G.template first<OutEdgeIt>(w)));
   2.495 +// 	    reached.set(w, true);
   2.496 +// 	    b_node_newly_reached=true;
   2.497 +// 	  } else {
   2.498 +// 	    b_node_newly_reached=false;
   2.499 +// 	  }
   2.500 +// 	} //else {
   2.501 +// 	//}
   2.502 +//       } else {
   2.503 +// 	bfs_queue.push(std::pair<Node, OutEdgeIt>(s, G.template first<OutEdgeIt>(s)));
   2.504 +//       }
   2.505 +//     }
   2.506 +//     BfsIterator3<Graph, OutEdgeIt, ReachedMap>& 
   2.507 +//     operator++() { 
   2.508 +//       if (bfs_queue.front().second.valid()) { 
   2.509 +// 	++(bfs_queue.front().second);
   2.510 +// 	actual_edge=bfs_queue.front().second;
   2.511 +// 	if (actual_edge.valid()) {
   2.512 +// 	  Node w=G.bNode(actual_edge);
   2.513 +// 	  if (!reached.get(w)) {
   2.514 +// 	    bfs_queue.push(std::pair<Node, OutEdgeIt>(w, G.template first<OutEdgeIt>(w)));
   2.515 +// 	    reached.set(w, true);
   2.516 +// 	    b_node_newly_reached=true;
   2.517 +// 	  } else {
   2.518 +// 	    b_node_newly_reached=false;
   2.519 +// 	  }
   2.520 +// 	}
   2.521 +//       } else {
   2.522 +// 	bfs_queue.pop(); 
   2.523 +// 	if (!bfs_queue.empty()) {
   2.524 +// 	  actual_edge=bfs_queue.front().second;
   2.525 +// 	  if (actual_edge.valid()) {
   2.526 +// 	    Node w=G.bNode(actual_edge);
   2.527 +// 	    if (!reached.get(w)) {
   2.528 +// 	      bfs_queue.push(std::pair<Node, OutEdgeIt>(w, G.template first<OutEdgeIt>(w)));
   2.529 +// 	      reached.set(w, true);
   2.530 +// 	      b_node_newly_reached=true;
   2.531 +// 	    } else {
   2.532 +// 	      b_node_newly_reached=false;
   2.533 +// 	    }
   2.534 +// 	  }
   2.535 +// 	}
   2.536 +//       }
   2.537 +//       return *this;
   2.538 +//     }
   2.539 +//     bool finished() const { return bfs_queue.empty(); }
   2.540 +//     operator OutEdgeIt () const { return actual_edge; }
   2.541 +//     bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   2.542 +//     bool isANodeExamined() const { return !(actual_edge.valid()); }
   2.543 +//     Node aNode() const { return bfs_queue.front().first; }
   2.544 +//     Node bNode() const { return G.bNode(actual_edge); }
   2.545 +//     const ReachedMap& getReachedMap() const { return reached; }
   2.546 +//     //const std::queue< std::pair<Node, OutEdgeIt> >& getBfsQueue() const { return bfs_queue; }
   2.547 +//  };
   2.548 +
   2.549 +
   2.550 +//   template <typename Graph, typename OutEdgeIt, 
   2.551 +// 	    typename ReachedMap/*=typename Graph::NodeMap<bool>*/ >
   2.552 +//   class BfsIterator4 {
   2.553 +//     typedef typename Graph::Node Node;
   2.554 +//     const Graph& G;
   2.555 +//     std::queue<Node> bfs_queue;
   2.556 +//     ReachedMap& reached;
   2.557 +//     bool b_node_newly_reached;
   2.558 +//     OutEdgeIt actual_edge;
   2.559 +//     bool own_reached_map;
   2.560 +//   public:
   2.561 +//     BfsIterator4(const Graph& _G, ReachedMap& _reached) : 
   2.562 +//       G(_G), reached(_reached), 
   2.563 +//       own_reached_map(false) { }
   2.564 +//     BfsIterator4(const Graph& _G) : 
   2.565 +//       G(_G), reached(*(new ReachedMap(G /*, false*/))), 
   2.566 +//       own_reached_map(true) { }
   2.567 +//     ~BfsIterator4() { if (own_reached_map) delete &reached; }
   2.568 +//     void pushAndSetReached(Node s) { 
   2.569 +//       //std::cout << "mimi" << &reached << std::endl;
   2.570 +//       reached.set(s, true);
   2.571 +//       //std::cout << "mumus" << std::endl;
   2.572 +//       if (bfs_queue.empty()) {
   2.573 +// 	//std::cout << "bibi1" << std::endl;
   2.574 +// 	bfs_queue.push(s);
   2.575 +// 	//std::cout << "zizi" << std::endl;
   2.576 +// 	G./*getF*/first(actual_edge, s);
   2.577 +// 	//std::cout << "kiki" << std::endl;
   2.578 +// 	if (G.valid(actual_edge)/*.valid()*/) { 
   2.579 +// 	  Node w=G.bNode(actual_edge);
   2.580 +// 	  if (!reached.get(w)) {
   2.581 +// 	    bfs_queue.push(w);
   2.582 +// 	    reached.set(w, true);
   2.583 +// 	    b_node_newly_reached=true;
   2.584 +// 	  } else {
   2.585 +// 	    b_node_newly_reached=false;
   2.586 +// 	  }
   2.587 +// 	} 
   2.588 +//       } else {
   2.589 +// 	//std::cout << "bibi2" << std::endl;
   2.590 +// 	bfs_queue.push(s);
   2.591 +//       }
   2.592 +//     }
   2.593 +//     BfsIterator4<Graph, OutEdgeIt, ReachedMap>& 
   2.594 +//     operator++() { 
   2.595 +//       if (G.valid(actual_edge)/*.valid()*/) { 
   2.596 +// 	/*++*/G.next(actual_edge);
   2.597 +// 	if (G.valid(actual_edge)/*.valid()*/) {
   2.598 +// 	  Node w=G.bNode(actual_edge);
   2.599 +// 	  if (!reached.get(w)) {
   2.600 +// 	    bfs_queue.push(w);
   2.601 +// 	    reached.set(w, true);
   2.602 +// 	    b_node_newly_reached=true;
   2.603 +// 	  } else {
   2.604 +// 	    b_node_newly_reached=false;
   2.605 +// 	  }
   2.606 +// 	}
   2.607 +//       } else {
   2.608 +// 	bfs_queue.pop(); 
   2.609 +// 	if (!bfs_queue.empty()) {
   2.610 +// 	  G./*getF*/first(actual_edge, bfs_queue.front());
   2.611 +// 	  if (G.valid(actual_edge)/*.valid()*/) {
   2.612 +// 	    Node w=G.bNode(actual_edge);
   2.613 +// 	    if (!reached.get(w)) {
   2.614 +// 	      bfs_queue.push(w);
   2.615 +// 	      reached.set(w, true);
   2.616 +// 	      b_node_newly_reached=true;
   2.617 +// 	    } else {
   2.618 +// 	      b_node_newly_reached=false;
   2.619 +// 	    }
   2.620 +// 	  }
   2.621 +// 	}
   2.622 +//       }
   2.623 +//       return *this;
   2.624 +//     }
   2.625 +//     bool finished() const { return bfs_queue.empty(); }
   2.626 +//     operator OutEdgeIt () const { return actual_edge; }
   2.627 +//     bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   2.628 +//     bool isANodeExamined() const { return !(G.valid(actual_edge)/*.valid()*/); }
   2.629 +//     Node aNode() const { return bfs_queue.front(); }
   2.630 +//     Node bNode() const { return G.bNode(actual_edge); }
   2.631 +//     const ReachedMap& getReachedMap() const { return reached; }
   2.632 +//     const std::queue<Node>& getBfsQueue() const { return bfs_queue; }
   2.633 +//  };  
   2.634 +
   2.635 +
   2.636 +  template <typename GraphWrapper, /*typename OutEdgeIt,*/ 
   2.637 +	    typename ReachedMap/*=typename GraphWrapper::NodeMap<bool>*/ >
   2.638 +  class BfsIterator5 {
   2.639 +    typedef typename GraphWrapper::Node Node;
   2.640 +    typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
   2.641 +    const GraphWrapper* g;
   2.642 +    std::queue<Node> bfs_queue;
   2.643 +    ReachedMap& reached;
   2.644 +    bool b_node_newly_reached;
   2.645 +    OutEdgeIt actual_edge;
   2.646 +    bool own_reached_map;
   2.647 +  public:
   2.648 +    BfsIterator5(const GraphWrapper& _g, ReachedMap& _reached) : 
   2.649 +      g(&_g), reached(_reached), 
   2.650 +      own_reached_map(false) { }
   2.651 +    BfsIterator5(const GraphWrapper& _g) : 
   2.652 +      g(&_g), reached(*(new ReachedMap(*g /*, false*/))), 
   2.653 +      own_reached_map(true) { }
   2.654 +//     BfsIterator5(const typename GraphWrapper::BaseGraph& _G, 
   2.655 +// 		 ReachedMap& _reached) : 
   2.656 +//       G(_G), reached(_reached), 
   2.657 +//       own_reached_map(false) { }
   2.658 +//     BfsIterator5(const typename GraphWrapper::BaseGraph& _G) : 
   2.659 +//       G(_G), reached(*(new ReachedMap(G /*, false*/))), 
   2.660 +//       own_reached_map(true) { }
   2.661 +    ~BfsIterator5() { if (own_reached_map) delete &reached; }
   2.662 +    void pushAndSetReached(Node s) { 
   2.663 +      reached.set(s, true);
   2.664 +      if (bfs_queue.empty()) {
   2.665 +	bfs_queue.push(s);
   2.666 +	g->first(actual_edge, s);
   2.667 +	if (g->valid(actual_edge)) { 
   2.668 +	  Node w=g->bNode(actual_edge);
   2.669 +	  if (!reached.get(w)) {
   2.670 +	    bfs_queue.push(w);
   2.671 +	    reached.set(w, true);
   2.672 +	    b_node_newly_reached=true;
   2.673 +	  } else {
   2.674 +	    b_node_newly_reached=false;
   2.675 +	  }
   2.676 +	} 
   2.677 +      } else {
   2.678 +	bfs_queue.push(s);
   2.679 +      }
   2.680 +    }
   2.681 +    BfsIterator5<GraphWrapper, /*OutEdgeIt,*/ ReachedMap>& 
   2.682 +    operator++() { 
   2.683 +      if (g->valid(actual_edge)) { 
   2.684 +	g->next(actual_edge);
   2.685 +	if (g->valid(actual_edge)) {
   2.686 +	  Node w=g->bNode(actual_edge);
   2.687 +	  if (!reached.get(w)) {
   2.688 +	    bfs_queue.push(w);
   2.689 +	    reached.set(w, true);
   2.690 +	    b_node_newly_reached=true;
   2.691 +	  } else {
   2.692 +	    b_node_newly_reached=false;
   2.693 +	  }
   2.694 +	}
   2.695 +      } else {
   2.696 +	bfs_queue.pop(); 
   2.697 +	if (!bfs_queue.empty()) {
   2.698 +	  g->first(actual_edge, bfs_queue.front());
   2.699 +	  if (g->valid(actual_edge)) {
   2.700 +	    Node w=g->bNode(actual_edge);
   2.701 +	    if (!reached.get(w)) {
   2.702 +	      bfs_queue.push(w);
   2.703 +	      reached.set(w, true);
   2.704 +	      b_node_newly_reached=true;
   2.705 +	    } else {
   2.706 +	      b_node_newly_reached=false;
   2.707 +	    }
   2.708 +	  }
   2.709 +	}
   2.710 +      }
   2.711 +      return *this;
   2.712 +    }
   2.713 +    bool finished() const { return bfs_queue.empty(); }
   2.714 +    operator OutEdgeIt () const { return actual_edge; }
   2.715 +    bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   2.716 +    bool isANodeExamined() const { return !(g->valid(actual_edge)); }
   2.717 +    Node aNode() const { return bfs_queue.front(); }
   2.718 +    Node bNode() const { return g->bNode(actual_edge); }
   2.719 +    const ReachedMap& getReachedMap() const { return reached; }
   2.720 +    const std::queue<Node>& getBfsQueue() const { return bfs_queue; }
   2.721 +  };  
   2.722 +
   2.723 +//   template <typename Graph, typename OutEdgeIt, 
   2.724 +// 	    typename ReachedMap/*=typename Graph::NodeMap<bool>*/ >
   2.725 +//   class DfsIterator4 {
   2.726 +//     typedef typename Graph::Node Node;
   2.727 +//     const Graph& G;
   2.728 +//     std::stack<OutEdgeIt> dfs_stack;
   2.729 +//     bool b_node_newly_reached;
   2.730 +//     OutEdgeIt actual_edge;
   2.731 +//     Node actual_node;
   2.732 +//     ReachedMap& reached;
   2.733 +//     bool own_reached_map;
   2.734 +//   public:
   2.735 +//     DfsIterator4(const Graph& _G, ReachedMap& _reached) : 
   2.736 +//       G(_G), reached(_reached), 
   2.737 +//       own_reached_map(false) { }
   2.738 +//     DfsIterator4(const Graph& _G) : 
   2.739 +//       G(_G), reached(*(new ReachedMap(G /*, false*/))), 
   2.740 +//       own_reached_map(true) { }
   2.741 +//     ~DfsIterator4() { if (own_reached_map) delete &reached; }
   2.742 +//     void pushAndSetReached(Node s) { 
   2.743 +//       actual_node=s;
   2.744 +//       reached.set(s, true);
   2.745 +//       dfs_stack.push(G.template first<OutEdgeIt>(s)); 
   2.746 +//     }
   2.747 +//     DfsIterator4<Graph, OutEdgeIt, ReachedMap>& 
   2.748 +//     operator++() { 
   2.749 +//       actual_edge=dfs_stack.top();
   2.750 +//       //actual_node=G.aNode(actual_edge);
   2.751 +//       if (G.valid(actual_edge)/*.valid()*/) { 
   2.752 +// 	Node w=G.bNode(actual_edge);
   2.753 +// 	actual_node=w;
   2.754 +// 	if (!reached.get(w)) {
   2.755 +// 	  dfs_stack.push(G.template first<OutEdgeIt>(w));
   2.756 +// 	  reached.set(w, true);
   2.757 +// 	  b_node_newly_reached=true;
   2.758 +// 	} else {
   2.759 +// 	  actual_node=G.aNode(actual_edge);
   2.760 +// 	  /*++*/G.next(dfs_stack.top());
   2.761 +// 	  b_node_newly_reached=false;
   2.762 +// 	}
   2.763 +//       } else {
   2.764 +// 	//actual_node=G.aNode(dfs_stack.top());
   2.765 +// 	dfs_stack.pop();
   2.766 +//       }
   2.767 +//       return *this;
   2.768 +//     }
   2.769 +//     bool finished() const { return dfs_stack.empty(); }
   2.770 +//     operator OutEdgeIt () const { return actual_edge; }
   2.771 +//     bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   2.772 +//     bool isANodeExamined() const { return !(G.valid(actual_edge)/*.valid()*/); }
   2.773 +//     Node aNode() const { return actual_node; /*FIXME*/}
   2.774 +//     Node bNode() const { return G.bNode(actual_edge); }
   2.775 +//     const ReachedMap& getReachedMap() const { return reached; }
   2.776 +//     const std::stack<OutEdgeIt>& getDfsStack() const { return dfs_stack; }
   2.777 +//   };
   2.778 +
   2.779 +  template <typename GraphWrapper, /*typename OutEdgeIt,*/ 
   2.780 +	    typename ReachedMap/*=typename GraphWrapper::NodeMap<bool>*/ >
   2.781 +  class DfsIterator5 {
   2.782 +    typedef typename GraphWrapper::Node Node;
   2.783 +    typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
   2.784 +    const GraphWrapper* g;
   2.785 +    std::stack<OutEdgeIt> dfs_stack;
   2.786 +    bool b_node_newly_reached;
   2.787 +    OutEdgeIt actual_edge;
   2.788 +    Node actual_node;
   2.789 +    ReachedMap& reached;
   2.790 +    bool own_reached_map;
   2.791 +  public:
   2.792 +    DfsIterator5(const GraphWrapper& _g, ReachedMap& _reached) : 
   2.793 +      g(&_g), reached(_reached), 
   2.794 +      own_reached_map(false) { }
   2.795 +    DfsIterator5(const GraphWrapper& _g) : 
   2.796 +      g(&_g), reached(*(new ReachedMap(*g /*, false*/))), 
   2.797 +      own_reached_map(true) { }
   2.798 +    ~DfsIterator5() { if (own_reached_map) delete &reached; }
   2.799 +    void pushAndSetReached(Node s) { 
   2.800 +      actual_node=s;
   2.801 +      reached.set(s, true);
   2.802 +      OutEdgeIt e;
   2.803 +      g->first(e, s);
   2.804 +      dfs_stack.push(e); 
   2.805 +    }
   2.806 +    DfsIterator5<GraphWrapper, /*OutEdgeIt,*/ ReachedMap>& 
   2.807 +    operator++() { 
   2.808 +      actual_edge=dfs_stack.top();
   2.809 +      //actual_node=G.aNode(actual_edge);
   2.810 +      if (g->valid(actual_edge)/*.valid()*/) { 
   2.811 +	Node w=g->bNode(actual_edge);
   2.812 +	actual_node=w;
   2.813 +	if (!reached.get(w)) {
   2.814 +	  OutEdgeIt e;
   2.815 +	  g->first(e, w);
   2.816 +	  dfs_stack.push(e);
   2.817 +	  reached.set(w, true);
   2.818 +	  b_node_newly_reached=true;
   2.819 +	} else {
   2.820 +	  actual_node=g->aNode(actual_edge);
   2.821 +	  g->next(dfs_stack.top());
   2.822 +	  b_node_newly_reached=false;
   2.823 +	}
   2.824 +      } else {
   2.825 +	//actual_node=G.aNode(dfs_stack.top());
   2.826 +	dfs_stack.pop();
   2.827 +      }
   2.828 +      return *this;
   2.829 +    }
   2.830 +    bool finished() const { return dfs_stack.empty(); }
   2.831 +    operator OutEdgeIt () const { return actual_edge; }
   2.832 +    bool isBNodeNewlyReached() const { return b_node_newly_reached; }
   2.833 +    bool isANodeExamined() const { return !(g->valid(actual_edge)); }
   2.834 +    Node aNode() const { return actual_node; /*FIXME*/}
   2.835 +    Node bNode() const { return G.bNode(actual_edge); }
   2.836 +    const ReachedMap& getReachedMap() const { return reached; }
   2.837 +    const std::stack<OutEdgeIt>& getDfsStack() const { return dfs_stack; }
   2.838 +  };
   2.839 +
   2.840 +
   2.841 +
   2.842 +} // namespace hugo
   2.843 +
   2.844 +#endif //HUGO_BFS_ITERATOR_H
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/work/marci/experiment/deref_vs_optimization	Sat Apr 03 17:26:46 2004 +0000
     3.3 @@ -0,0 +1,147 @@
     3.4 +-O0:
     3.5 +
     3.6 +marci@karp:~/etik-ol/src/demo/marci/experiment$ ./edmonds_karp_demo < ../flow-1.dim
     3.7 +edmonds karp demo (physical blocking flow augmentation)...
     3.8 +elapsed time: u: 1.11s, s: 0.02s, cu: 0s, cs: 0s, real: 1.23456s
     3.9 +number of augmentation phases: 3
    3.10 +flow value: 6068
    3.11 +edmonds karp demo (physical blocking flow 1 augmentation)...
    3.12 +elapsed time: u: 0.78s, s: 0s, cu: 0s, cs: 0s, real: 0.851246s
    3.13 +number of augmentation phases: 3
    3.14 +flow value: 6068
    3.15 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    3.16 +elapsed time: u: 1.02s, s: 0s, cu: 0s, cs: 0s, real: 1.12829s
    3.17 +number of augmentation phases: 3
    3.18 +flow value: 6068
    3.19 +edmonds karp demo (on-the-fly shortest path augmentation)...
    3.20 +elapsed time: u: 76.09s, s: 0.77s, cu: 0s, cs: 0s, real: 127.892s
    3.21 +number of augmentation phases: 1854
    3.22 +flow value: 6068
    3.23 +
    3.24 +marci@karp:~/etik-ol/src/demo/marci/experiment$ ./edmonds_karp_demo_1 < ../flow-1.dim
    3.25 +edmonds karp demo (physical blocking flow augmentation)...
    3.26 +elapsed time: u: 1.04s, s: 0.01s, cu: 0s, cs: 0s, real: 1.1643s
    3.27 +number of augmentation phases: 3
    3.28 +flow value: 6068
    3.29 +edmonds karp demo (physical blocking flow 1 augmentation)...
    3.30 +elapsed time: u: 0.73s, s: 0s, cu: 0s, cs: 0s, real: 1.29574s
    3.31 +number of augmentation phases: 3
    3.32 +flow value: 6068
    3.33 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    3.34 +elapsed time: u: 0.96s, s: 0.01s, cu: 0s, cs: 0s, real: 1.05265s
    3.35 +number of augmentation phases: 3
    3.36 +flow value: 6068
    3.37 +edmonds karp demo (on-the-fly shortest path augmentation)...
    3.38 +elapsed time: u: 72.65s, s: 0.67s, cu: 0s, cs: 0s, real: 79.8199s
    3.39 +number of augmentation phases: 1854
    3.40 +flow value: 6068
    3.41 +
    3.42 +marci@linux:~/etik-ol/src/demo/marci/experiment> ./edmonds_karp_demo < ../flow-1.dim
    3.43 +edmonds karp demo (physical blocking flow augmentation)...
    3.44 +elapsed time: u: 3.04s, s: 0.01s, cu: 0s, cs: 0s, real: 3.09736s
    3.45 +number of augmentation phases: 3
    3.46 +flow value: 6068
    3.47 +edmonds karp demo (physical blocking flow 1 augmentation)...
    3.48 +elapsed time: u: 2.22s, s: 0.02s, cu: 0s, cs: 0s, real: 2.26504s
    3.49 +number of augmentation phases: 3
    3.50 +flow value: 6068
    3.51 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    3.52 +elapsed time: u: 2.88s, s: 0.01s, cu: 0s, cs: 0s, real: 3.03116s
    3.53 +number of augmentation phases: 3
    3.54 +flow value: 6068
    3.55 +edmonds karp demo (on-the-fly shortest path augmentation)...
    3.56 +elapsed time: u: 201.69s, s: 0.08s, cu: 0s, cs: 0s, real: 203.99s
    3.57 +number of augmentation phases: 1854
    3.58 +flow value: 6068
    3.59 +
    3.60 +marci@linux:~/etik-ol/src/demo/marci/experiment> ./edmonds_karp_demo_1 < ../flow-1.dim
    3.61 +edmonds karp demo (physical blocking flow augmentation)...
    3.62 +elapsed time: u: 3s, s: 0.04s, cu: 0s, cs: 0s, real: 3.19728s
    3.63 +number of augmentation phases: 3
    3.64 +flow value: 6068
    3.65 +edmonds karp demo (physical blocking flow 1 augmentation)...
    3.66 +elapsed time: u: 2.21s, s: 0.03s, cu: 0s, cs: 0s, real: 2.25725s
    3.67 +number of augmentation phases: 3
    3.68 +flow value: 6068
    3.69 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    3.70 +elapsed time: u: 2.82s, s: 0s, cu: 0s, cs: 0s, real: 2.83294s
    3.71 +number of augmentation phases: 3
    3.72 +flow value: 6068
    3.73 +edmonds karp demo (on-the-fly shortest path augmentation)...
    3.74 +elapsed time: u: 203.39s, s: 0.07s, cu: 0s, cs: 0s, real: 204.401s
    3.75 +number of augmentation phases: 1854
    3.76 +flow value: 6068
    3.77 +
    3.78 +-03:
    3.79 +
    3.80 +marci@karp:~/etik-ol/src/demo/marci/experiment$ ./edmonds_karp_demo < ../flow-1.dim
    3.81 +edmonds karp demo (physical blocking flow augmentation)...
    3.82 +elapsed time: u: 0.36s, s: 0.01s, cu: 0s, cs: 0s, real: 1.13854s
    3.83 +number of augmentation phases: 3
    3.84 +flow value: 6068
    3.85 +edmonds karp demo (physical blocking flow 1 augmentation)...
    3.86 +elapsed time: u: 0.23s, s: 0s, cu: 0s, cs: 0s, real: 0.243452s
    3.87 +number of augmentation phases: 3
    3.88 +flow value: 6068
    3.89 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    3.90 +elapsed time: u: 0.32s, s: 0.01s, cu: 0s, cs: 0s, real: 0.339224s
    3.91 +number of augmentation phases: 3
    3.92 +flow value: 6068
    3.93 +edmonds karp demo (on-the-fly shortest path augmentation)...
    3.94 +elapsed time: u: 26.98s, s: 0.29s, cu: 0s, cs: 0s, real: 32.2458s
    3.95 +number of augmentation phases: 1854
    3.96 +flow value: 6068
    3.97 +
    3.98 +marci@karp:~/etik-ol/src/demo/marci/experiment$ ./edmonds_karp_demo_1 < ../flow-1.dim
    3.99 +edmonds karp demo (physical blocking flow augmentation)...
   3.100 +elapsed time: u: 0.37s, s: 0.01s, cu: 0s, cs: 0s, real: 0.402523s
   3.101 +number of augmentation phases: 3
   3.102 +flow value: 6068
   3.103 +edmonds karp demo (physical blocking flow 1 augmentation)...
   3.104 +elapsed time: u: 0.22s, s: 0s, cu: 0s, cs: 0s, real: 0.244878s
   3.105 +number of augmentation phases: 3
   3.106 +flow value: 6068
   3.107 +edmonds karp demo (on-the-fly blocking flow augmentation)...
   3.108 +elapsed time: u: 0.32s, s: 0.01s, cu: 0s, cs: 0s, real: 0.353093s
   3.109 +number of augmentation phases: 3
   3.110 +flow value: 6068
   3.111 +edmonds karp demo (on-the-fly shortest path augmentation)...
   3.112 +elapsed time: u: 27.02s, s: 0.34s, cu: 0s, cs: 0s, real: 30.0516s
   3.113 +number of augmentation phases: 1854
   3.114 +flow value: 6068
   3.115 +
   3.116 +marci@linux:~/etik-ol/src/demo/marci/experiment> ./edmonds_karp_demo < ../flow-1.dim
   3.117 +edmonds karp demo (physical blocking flow augmentation)...
   3.118 +elapsed time: u: 0.91s, s: 0.01s, cu: 0s, cs: 0s, real: 0.938415s
   3.119 +number of augmentation phases: 3
   3.120 +flow value: 6068
   3.121 +edmonds karp demo (physical blocking flow 1 augmentation)...
   3.122 +elapsed time: u: 0.61s, s: 0.01s, cu: 0s, cs: 0s, real: 0.62244s
   3.123 +number of augmentation phases: 3
   3.124 +flow value: 6068
   3.125 +edmonds karp demo (on-the-fly blocking flow augmentation)...
   3.126 +elapsed time: u: 0.88s, s: 0s, cu: 0s, cs: 0s, real: 0.914984s
   3.127 +number of augmentation phases: 3
   3.128 +flow value: 6068
   3.129 +edmonds karp demo (on-the-fly shortest path augmentation)...
   3.130 +elapsed time: u: 66.55s, s: 0.09s, cu: 0s, cs: 0s, real: 67.5525s
   3.131 +number of augmentation phases: 1854
   3.132 +flow value: 6068
   3.133 +
   3.134 +marci@linux:~/etik-ol/src/demo/marci/experiment> ./edmonds_karp_demo_1 < ../flow-1.dim
   3.135 +edmonds karp demo (physical blocking flow augmentation)...
   3.136 +elapsed time: u: 0.85s, s: 0s, cu: 0s, cs: 0s, real: 0.858786s
   3.137 +number of augmentation phases: 3
   3.138 +flow value: 6068
   3.139 +edmonds karp demo (physical blocking flow 1 augmentation)...
   3.140 +elapsed time: u: 0.58s, s: 0.03s, cu: 0s, cs: 0s, real: 0.61541s
   3.141 +number of augmentation phases: 3
   3.142 +flow value: 6068
   3.143 +edmonds karp demo (on-the-fly blocking flow augmentation)...
   3.144 +elapsed time: u: 0.85s, s: 0s, cu: 0s, cs: 0s, real: 0.85847s
   3.145 +number of augmentation phases: 3
   3.146 +flow value: 6068
   3.147 +edmonds karp demo (on-the-fly shortest path augmentation)...
   3.148 +elapsed time: u: 66.71s, s: 0.06s, cu: 0s, cs: 0s, real: 68.0292s
   3.149 +number of augmentation phases: 1854
   3.150 +flow value: 6068
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/work/marci/experiment/deref_vs_optimization_lenyeg	Sat Apr 03 17:26:46 2004 +0000
     4.3 @@ -0,0 +1,83 @@
     4.4 +-O0:
     4.5 +
     4.6 +marci@karp:~/etik-ol/src/demo/marci/experiment$ ./edmonds_karp_demo < ../flow-1.dim
     4.7 +edmonds karp demo (physical blocking flow augmentation)...
     4.8 +elapsed time: u: 1.11s, s: 0.02s, cu: 0s, cs: 0s, real: 1.23456s
     4.9 +edmonds karp demo (physical blocking flow 1 augmentation)...
    4.10 +elapsed time: u: 0.78s, s: 0s, cu: 0s, cs: 0s, real: 0.851246s
    4.11 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    4.12 +elapsed time: u: 1.02s, s: 0s, cu: 0s, cs: 0s, real: 1.12829s
    4.13 +edmonds karp demo (on-the-fly shortest path augmentation)...
    4.14 +elapsed time: u: 76.09s, s: 0.77s, cu: 0s, cs: 0s, real: 127.892s
    4.15 +
    4.16 +marci@karp:~/etik-ol/src/demo/marci/experiment$ ./edmonds_karp_demo_1 < ../flow-1.dim
    4.17 +edmonds karp demo (physical blocking flow augmentation)...
    4.18 +elapsed time: u: 1.04s, s: 0.01s, cu: 0s, cs: 0s, real: 1.1643s
    4.19 +edmonds karp demo (physical blocking flow 1 augmentation)...
    4.20 +elapsed time: u: 0.73s, s: 0s, cu: 0s, cs: 0s, real: 1.29574s
    4.21 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    4.22 +elapsed time: u: 0.96s, s: 0.01s, cu: 0s, cs: 0s, real: 1.05265s
    4.23 +edmonds karp demo (on-the-fly shortest path augmentation)...
    4.24 +elapsed time: u: 72.65s, s: 0.67s, cu: 0s, cs: 0s, real: 79.8199s
    4.25 +
    4.26 +marci@linux:~/etik-ol/src/demo/marci/experiment> ./edmonds_karp_demo < ../flow-1.dim
    4.27 +edmonds karp demo (physical blocking flow augmentation)...
    4.28 +elapsed time: u: 3.04s, s: 0.01s, cu: 0s, cs: 0s, real: 3.09736s
    4.29 +edmonds karp demo (physical blocking flow 1 augmentation)...
    4.30 +elapsed time: u: 2.22s, s: 0.02s, cu: 0s, cs: 0s, real: 2.26504s
    4.31 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    4.32 +elapsed time: u: 2.88s, s: 0.01s, cu: 0s, cs: 0s, real: 3.03116s
    4.33 +edmonds karp demo (on-the-fly shortest path augmentation)...
    4.34 +elapsed time: u: 201.69s, s: 0.08s, cu: 0s, cs: 0s, real: 203.99s
    4.35 +
    4.36 +marci@linux:~/etik-ol/src/demo/marci/experiment> ./edmonds_karp_demo_1 < ../flow-1.dim
    4.37 +edmonds karp demo (physical blocking flow augmentation)...
    4.38 +elapsed time: u: 3s, s: 0.04s, cu: 0s, cs: 0s, real: 3.19728s
    4.39 +edmonds karp demo (physical blocking flow 1 augmentation)...
    4.40 +elapsed time: u: 2.21s, s: 0.03s, cu: 0s, cs: 0s, real: 2.25725s
    4.41 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    4.42 +elapsed time: u: 2.82s, s: 0s, cu: 0s, cs: 0s, real: 2.83294s
    4.43 +edmonds karp demo (on-the-fly shortest path augmentation)...
    4.44 +elapsed time: u: 203.39s, s: 0.07s, cu: 0s, cs: 0s, real: 204.401s
    4.45 +
    4.46 +-03:
    4.47 +
    4.48 +marci@karp:~/etik-ol/src/demo/marci/experiment$ ./edmonds_karp_demo < ../flow-1.dim
    4.49 +edmonds karp demo (physical blocking flow augmentation)...
    4.50 +elapsed time: u: 0.36s, s: 0.01s, cu: 0s, cs: 0s, real: 1.13854s
    4.51 +edmonds karp demo (physical blocking flow 1 augmentation)...
    4.52 +elapsed time: u: 0.23s, s: 0s, cu: 0s, cs: 0s, real: 0.243452s
    4.53 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    4.54 +elapsed time: u: 0.32s, s: 0.01s, cu: 0s, cs: 0s, real: 0.339224s
    4.55 +edmonds karp demo (on-the-fly shortest path augmentation)...
    4.56 +elapsed time: u: 26.98s, s: 0.29s, cu: 0s, cs: 0s, real: 32.2458s
    4.57 +
    4.58 +marci@karp:~/etik-ol/src/demo/marci/experiment$ ./edmonds_karp_demo_1 < ../flow-1.dim
    4.59 +edmonds karp demo (physical blocking flow augmentation)...
    4.60 +elapsed time: u: 0.37s, s: 0.01s, cu: 0s, cs: 0s, real: 0.402523s
    4.61 +edmonds karp demo (physical blocking flow 1 augmentation)...
    4.62 +elapsed time: u: 0.22s, s: 0s, cu: 0s, cs: 0s, real: 0.244878s
    4.63 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    4.64 +elapsed time: u: 0.32s, s: 0.01s, cu: 0s, cs: 0s, real: 0.353093s
    4.65 +edmonds karp demo (on-the-fly shortest path augmentation)...
    4.66 +elapsed time: u: 27.02s, s: 0.34s, cu: 0s, cs: 0s, real: 30.0516s
    4.67 +
    4.68 +marci@linux:~/etik-ol/src/demo/marci/experiment> ./edmonds_karp_demo < ../flow-1.dim
    4.69 +edmonds karp demo (physical blocking flow augmentation)...
    4.70 +elapsed time: u: 0.91s, s: 0.01s, cu: 0s, cs: 0s, real: 0.938415s
    4.71 +edmonds karp demo (physical blocking flow 1 augmentation)...
    4.72 +elapsed time: u: 0.61s, s: 0.01s, cu: 0s, cs: 0s, real: 0.62244s
    4.73 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    4.74 +elapsed time: u: 0.88s, s: 0s, cu: 0s, cs: 0s, real: 0.914984s
    4.75 +edmonds karp demo (on-the-fly shortest path augmentation)...
    4.76 +elapsed time: u: 66.55s, s: 0.09s, cu: 0s, cs: 0s, real: 67.5525s
    4.77 +
    4.78 +marci@linux:~/etik-ol/src/demo/marci/experiment> ./edmonds_karp_demo_1 < ../flow-1.dim
    4.79 +edmonds karp demo (physical blocking flow augmentation)...
    4.80 +elapsed time: u: 0.85s, s: 0s, cu: 0s, cs: 0s, real: 0.858786s
    4.81 +edmonds karp demo (physical blocking flow 1 augmentation)...
    4.82 +elapsed time: u: 0.58s, s: 0.03s, cu: 0s, cs: 0s, real: 0.61541s
    4.83 +edmonds karp demo (on-the-fly blocking flow augmentation)...
    4.84 +elapsed time: u: 0.85s, s: 0s, cu: 0s, cs: 0s, real: 0.85847s
    4.85 +edmonds karp demo (on-the-fly shortest path augmentation)...
    4.86 +elapsed time: u: 66.71s, s: 0.06s, cu: 0s, cs: 0s, real: 68.0292s
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/work/marci/experiment/edmonds_karp.h	Sat Apr 03 17:26:46 2004 +0000
     5.3 @@ -0,0 +1,1238 @@
     5.4 +// -*- c++ -*-
     5.5 +#ifndef HUGO_EDMONDS_KARP_H
     5.6 +#define HUGO_EDMONDS_KARP_H
     5.7 +
     5.8 +#include <algorithm>
     5.9 +#include <list>
    5.10 +#include <iterator>
    5.11 +
    5.12 +#include <bfs_iterator.h>
    5.13 +#include <invalid.h>
    5.14 +
    5.15 +namespace hugo {
    5.16 +
    5.17 +  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
    5.18 +  class ResGraph {
    5.19 +  public:
    5.20 +    typedef typename Graph::Node Node;
    5.21 +    typedef typename Graph::NodeIt NodeIt;
    5.22 +  private:
    5.23 +    typedef typename Graph::SymEdgeIt OldSymEdgeIt;
    5.24 +    const Graph& G;
    5.25 +    FlowMap& flow;
    5.26 +    const CapacityMap& capacity;
    5.27 +  public:
    5.28 +    ResGraph(const Graph& _G, FlowMap& _flow, 
    5.29 +	     const CapacityMap& _capacity) : 
    5.30 +      G(_G), flow(_flow), capacity(_capacity) { }
    5.31 +
    5.32 +    class Edge; 
    5.33 +    class OutEdgeIt; 
    5.34 +    friend class Edge; 
    5.35 +    friend class OutEdgeIt; 
    5.36 +
    5.37 +    class Edge {
    5.38 +      friend class ResGraph<Graph, Number, FlowMap, CapacityMap>;
    5.39 +    protected:
    5.40 +      const ResGraph<Graph, Number, FlowMap, CapacityMap>* resG;
    5.41 +      OldSymEdgeIt sym;
    5.42 +    public:
    5.43 +      Edge() { } 
    5.44 +      //Edge(const Edge& e) : resG(e.resG), sym(e.sym) { }
    5.45 +      Number free() const { 
    5.46 +	if (resG->G.aNode(sym)==resG->G.tail(sym)) { 
    5.47 +	  return (resG->capacity.get(sym)-resG->flow.get(sym)); 
    5.48 +	} else { 
    5.49 +	  return (resG->flow.get(sym)); 
    5.50 +	}
    5.51 +      }
    5.52 +      bool valid() const { return sym.valid(); }
    5.53 +      void augment(Number a) const {
    5.54 +	if (resG->G.aNode(sym)==resG->G.tail(sym)) { 
    5.55 +	  resG->flow.set(sym, resG->flow.get(sym)+a);
    5.56 +	  //resG->flow[sym]+=a;
    5.57 +	} else { 
    5.58 +	  resG->flow.set(sym, resG->flow.get(sym)-a);
    5.59 +	  //resG->flow[sym]-=a;
    5.60 +	}
    5.61 +      }
    5.62 +    };
    5.63 +
    5.64 +    class OutEdgeIt : public Edge {
    5.65 +      friend class ResGraph<Graph, Number, FlowMap, CapacityMap>;
    5.66 +    public:
    5.67 +      OutEdgeIt() { }
    5.68 +      //OutEdgeIt(const OutEdgeIt& e) { resG=e.resG; sym=e.sym; }
    5.69 +    private:
    5.70 +      OutEdgeIt(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _resG, Node v) { 
    5.71 +      	resG=&_resG;
    5.72 +	sym=resG->G.template first<OldSymEdgeIt>(v);
    5.73 +	while( sym.valid() && !(free()>0) ) { ++sym; }
    5.74 +      }
    5.75 +    public:
    5.76 +      OutEdgeIt& operator++() { 
    5.77 +	++sym; 
    5.78 +	while( sym.valid() && !(free()>0) ) { ++sym; }
    5.79 +	return *this; 
    5.80 +      }
    5.81 +    };
    5.82 +
    5.83 +    void /*getF*/first(OutEdgeIt& e, Node v) const { 
    5.84 +      e=OutEdgeIt(*this, v); 
    5.85 +    }
    5.86 +    void /*getF*/first(NodeIt& v) const { G./*getF*/first(v); }
    5.87 +    
    5.88 +    template< typename It >
    5.89 +    It first() const { 
    5.90 +      It e;      
    5.91 +      /*getF*/first(e);
    5.92 +      return e; 
    5.93 +    }
    5.94 +
    5.95 +    template< typename It >
    5.96 +    It first(Node v) const { 
    5.97 +      It e;
    5.98 +      /*getF*/first(e, v);
    5.99 +      return e; 
   5.100 +    }
   5.101 +
   5.102 +    Node tail(Edge e) const { return G.aNode(e.sym); }
   5.103 +    Node head(Edge e) const { return G.bNode(e.sym); }
   5.104 +
   5.105 +    Node aNode(OutEdgeIt e) const { return G.aNode(e.sym); }
   5.106 +    Node bNode(OutEdgeIt e) const { return G.bNode(e.sym); }
   5.107 +
   5.108 +    int id(Node v) const { return G.id(v); }
   5.109 +
   5.110 +    template <typename S>
   5.111 +    class NodeMap {
   5.112 +      typename Graph::NodeMap<S> node_map; 
   5.113 +    public:
   5.114 +      NodeMap(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(_G.G) { }
   5.115 +      NodeMap(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _G, S a) : node_map(_G.G, a) { }
   5.116 +      void set(Node nit, S a) { node_map.set(nit, a); }
   5.117 +      S get(Node nit) const { return node_map.get(nit); }
   5.118 +      S& operator[](Node nit) { return node_map[nit]; } 
   5.119 +      const S& operator[](Node nit) const { return node_map[nit]; } 
   5.120 +    };
   5.121 +
   5.122 +  };
   5.123 +
   5.124 +
   5.125 +  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
   5.126 +  class ResGraph2 {
   5.127 +  public:
   5.128 +    typedef typename Graph::Node Node;
   5.129 +    typedef typename Graph::NodeIt NodeIt;
   5.130 +  private:
   5.131 +    //typedef typename Graph::SymEdgeIt OldSymEdgeIt;
   5.132 +    typedef typename Graph::OutEdgeIt OldOutEdgeIt;
   5.133 +    typedef typename Graph::InEdgeIt OldInEdgeIt;
   5.134 +    
   5.135 +    const Graph& G;
   5.136 +    FlowMap& flow;
   5.137 +    const CapacityMap& capacity;
   5.138 +  public:
   5.139 +    ResGraph2(const Graph& _G, FlowMap& _flow, 
   5.140 +	     const CapacityMap& _capacity) : 
   5.141 +      G(_G), flow(_flow), capacity(_capacity) { }
   5.142 +
   5.143 +    class Edge; 
   5.144 +    class OutEdgeIt; 
   5.145 +    friend class Edge; 
   5.146 +    friend class OutEdgeIt; 
   5.147 +
   5.148 +    class Edge {
   5.149 +      friend class ResGraph2<Graph, Number, FlowMap, CapacityMap>;
   5.150 +    protected:
   5.151 +      const ResGraph2<Graph, Number, FlowMap, CapacityMap>* resG;
   5.152 +      //OldSymEdgeIt sym;
   5.153 +      OldOutEdgeIt out;
   5.154 +      OldInEdgeIt in;
   5.155 +      bool out_or_in; //true, iff out
   5.156 +    public:
   5.157 +      Edge() : out_or_in(true) { } 
   5.158 +      Number free() const { 
   5.159 +	if (out_or_in) { 
   5.160 +	  return (resG->capacity.get(out)-resG->flow.get(out)); 
   5.161 +	} else { 
   5.162 +	  return (resG->flow.get(in)); 
   5.163 +	}
   5.164 +      }
   5.165 +      bool valid() const { 
   5.166 +	return out_or_in && out.valid() || in.valid(); }
   5.167 +      void augment(Number a) const {
   5.168 +	if (out_or_in) { 
   5.169 +	  resG->flow.set(out, resG->flow.get(out)+a);
   5.170 +	} else { 
   5.171 +	  resG->flow.set(in, resG->flow.get(in)-a);
   5.172 +	}
   5.173 +      }
   5.174 +    };
   5.175 +
   5.176 +    class OutEdgeIt : public Edge {
   5.177 +      friend class ResGraph2<Graph, Number, FlowMap, CapacityMap>;
   5.178 +    public:
   5.179 +      OutEdgeIt() { }
   5.180 +    private:
   5.181 +      OutEdgeIt(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _resG, Node v) { 
   5.182 +      	resG=&_resG;
   5.183 +	out=resG->G.template first<OldOutEdgeIt>(v);
   5.184 +	while( out.valid() && !(free()>0) ) { ++out; }
   5.185 +	if (!out.valid()) {
   5.186 +	  out_or_in=0;
   5.187 +	  in=resG->G.template first<OldInEdgeIt>(v);
   5.188 +	  while( in.valid() && !(free()>0) ) { ++in; }
   5.189 +	}
   5.190 +      }
   5.191 +    public:
   5.192 +      OutEdgeIt& operator++() { 
   5.193 +	if (out_or_in) {
   5.194 +	  Node v=resG->G.aNode(out);
   5.195 +	  ++out;
   5.196 +	  while( out.valid() && !(free()>0) ) { ++out; }
   5.197 +	  if (!out.valid()) {
   5.198 +	    out_or_in=0;
   5.199 +	    in=resG->G.template first<OldInEdgeIt>(v);
   5.200 +	    while( in.valid() && !(free()>0) ) { ++in; }
   5.201 +	  }
   5.202 +	} else {
   5.203 +	  ++in;
   5.204 +	  while( in.valid() && !(free()>0) ) { ++in; } 
   5.205 +	}
   5.206 +	return *this; 
   5.207 +      }
   5.208 +    };
   5.209 +
   5.210 +    void /*getF*/first(OutEdgeIt& e, Node v) const { 
   5.211 +      e=OutEdgeIt(*this, v); 
   5.212 +    }
   5.213 +    void /*getF*/first(NodeIt& v) const { G./*getF*/first(v); }
   5.214 +    
   5.215 +    template< typename It >
   5.216 +    It first() const { 
   5.217 +      It e;
   5.218 +      /*getF*/first(e);
   5.219 +      return e; 
   5.220 +    }
   5.221 +
   5.222 +    template< typename It >
   5.223 +    It first(Node v) const { 
   5.224 +      It e;
   5.225 +      /*getF*/first(e, v);
   5.226 +      return e; 
   5.227 +    }
   5.228 +
   5.229 +    Node tail(Edge e) const { 
   5.230 +      return ((e.out_or_in) ? G.aNode(e.out) : G.aNode(e.in)); }
   5.231 +    Node head(Edge e) const { 
   5.232 +      return ((e.out_or_in) ? G.bNode(e.out) : G.bNode(e.in)); }
   5.233 +
   5.234 +    Node aNode(OutEdgeIt e) const { 
   5.235 +      return ((e.out_or_in) ? G.aNode(e.out) : G.aNode(e.in)); }
   5.236 +    Node bNode(OutEdgeIt e) const { 
   5.237 +      return ((e.out_or_in) ? G.bNode(e.out) : G.bNode(e.in)); }
   5.238 +
   5.239 +    int id(Node v) const { return G.id(v); }
   5.240 +
   5.241 +    template <typename S>
   5.242 +    class NodeMap {
   5.243 +      typename Graph::NodeMap<S> node_map; 
   5.244 +    public:
   5.245 +      NodeMap(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(_G.G) { }
   5.246 +      NodeMap(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _G, S a) : node_map(_G.G, a) { }
   5.247 +      void set(Node nit, S a) { node_map.set(nit, a); }
   5.248 +      S get(Node nit) const { return node_map.get(nit); }
   5.249 +    };
   5.250 +  };
   5.251 +
   5.252 +
   5.253 +  template <typename GraphWrapper, typename Number, typename FlowMap, typename CapacityMap>
   5.254 +  class MaxFlow {
   5.255 +  protected:
   5.256 +    typedef GraphWrapper GW;
   5.257 +    typedef typename GW::Node Node;
   5.258 +    typedef typename GW::Edge Edge;
   5.259 +    typedef typename GW::EdgeIt EdgeIt;
   5.260 +    typedef typename GW::OutEdgeIt OutEdgeIt;
   5.261 +    typedef typename GW::InEdgeIt InEdgeIt;
   5.262 +    //const Graph* G;
   5.263 +    GW gw;
   5.264 +    Node s;
   5.265 +    Node t;
   5.266 +    FlowMap* flow;
   5.267 +    const CapacityMap* capacity;
   5.268 +    typedef ResGraphWrapper<GW, Number, FlowMap, CapacityMap > ResGW;
   5.269 +    typedef typename ResGW::OutEdgeIt ResGWOutEdgeIt;
   5.270 +    typedef typename ResGW::Edge ResGWEdge;
   5.271 +  public:
   5.272 +
   5.273 +    MaxFlow(const GW& _gw, Node _s, Node _t, FlowMap& _flow, const CapacityMap& _capacity) : 
   5.274 +      gw(_gw), s(_s), t(_t), flow(&_flow), capacity(&_capacity) { }
   5.275 +
   5.276 +    bool augmentOnShortestPath() {
   5.277 +      ResGW res_graph(gw, *flow, *capacity);
   5.278 +      bool _augment=false;
   5.279 +      
   5.280 +      typedef typename ResGW::NodeMap<bool> ReachedMap;
   5.281 +      BfsIterator5< ResGW, ReachedMap > bfs(res_graph);
   5.282 +      bfs.pushAndSetReached(s);
   5.283 +	
   5.284 +      typename ResGW::NodeMap<ResGWEdge> pred(res_graph); 
   5.285 +      pred.set(s, INVALID);
   5.286 +      
   5.287 +      typename ResGW::NodeMap<Number> free(res_graph);
   5.288 +	
   5.289 +      //searching for augmenting path
   5.290 +      while ( !bfs.finished() ) { 
   5.291 +	ResGWOutEdgeIt e=bfs;
   5.292 +	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   5.293 +	  Node v=res_graph.tail(e);
   5.294 +	  Node w=res_graph.head(e);
   5.295 +	  pred.set(w, e);
   5.296 +	  if (res_graph.valid(pred.get(v))) {
   5.297 +	    free.set(w, std::min(free.get(v), res_graph.resCap(e)));
   5.298 +	  } else {
   5.299 +	    free.set(w, res_graph.resCap(e)); 
   5.300 +	  }
   5.301 +	  if (res_graph.head(e)==t) { _augment=true; break; }
   5.302 +	}
   5.303 +	
   5.304 +	++bfs;
   5.305 +      } //end of searching augmenting path
   5.306 +
   5.307 +      if (_augment) {
   5.308 +	Node n=t;
   5.309 +	Number augment_value=free.get(t);
   5.310 +	while (res_graph.valid(pred.get(n))) { 
   5.311 +	  ResGWEdge e=pred.get(n);
   5.312 +	  res_graph.augment(e, augment_value); 
   5.313 +	  n=res_graph.tail(e);
   5.314 +	}
   5.315 +      }
   5.316 +
   5.317 +      return _augment;
   5.318 +    }
   5.319 +
   5.320 +    template<typename MapGraphWrapper> 
   5.321 +    class DistanceMap {
   5.322 +    protected:
   5.323 +      MapGraphWrapper gw;
   5.324 +      typename MapGraphWrapper::NodeMap<int> dist; 
   5.325 +    public:
   5.326 +      DistanceMap(MapGraphWrapper& _gw) : gw(_gw), dist(_gw, _gw.nodeNum()) { }
   5.327 +      void set(const typename MapGraphWrapper::Node& n, int a) { dist[n]=a; }
   5.328 +      int get(const typename MapGraphWrapper::Node& n) const { return dist[n]; }
   5.329 +      bool get(const typename MapGraphWrapper::Edge& e) const { 
   5.330 +	return (dist.get(gw.tail(e))<dist.get(gw.head(e))); 
   5.331 +      }
   5.332 +    };
   5.333 +
   5.334 +    template<typename MutableGraph> bool augmentOnBlockingFlow() {      
   5.335 +      typedef MutableGraph MG;
   5.336 +      bool _augment=false;
   5.337 +
   5.338 +      ResGW res_graph(gw, *flow, *capacity);
   5.339 +
   5.340 +      typedef typename ResGW::NodeMap<bool> ReachedMap;
   5.341 +      BfsIterator5< ResGW, ReachedMap > bfs(res_graph);
   5.342 +
   5.343 +      bfs.pushAndSetReached(s);
   5.344 +      //typename ResGW::NodeMap<int> dist(res_graph); //filled up with 0's
   5.345 +      DistanceMap<ResGW> dist(res_graph);
   5.346 +      while ( !bfs.finished() ) { 
   5.347 +	ResGWOutEdgeIt e=bfs;
   5.348 +	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   5.349 +	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
   5.350 +	}
   5.351 +	++bfs;
   5.352 +      } //computing distances from s in the residual graph
   5.353 +
   5.354 +      MG F;
   5.355 +      typedef SubGraphWrapper<ResGW, DistanceMap<ResGW> > FilterResGW;
   5.356 +      FilterResGW filter_res_graph(res_graph, dist);
   5.357 +      typename ResGW::NodeMap<typename MG::Node> res_graph_to_F(res_graph);
   5.358 +      {
   5.359 +	typename ResGW::NodeIt n;
   5.360 +	for(res_graph.first(n); res_graph.valid(n); res_graph.next(n)) {
   5.361 +	  res_graph_to_F.set(n, F.addNode());
   5.362 +	}
   5.363 +      }
   5.364 +
   5.365 +      typename MG::Node sF=res_graph_to_F.get(s);
   5.366 +      typename MG::Node tF=res_graph_to_F.get(t);
   5.367 +      typename MG::EdgeMap<ResGWEdge> original_edge(F);
   5.368 +      typename MG::EdgeMap<Number> residual_capacity(F);
   5.369 +
   5.370 +      //Making F to the graph containing the edges of the residual graph 
   5.371 +      //which are in some shortest paths
   5.372 +      {
   5.373 +	typename FilterResGW::EdgeIt e;
   5.374 +	for(filter_res_graph.first(e); filter_res_graph.valid(e); filter_res_graph.next(e)) {
   5.375 +	  //if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
   5.376 +	  typename MG::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
   5.377 +	  original_edge.update();
   5.378 +	  original_edge.set(f, e);
   5.379 +	  residual_capacity.update();
   5.380 +	  residual_capacity.set(f, res_graph.resCap(e));
   5.381 +	  //} 
   5.382 +	}
   5.383 +      }
   5.384 +
   5.385 +      bool __augment=true;
   5.386 +
   5.387 +      while (__augment) {
   5.388 +	__augment=false;
   5.389 +	//computing blocking flow with dfs
   5.390 +	typedef typename TrivGraphWrapper<MG>::NodeMap<bool> BlockingReachedMap;
   5.391 +	DfsIterator5< TrivGraphWrapper<MG>, BlockingReachedMap > dfs(F);
   5.392 +	typename MG::NodeMap<typename MG::Edge> pred(F);
   5.393 +	pred.set(sF, INVALID);
   5.394 +	//invalid iterators for sources
   5.395 +
   5.396 +	typename MG::NodeMap<Number> free(F);
   5.397 +
   5.398 +	dfs.pushAndSetReached(sF);      
   5.399 +	while (!dfs.finished()) {
   5.400 +	  ++dfs;
   5.401 +	  if (F.valid(/*typename MG::OutEdgeIt*/(dfs))) {
   5.402 +	    if (dfs.isBNodeNewlyReached()) {
   5.403 +	      typename MG::Node v=F.aNode(dfs);
   5.404 +	      typename MG::Node w=F.bNode(dfs);
   5.405 +	      pred.set(w, dfs);
   5.406 +	      if (F.valid(pred.get(v))) {
   5.407 +		free.set(w, std::min(free.get(v), residual_capacity.get(dfs)));
   5.408 +	      } else {
   5.409 +		free.set(w, residual_capacity.get(dfs)); 
   5.410 +	      }
   5.411 +	      if (w==tF) { 
   5.412 +		__augment=true; 
   5.413 +		_augment=true;
   5.414 +		break; 
   5.415 +	      }
   5.416 +	      
   5.417 +	    } else {
   5.418 +	      F.erase(/*typename MG::OutEdgeIt*/(dfs));
   5.419 +	    }
   5.420 +	  } 
   5.421 +	}
   5.422 +
   5.423 +	if (__augment) {
   5.424 +	  typename MG::Node n=tF;
   5.425 +	  Number augment_value=free.get(tF);
   5.426 +	  while (F.valid(pred.get(n))) { 
   5.427 +	    typename MG::Edge e=pred.get(n);
   5.428 +	    res_graph.augment(original_edge.get(e), augment_value); 
   5.429 +	    n=F.tail(e);
   5.430 +	    if (residual_capacity.get(e)==augment_value) 
   5.431 +	      F.erase(e); 
   5.432 +	    else 
   5.433 +	      residual_capacity.set(e, residual_capacity.get(e)-augment_value);
   5.434 +	  }
   5.435 +	}
   5.436 +	
   5.437 +      }
   5.438 +            
   5.439 +      return _augment;
   5.440 +    }
   5.441 +
   5.442 +    template<typename MutableGraph> bool augmentOnBlockingFlow1() {      
   5.443 +      typedef MutableGraph MG;
   5.444 +      bool _augment=false;
   5.445 +
   5.446 +      ResGW res_graph(gw, *flow, *capacity);
   5.447 +
   5.448 +      //bfs for distances on the residual graph
   5.449 +      typedef typename ResGW::NodeMap<bool> ReachedMap;
   5.450 +      BfsIterator5< ResGW, ReachedMap > bfs(res_graph);
   5.451 +      bfs.pushAndSetReached(s);
   5.452 +      typename ResGW::NodeMap<int> dist(res_graph); //filled up with 0's
   5.453 +
   5.454 +      //F will contain the physical copy of the residual graph
   5.455 +      //with the set of edges which are on shortest paths
   5.456 +      MG F;
   5.457 +      typename ResGW::NodeMap<typename MG::Node> res_graph_to_F(res_graph);
   5.458 +      {
   5.459 +	typename ResGW::NodeIt n;
   5.460 +	for(res_graph.first(n); res_graph.valid(n); res_graph.next(n)) {
   5.461 +	  res_graph_to_F.set(n, F.addNode());
   5.462 +	}
   5.463 +      }
   5.464 +
   5.465 +      typename MG::Node sF=res_graph_to_F.get(s);
   5.466 +      typename MG::Node tF=res_graph_to_F.get(t);
   5.467 +      typename MG::EdgeMap<ResGWEdge> original_edge(F);
   5.468 +      typename MG::EdgeMap<Number> residual_capacity(F);
   5.469 +
   5.470 +      while ( !bfs.finished() ) { 
   5.471 +	ResGWOutEdgeIt e=bfs;
   5.472 +	if (res_graph.valid(e)) {
   5.473 +	  if (bfs.isBNodeNewlyReached()) {
   5.474 +	    dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
   5.475 +	    typename MG::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
   5.476 +	    original_edge.update();
   5.477 +	    original_edge.set(f, e);
   5.478 +	    residual_capacity.update();
   5.479 +	    residual_capacity.set(f, res_graph.resCap(e));
   5.480 +	  } else {
   5.481 +	    if (dist.get(res_graph.head(e))==(dist.get(res_graph.tail(e))+1)) {
   5.482 +	      typename MG::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
   5.483 +	      original_edge.update();
   5.484 +	      original_edge.set(f, e);
   5.485 +	      residual_capacity.update();
   5.486 +	      residual_capacity.set(f, res_graph.resCap(e));
   5.487 +	    }
   5.488 +	  }
   5.489 +	}
   5.490 +	++bfs;
   5.491 +      } //computing distances from s in the residual graph
   5.492 +
   5.493 +      bool __augment=true;
   5.494 +
   5.495 +      while (__augment) {
   5.496 +	__augment=false;
   5.497 +	//computing blocking flow with dfs
   5.498 +	typedef typename TrivGraphWrapper<MG>::NodeMap<bool> BlockingReachedMap;
   5.499 +	DfsIterator5< TrivGraphWrapper<MG>, BlockingReachedMap > dfs(F);
   5.500 +	typename MG::NodeMap<typename MG::Edge> pred(F);
   5.501 +	pred.set(sF, INVALID);
   5.502 +	//invalid iterators for sources
   5.503 +
   5.504 +	typename MG::NodeMap<Number> free(F);
   5.505 +
   5.506 +	dfs.pushAndSetReached(sF);      
   5.507 +	while (!dfs.finished()) {
   5.508 +	  ++dfs;
   5.509 +	  if (F.valid(/*typename MG::OutEdgeIt*/(dfs))) {
   5.510 +	    if (dfs.isBNodeNewlyReached()) {
   5.511 +	      typename MG::Node v=F.aNode(dfs);
   5.512 +	      typename MG::Node w=F.bNode(dfs);
   5.513 +	      pred.set(w, dfs);
   5.514 +	      if (F.valid(pred.get(v))) {
   5.515 +		free.set(w, std::min(free.get(v), residual_capacity.get(dfs)));
   5.516 +	      } else {
   5.517 +		free.set(w, residual_capacity.get(dfs)); 
   5.518 +	      }
   5.519 +	      if (w==tF) { 
   5.520 +		__augment=true; 
   5.521 +		_augment=true;
   5.522 +		break; 
   5.523 +	      }
   5.524 +	      
   5.525 +	    } else {
   5.526 +	      F.erase(/*typename MG::OutEdgeIt*/(dfs));
   5.527 +	    }
   5.528 +	  } 
   5.529 +	}
   5.530 +
   5.531 +	if (__augment) {
   5.532 +	  typename MG::Node n=tF;
   5.533 +	  Number augment_value=free.get(tF);
   5.534 +	  while (F.valid(pred.get(n))) { 
   5.535 +	    typename MG::Edge e=pred.get(n);
   5.536 +	    res_graph.augment(original_edge.get(e), augment_value); 
   5.537 +	    n=F.tail(e);
   5.538 +	    if (residual_capacity.get(e)==augment_value) 
   5.539 +	      F.erase(e); 
   5.540 +	    else 
   5.541 +	      residual_capacity.set(e, residual_capacity.get(e)-augment_value);
   5.542 +	  }
   5.543 +	}
   5.544 +	
   5.545 +      }
   5.546 +            
   5.547 +      return _augment;
   5.548 +    }
   5.549 +
   5.550 +    bool augmentOnBlockingFlow2() {
   5.551 +      bool _augment=false;
   5.552 +
   5.553 +      ResGW res_graph(gw, *flow, *capacity);
   5.554 +
   5.555 +      typedef typename ResGW::NodeMap<bool> ReachedMap;
   5.556 +      BfsIterator5< ResGW, ReachedMap > bfs(res_graph);
   5.557 +
   5.558 +      bfs.pushAndSetReached(s);
   5.559 +      DistanceMap<ResGW> dist(res_graph);
   5.560 +      while ( !bfs.finished() ) { 
   5.561 + 	ResGWOutEdgeIt e=bfs;
   5.562 + 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   5.563 + 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
   5.564 + 	}
   5.565 +	++bfs;
   5.566 +      } //computing distances from s in the residual graph
   5.567 +
   5.568 +      //Subgraph containing the edges on some shortest paths
   5.569 +      typedef SubGraphWrapper<ResGW, DistanceMap<ResGW> > FilterResGW;
   5.570 +      FilterResGW filter_res_graph(res_graph, dist);
   5.571 +
   5.572 +      //Subgraph, which is able to delete edges which are already 
   5.573 +      //met by the dfs
   5.574 +      typename FilterResGW::NodeMap<typename FilterResGW::OutEdgeIt> 
   5.575 + 	first_out_edges(filter_res_graph);
   5.576 +      typename FilterResGW::NodeIt v;
   5.577 +      for(filter_res_graph.first(v); filter_res_graph.valid(v); 
   5.578 + 	  filter_res_graph.next(v)) 
   5.579 +      {
   5.580 + 	typename FilterResGW::OutEdgeIt e;
   5.581 + 	filter_res_graph.first(e, v);
   5.582 + 	first_out_edges.set(v, e);
   5.583 +      }
   5.584 +      typedef ErasingFirstGraphWrapper<FilterResGW, typename FilterResGW::
   5.585 +	NodeMap<typename FilterResGW::OutEdgeIt> > ErasingResGW;
   5.586 +      ErasingResGW erasing_res_graph(filter_res_graph, first_out_edges);
   5.587 +
   5.588 +      bool __augment=true;
   5.589 +
   5.590 +      while (__augment) {
   5.591 +
   5.592 + 	__augment=false;
   5.593 + 	//computing blocking flow with dfs
   5.594 +	typedef typename ErasingResGW::NodeMap<bool> BlockingReachedMap;
   5.595 + 	DfsIterator5< ErasingResGW, BlockingReachedMap > 
   5.596 + 	  dfs(erasing_res_graph);
   5.597 + 	typename ErasingResGW::NodeMap<typename ErasingResGW::OutEdgeIt> 
   5.598 + 	  pred(erasing_res_graph); 
   5.599 + 	pred.set(s, INVALID);
   5.600 + 	//invalid iterators for sources
   5.601 +
   5.602 + 	typename ErasingResGW::NodeMap<Number> free(erasing_res_graph);
   5.603 +
   5.604 + 	dfs.pushAndSetReached(s);
   5.605 + 	while (!dfs.finished()) {
   5.606 + 	  ++dfs;
   5.607 + 	  if (erasing_res_graph.valid(
   5.608 + 		/*typename ErasingResGW::OutEdgeIt*/(dfs))) 
   5.609 + 	  { 
   5.610 + 	    if (dfs.isBNodeNewlyReached()) {
   5.611 +	  
   5.612 + 	      typename ErasingResGW::Node v=erasing_res_graph.aNode(dfs);
   5.613 + 	      typename ErasingResGW::Node w=erasing_res_graph.bNode(dfs);
   5.614 +
   5.615 + 	      pred.set(w, /*typename ErasingResGW::OutEdgeIt*/(dfs));
   5.616 + 	      if (erasing_res_graph.valid(pred.get(v))) {
   5.617 + 		free.set(w, std::min(free.get(v), res_graph.resCap(dfs)));
   5.618 + 	      } else {
   5.619 + 		free.set(w, res_graph.resCap(dfs)); 
   5.620 + 	      }
   5.621 +	      
   5.622 + 	      if (w==t) { 
   5.623 + 		__augment=true; 
   5.624 + 		_augment=true;
   5.625 + 		break; 
   5.626 + 	      }
   5.627 +	    } else {
   5.628 +	      erasing_res_graph.erase(dfs);
   5.629 +	    }
   5.630 +	  }
   5.631 +	}	
   5.632 +
   5.633 + 	if (__augment) {
   5.634 + 	  typename ErasingResGW::Node n=t;
   5.635 + 	  Number augment_value=free.get(n);
   5.636 + 	  while (erasing_res_graph.valid(pred.get(n))) { 
   5.637 + 	    typename ErasingResGW::OutEdgeIt e=pred.get(n);
   5.638 + 	    res_graph.augment(e, augment_value);
   5.639 + 	    n=erasing_res_graph.tail(e);
   5.640 + 	    if (res_graph.resCap(e)==0)
   5.641 + 	      erasing_res_graph.erase(e);
   5.642 + 	  }
   5.643 + 	}
   5.644 +      
   5.645 +      } //while (__augment) 
   5.646 +            
   5.647 +      return _augment;
   5.648 +    }
   5.649 +
   5.650 +//     bool augmentOnBlockingFlow2() {
   5.651 +//       bool _augment=false;
   5.652 +
   5.653 +//       //typedef ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> EAugGraph;
   5.654 +//       typedef FilterGraphWrapper< ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > EAugGraph;
   5.655 +//       typedef typename EAugGraph::OutEdgeIt EAugOutEdgeIt;
   5.656 +//       typedef typename EAugGraph::Edge EAugEdge;
   5.657 +
   5.658 +//       EAugGraph res_graph(*G, *flow, *capacity);
   5.659 +
   5.660 +//       //typedef typename EAugGraph::NodeMap<bool> ReachedMap;
   5.661 +//       BfsIterator5< 
   5.662 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>, 
   5.663 +// 	/*typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt,*/ 
   5.664 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<bool> > bfs(res_graph);
   5.665 +      
   5.666 +//       bfs.pushAndSetReached(s);
   5.667 +
   5.668 +//       typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::
   5.669 +// 	NodeMap<int>& dist=res_graph.dist;
   5.670 +
   5.671 +//       while ( !bfs.finished() ) {
   5.672 +// 	typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt e=bfs;
   5.673 +// 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   5.674 +// 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
   5.675 +// 	}
   5.676 +// 	++bfs;	
   5.677 +//       } //computing distances from s in the residual graph
   5.678 +
   5.679 +//       bool __augment=true;
   5.680 +
   5.681 +//       while (__augment) {
   5.682 +
   5.683 +// 	__augment=false;
   5.684 +// 	//computing blocking flow with dfs
   5.685 +// 	typedef typename EAugGraph::NodeMap<bool> BlockingReachedMap;
   5.686 +// 	DfsIterator5< EAugGraph/*, EAugOutEdgeIt*/, BlockingReachedMap > 
   5.687 +// 	  dfs(res_graph);
   5.688 +// 	typename EAugGraph::NodeMap<EAugEdge> pred(res_graph); 
   5.689 +// 	pred.set(s, EAugEdge(INVALID));
   5.690 +// 	//invalid iterators for sources
   5.691 +
   5.692 +// 	typename EAugGraph::NodeMap<Number> free(res_graph);
   5.693 +
   5.694 +// 	dfs.pushAndSetReached(s);
   5.695 +// 	while (!dfs.finished()) {
   5.696 +// 	  ++dfs;
   5.697 +// 	  if (res_graph.valid(EAugOutEdgeIt(dfs))) { 
   5.698 +// 	    if (dfs.isBNodeNewlyReached()) {
   5.699 +	  
   5.700 +// 	      typename EAugGraph::Node v=res_graph.aNode(dfs);
   5.701 +// 	      typename EAugGraph::Node w=res_graph.bNode(dfs);
   5.702 +
   5.703 +// 	      pred.set(w, EAugOutEdgeIt(dfs));
   5.704 +// 	      if (res_graph.valid(pred.get(v))) {
   5.705 +// 		free.set(w, std::min(free.get(v), res_graph.free(dfs)));
   5.706 +// 	      } else {
   5.707 +// 		free.set(w, res_graph.free(dfs)); 
   5.708 +// 	      }
   5.709 +	      
   5.710 +// 	      if (w==t) { 
   5.711 +// 		__augment=true; 
   5.712 +// 		_augment=true;
   5.713 +// 		break; 
   5.714 +// 	      }
   5.715 +// 	    } else {
   5.716 +// 	      res_graph.erase(dfs);
   5.717 +// 	    }
   5.718 +// 	  } 
   5.719 +
   5.720 +// 	}
   5.721 +
   5.722 +// 	if (__augment) {
   5.723 +// 	  typename EAugGraph::Node n=t;
   5.724 +// 	  Number augment_value=free.get(t);
   5.725 +// 	  while (res_graph.valid(pred.get(n))) { 
   5.726 +// 	    EAugEdge e=pred.get(n);
   5.727 +// 	    res_graph.augment(e, augment_value);
   5.728 +// 	    n=res_graph.tail(e);
   5.729 +// 	    if (res_graph.free(e)==0)
   5.730 +// 	      res_graph.erase(e);
   5.731 +// 	  }
   5.732 +// 	}
   5.733 +      
   5.734 +//       }
   5.735 +            
   5.736 +//       return _augment;
   5.737 +//     }
   5.738 +
   5.739 +    void run() {
   5.740 +      //int num_of_augmentations=0;
   5.741 +      while (augmentOnShortestPath()) { 
   5.742 +	//while (augmentOnBlockingFlow<MutableGraph>()) { 
   5.743 +	//std::cout << ++num_of_augmentations << " ";
   5.744 +	//std::cout<<std::endl;
   5.745 +      } 
   5.746 +    }
   5.747 +
   5.748 +    template<typename MutableGraph> void run() {
   5.749 +      //int num_of_augmentations=0;
   5.750 +      //while (augmentOnShortestPath()) { 
   5.751 +	while (augmentOnBlockingFlow<MutableGraph>()) { 
   5.752 +	//std::cout << ++num_of_augmentations << " ";
   5.753 +	//std::cout<<std::endl;
   5.754 +      } 
   5.755 +    }
   5.756 +
   5.757 +    Number flowValue() { 
   5.758 +      Number a=0;
   5.759 +      OutEdgeIt e;
   5.760 +      for(gw.first(e, s); gw.valid(e); gw.next(e)) {
   5.761 +	a+=flow->get(e);
   5.762 +      }
   5.763 +      return a;
   5.764 +    }
   5.765 +
   5.766 +  };
   5.767 +
   5.768 +
   5.769 +//   template <typename Graph, typename Number, typename FlowMap, typename CapacityMap>
   5.770 +//   class MaxMatching {
   5.771 +//   public:
   5.772 +//     typedef typename Graph::Node Node;
   5.773 +//     typedef typename Graph::NodeIt NodeIt;
   5.774 +//     typedef typename Graph::Edge Edge;
   5.775 +//     typedef typename Graph::EdgeIt EdgeIt;
   5.776 +//     typedef typename Graph::OutEdgeIt OutEdgeIt;
   5.777 +//     typedef typename Graph::InEdgeIt InEdgeIt;
   5.778 +
   5.779 +//     typedef typename Graph::NodeMap<bool> SMap;
   5.780 +//     typedef typename Graph::NodeMap<bool> TMap;
   5.781 +//   private:
   5.782 +//     const Graph* G;
   5.783 +//     SMap* S;
   5.784 +//     TMap* T;
   5.785 +//     //Node s;
   5.786 +//     //Node t;
   5.787 +//     FlowMap* flow;
   5.788 +//     const CapacityMap* capacity;
   5.789 +//     typedef ResGraphWrapper<Graph, Number, FlowMap, CapacityMap > AugGraph;
   5.790 +//     typedef typename AugGraph::OutEdgeIt AugOutEdgeIt;
   5.791 +//     typedef typename AugGraph::Edge AugEdge;
   5.792 +//     typename Graph::NodeMap<int> used; //0
   5.793 +
   5.794 +//   public:
   5.795 +//     MaxMatching(const Graph& _G, SMap& _S, TMap& _T, FlowMap& _flow, const CapacityMap& _capacity) : 
   5.796 +//       G(&_G), S(&_S), T(&_T), flow(&_flow), capacity(&_capacity), used(_G) { }
   5.797 +//     bool augmentOnShortestPath() {
   5.798 +//       AugGraph res_graph(*G, *flow, *capacity);
   5.799 +//       bool _augment=false;
   5.800 +      
   5.801 +//       typedef typename AugGraph::NodeMap<bool> ReachedMap;
   5.802 +//       BfsIterator5< AugGraph, /*AugOutEdgeIt,*/ ReachedMap > bfs(res_graph);
   5.803 +//       typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
   5.804 +//       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
   5.805 +// 	if ((S->get(s)) && (used.get(s)<1) ) {
   5.806 +// 	  //Number u=0;
   5.807 +// 	  //for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
   5.808 +// 	  //u+=flow->get(e);
   5.809 +// 	  //if (u<1) {
   5.810 +// 	    bfs.pushAndSetReached(s);
   5.811 +// 	    pred.set(s, AugEdge(INVALID));
   5.812 +// 	    //}
   5.813 +// 	}
   5.814 +//       }
   5.815 +      
   5.816 +//       typename AugGraph::NodeMap<Number> free(res_graph);
   5.817 +	
   5.818 +//       Node n;
   5.819 +//       //searching for augmenting path
   5.820 +//       while ( !bfs.finished() ) { 
   5.821 +// 	AugOutEdgeIt e=bfs;
   5.822 +// 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   5.823 +// 	  Node v=res_graph.tail(e);
   5.824 +// 	  Node w=res_graph.head(e);
   5.825 +// 	  pred.set(w, e);
   5.826 +// 	  if (res_graph.valid(pred.get(v))) {
   5.827 +// 	    free.set(w, std::min(free.get(v), res_graph.free(e)));
   5.828 +// 	  } else {
   5.829 +// 	    free.set(w, res_graph.free(e)); 
   5.830 +// 	  }
   5.831 +// 	  n=res_graph.head(e);
   5.832 +// 	  if (T->get(n) && (used.get(n)<1) ) { 
   5.833 +// 	    //Number u=0;
   5.834 +// 	    //for(InEdgeIt f=G->template first<InEdgeIt>(n); G->valid(f); G->next(f))
   5.835 +// 	    //u+=flow->get(f);
   5.836 +// 	    //if (u<1) {
   5.837 +// 	      _augment=true; 
   5.838 +// 	      break; 
   5.839 +// 	      //}
   5.840 +// 	  }
   5.841 +// 	}
   5.842 +	
   5.843 +// 	++bfs;
   5.844 +//       } //end of searching augmenting path
   5.845 +
   5.846 +//       if (_augment) {
   5.847 +// 	//Node n=t;
   5.848 +// 	used.set(n, 1); //mind2 vegen jav
   5.849 +// 	Number augment_value=free.get(n);
   5.850 +// 	while (res_graph.valid(pred.get(n))) { 
   5.851 +// 	  AugEdge e=pred.get(n);
   5.852 +// 	  res_graph.augment(e, augment_value); 
   5.853 +// 	  n=res_graph.tail(e);
   5.854 +// 	}
   5.855 +// 	used.set(n, 1); //mind2 vegen jav
   5.856 +//       }
   5.857 +
   5.858 +//       return _augment;
   5.859 +//     }
   5.860 +
   5.861 +// //     template<typename MutableGraph> bool augmentOnBlockingFlow() {      
   5.862 +// //       bool _augment=false;
   5.863 +
   5.864 +// //       AugGraph res_graph(*G, *flow, *capacity);
   5.865 +
   5.866 +// //       typedef typename AugGraph::NodeMap<bool> ReachedMap;
   5.867 +// //       BfsIterator4< AugGraph, AugOutEdgeIt, ReachedMap > bfs(res_graph);
   5.868 +
   5.869 +
   5.870 +
   5.871 +
   5.872 +
   5.873 +// //       //typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
   5.874 +// //       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
   5.875 +// // 	if (S->get(s)) {
   5.876 +// // 	  Number u=0;
   5.877 +// // 	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
   5.878 +// // 	    u+=flow->get(e);
   5.879 +// // 	  if (u<1) {
   5.880 +// // 	    bfs.pushAndSetReached(s);
   5.881 +// // 	    //pred.set(s, AugEdge(INVALID));
   5.882 +// // 	  }
   5.883 +// // 	}
   5.884 +// //       }
   5.885 +
   5.886 +
   5.887 +
   5.888 +
   5.889 +// //       //bfs.pushAndSetReached(s);
   5.890 +// //       typename AugGraph::NodeMap<int> dist(res_graph); //filled up with 0's
   5.891 +// //       while ( !bfs.finished() ) { 
   5.892 +// // 	AugOutEdgeIt e=bfs;
   5.893 +// // 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   5.894 +// // 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
   5.895 +// // 	}
   5.896 +	
   5.897 +// // 	++bfs;
   5.898 +// //       } //computing distances from s in the residual graph
   5.899 +
   5.900 +// //       MutableGraph F;
   5.901 +// //       typename AugGraph::NodeMap<typename MutableGraph::Node> 
   5.902 +// // 	res_graph_to_F(res_graph);
   5.903 +// //       for(typename AugGraph::NodeIt n=res_graph.template first<typename AugGraph::NodeIt>(); res_graph.valid(n); res_graph.next(n)) {
   5.904 +// // 	res_graph_to_F.set(n, F.addNode());
   5.905 +// //       }
   5.906 +      
   5.907 +// //       typename MutableGraph::Node sF=res_graph_to_F.get(s);
   5.908 +// //       typename MutableGraph::Node tF=res_graph_to_F.get(t);
   5.909 +
   5.910 +// //       typename MutableGraph::EdgeMap<AugEdge> original_edge(F);
   5.911 +// //       typename MutableGraph::EdgeMap<Number> residual_capacity(F);
   5.912 +
   5.913 +// //       //Making F to the graph containing the edges of the residual graph 
   5.914 +// //       //which are in some shortest paths
   5.915 +// //       for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); res_graph.valid(e); res_graph.next(e)) {
   5.916 +// // 	if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
   5.917 +// // 	  typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
   5.918 +// // 	  original_edge.update();
   5.919 +// // 	  original_edge.set(f, e);
   5.920 +// // 	  residual_capacity.update();
   5.921 +// // 	  residual_capacity.set(f, res_graph.free(e));
   5.922 +// // 	} 
   5.923 +// //       }
   5.924 +
   5.925 +// //       bool __augment=true;
   5.926 +
   5.927 +// //       while (__augment) {
   5.928 +// // 	__augment=false;
   5.929 +// // 	//computing blocking flow with dfs
   5.930 +// // 	typedef typename MutableGraph::NodeMap<bool> BlockingReachedMap;
   5.931 +// // 	DfsIterator4< MutableGraph, typename MutableGraph::OutEdgeIt, BlockingReachedMap > dfs(F);
   5.932 +// // 	typename MutableGraph::NodeMap<typename MutableGraph::Edge> pred(F);
   5.933 +// // 	pred.set(sF, typename MutableGraph::Edge(INVALID));
   5.934 +// // 	//invalid iterators for sources
   5.935 +
   5.936 +// // 	typename MutableGraph::NodeMap<Number> free(F);
   5.937 +
   5.938 +// // 	dfs.pushAndSetReached(sF);      
   5.939 +// // 	while (!dfs.finished()) {
   5.940 +// // 	  ++dfs;
   5.941 +// // 	  if (F.valid(typename MutableGraph::OutEdgeIt(dfs))) {
   5.942 +// // 	    if (dfs.isBNodeNewlyReached()) {
   5.943 +// // 	      typename MutableGraph::Node v=F.aNode(dfs);
   5.944 +// // 	      typename MutableGraph::Node w=F.bNode(dfs);
   5.945 +// // 	      pred.set(w, dfs);
   5.946 +// // 	      if (F.valid(pred.get(v))) {
   5.947 +// // 		free.set(w, std::min(free.get(v), residual_capacity.get(dfs)));
   5.948 +// // 	      } else {
   5.949 +// // 		free.set(w, residual_capacity.get(dfs)); 
   5.950 +// // 	      }
   5.951 +// // 	      if (w==tF) { 
   5.952 +// // 		__augment=true; 
   5.953 +// // 		_augment=true;
   5.954 +// // 		break; 
   5.955 +// // 	      }
   5.956 +	      
   5.957 +// // 	    } else {
   5.958 +// // 	      F.erase(typename MutableGraph::OutEdgeIt(dfs));
   5.959 +// // 	    }
   5.960 +// // 	  } 
   5.961 +// // 	}
   5.962 +
   5.963 +// // 	if (__augment) {
   5.964 +// // 	  typename MutableGraph::Node n=tF;
   5.965 +// // 	  Number augment_value=free.get(tF);
   5.966 +// // 	  while (F.valid(pred.get(n))) { 
   5.967 +// // 	    typename MutableGraph::Edge e=pred.get(n);
   5.968 +// // 	    res_graph.augment(original_edge.get(e), augment_value); 
   5.969 +// // 	    n=F.tail(e);
   5.970 +// // 	    if (residual_capacity.get(e)==augment_value) 
   5.971 +// // 	      F.erase(e); 
   5.972 +// // 	    else 
   5.973 +// // 	      residual_capacity.set(e, residual_capacity.get(e)-augment_value);
   5.974 +// // 	  }
   5.975 +// // 	}
   5.976 +	
   5.977 +// //       }
   5.978 +            
   5.979 +// //       return _augment;
   5.980 +// //     }
   5.981 +//     bool augmentOnBlockingFlow2() {
   5.982 +//       bool _augment=false;
   5.983 +
   5.984 +//       //typedef ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> EAugGraph;
   5.985 +//       typedef FilterGraphWrapper< ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > EAugGraph;
   5.986 +//       typedef typename EAugGraph::OutEdgeIt EAugOutEdgeIt;
   5.987 +//       typedef typename EAugGraph::Edge EAugEdge;
   5.988 +
   5.989 +//       EAugGraph res_graph(*G, *flow, *capacity);
   5.990 +
   5.991 +//       //typedef typename EAugGraph::NodeMap<bool> ReachedMap;
   5.992 +//       BfsIterator5< 
   5.993 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>, 
   5.994 +// 	/*typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt,*/ 
   5.995 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<bool> > bfs(res_graph);
   5.996 +
   5.997 +
   5.998 +//       //typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
   5.999 +//       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
  5.1000 +// 	if (S->get(s)) {
  5.1001 +// 	  Number u=0;
  5.1002 +// 	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
  5.1003 +// 	    u+=flow->get(e);
  5.1004 +// 	  if (u<1) {
  5.1005 +// 	    bfs.pushAndSetReached(s);
  5.1006 +// 	    //pred.set(s, AugEdge(INVALID));
  5.1007 +// 	  }
  5.1008 +// 	}
  5.1009 +//       }
  5.1010 +
  5.1011 +      
  5.1012 +//       //bfs.pushAndSetReached(s);
  5.1013 +
  5.1014 +//       typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::
  5.1015 +// 	NodeMap<int>& dist=res_graph.dist;
  5.1016 +
  5.1017 +//       while ( !bfs.finished() ) {
  5.1018 +// 	typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt e=bfs;
  5.1019 +// 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
  5.1020 +// 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
  5.1021 +// 	}
  5.1022 +// 	++bfs;	
  5.1023 +//       } //computing distances from s in the residual graph
  5.1024 +
  5.1025 +//       bool __augment=true;
  5.1026 +
  5.1027 +//       while (__augment) {
  5.1028 +
  5.1029 +// 	__augment=false;
  5.1030 +// 	//computing blocking flow with dfs
  5.1031 +// 	typedef typename EAugGraph::NodeMap<bool> BlockingReachedMap;
  5.1032 +// 	DfsIterator5< EAugGraph/*, EAugOutEdgeIt*/, BlockingReachedMap > 
  5.1033 +// 	  dfs(res_graph);
  5.1034 +// 	typename EAugGraph::NodeMap<EAugEdge> pred(res_graph, INVALID); 
  5.1035 +// 	//pred.set(s, EAugEdge(INVALID));
  5.1036 +// 	//invalid iterators for sources
  5.1037 +
  5.1038 +// 	typename EAugGraph::NodeMap<Number> free(res_graph);
  5.1039 +
  5.1040 +
  5.1041 +// 	//typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
  5.1042 +//       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
  5.1043 +// 	if (S->get(s)) {
  5.1044 +// 	  Number u=0;
  5.1045 +// 	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
  5.1046 +// 	    u+=flow->get(e);
  5.1047 +// 	  if (u<1) {
  5.1048 +// 	    dfs.pushAndSetReached(s);
  5.1049 +// 	    //pred.set(s, AugEdge(INVALID));
  5.1050 +// 	  }
  5.1051 +// 	}
  5.1052 +//       }
  5.1053 +
  5.1054 +
  5.1055 +
  5.1056 +//       //dfs.pushAndSetReached(s);
  5.1057 +//       typename EAugGraph::Node n;
  5.1058 +// 	while (!dfs.finished()) {
  5.1059 +// 	  ++dfs;
  5.1060 +// 	  if (res_graph.valid(EAugOutEdgeIt(dfs))) { 
  5.1061 +// 	    if (dfs.isBNodeNewlyReached()) {
  5.1062 +	  
  5.1063 +// 	      typename EAugGraph::Node v=res_graph.aNode(dfs);
  5.1064 +// 	      typename EAugGraph::Node w=res_graph.bNode(dfs);
  5.1065 +
  5.1066 +// 	      pred.set(w, EAugOutEdgeIt(dfs));
  5.1067 +// 	      if (res_graph.valid(pred.get(v))) {
  5.1068 +// 		free.set(w, std::min(free.get(v), res_graph.free(dfs)));
  5.1069 +// 	      } else {
  5.1070 +// 		free.set(w, res_graph.free(dfs)); 
  5.1071 +// 	      }
  5.1072 +	     
  5.1073 +// 	      n=w;
  5.1074 +// 	      if (T->get(w)) {
  5.1075 +// 		Number u=0;
  5.1076 +// 		for(InEdgeIt f=G->template first<InEdgeIt>(n); G->valid(f); G->next(f))
  5.1077 +// 		  u+=flow->get(f);
  5.1078 +// 		if (u<1) {
  5.1079 +// 		  __augment=true; 
  5.1080 +// 		  _augment=true;
  5.1081 +// 		  break; 
  5.1082 +// 		}
  5.1083 +// 	      }
  5.1084 +// 	    } else {
  5.1085 +// 	      res_graph.erase(dfs);
  5.1086 +// 	    }
  5.1087 +// 	  } 
  5.1088 +
  5.1089 +// 	}
  5.1090 +
  5.1091 +// 	if (__augment) {
  5.1092 +// 	  // typename EAugGraph::Node n=t;
  5.1093 +// 	  Number augment_value=free.get(n);
  5.1094 +// 	  while (res_graph.valid(pred.get(n))) { 
  5.1095 +// 	    EAugEdge e=pred.get(n);
  5.1096 +// 	    res_graph.augment(e, augment_value);
  5.1097 +// 	    n=res_graph.tail(e);
  5.1098 +// 	    if (res_graph.free(e)==0)
  5.1099 +// 	      res_graph.erase(e);
  5.1100 +// 	  }
  5.1101 +// 	}
  5.1102 +      
  5.1103 +//       }
  5.1104 +            
  5.1105 +//       return _augment;
  5.1106 +//     }
  5.1107 +//     void run() {
  5.1108 +//       //int num_of_augmentations=0;
  5.1109 +//       while (augmentOnShortestPath()) { 
  5.1110 +// 	//while (augmentOnBlockingFlow<MutableGraph>()) { 
  5.1111 +// 	//std::cout << ++num_of_augmentations << " ";
  5.1112 +// 	//std::cout<<std::endl;
  5.1113 +//       } 
  5.1114 +//     }
  5.1115 +// //     template<typename MutableGraph> void run() {
  5.1116 +// //       //int num_of_augmentations=0;
  5.1117 +// //       //while (augmentOnShortestPath()) { 
  5.1118 +// // 	while (augmentOnBlockingFlow<MutableGraph>()) { 
  5.1119 +// // 	//std::cout << ++num_of_augmentations << " ";
  5.1120 +// // 	//std::cout<<std::endl;
  5.1121 +// //       } 
  5.1122 +// //     } 
  5.1123 +//     Number flowValue() { 
  5.1124 +//       Number a=0;
  5.1125 +//       EdgeIt e;
  5.1126 +//       for(G->/*getF*/first(e); G->valid(e); G->next(e)) {
  5.1127 +// 	a+=flow->get(e);
  5.1128 +//       }
  5.1129 +//       return a;
  5.1130 +//     }
  5.1131 +//   };
  5.1132 +
  5.1133 +
  5.1134 +
  5.1135 +
  5.1136 +
  5.1137 +  
  5.1138 +// //   template <typename Graph, typename Number, typename FlowMap, typename CapacityMap>
  5.1139 +// //   class MaxFlow2 {
  5.1140 +// //   public:
  5.1141 +// //     typedef typename Graph::Node Node;
  5.1142 +// //     typedef typename Graph::Edge Edge;
  5.1143 +// //     typedef typename Graph::EdgeIt EdgeIt;
  5.1144 +// //     typedef typename Graph::OutEdgeIt OutEdgeIt;
  5.1145 +// //     typedef typename Graph::InEdgeIt InEdgeIt;
  5.1146 +// //   private:
  5.1147 +// //     const Graph& G;
  5.1148 +// //     std::list<Node>& S;
  5.1149 +// //     std::list<Node>& T;
  5.1150 +// //     FlowMap& flow;
  5.1151 +// //     const CapacityMap& capacity;
  5.1152 +// //     typedef ResGraphWrapper<Graph, Number, FlowMap, CapacityMap > AugGraph;
  5.1153 +// //     typedef typename AugGraph::OutEdgeIt AugOutEdgeIt;
  5.1154 +// //     typedef typename AugGraph::Edge AugEdge;
  5.1155 +// //     typename Graph::NodeMap<bool> SMap;
  5.1156 +// //     typename Graph::NodeMap<bool> TMap;
  5.1157 +// //   public:
  5.1158 +// //     MaxFlow2(const Graph& _G, std::list<Node>& _S, std::list<Node>& _T, FlowMap& _flow, const CapacityMap& _capacity) : G(_G), S(_S), T(_T), flow(_flow), capacity(_capacity), SMap(_G), TMap(_G) { 
  5.1159 +// //       for(typename std::list<Node>::const_iterator i=S.begin(); 
  5.1160 +// // 	  i!=S.end(); ++i) { 
  5.1161 +// // 	SMap.set(*i, true); 
  5.1162 +// //       }
  5.1163 +// //       for (typename std::list<Node>::const_iterator i=T.begin(); 
  5.1164 +// // 	   i!=T.end(); ++i) { 
  5.1165 +// // 	TMap.set(*i, true); 
  5.1166 +// //       }
  5.1167 +// //     }
  5.1168 +// //     bool augment() {
  5.1169 +// //       AugGraph res_graph(G, flow, capacity);
  5.1170 +// //       bool _augment=false;
  5.1171 +// //       Node reached_t_node;
  5.1172 +      
  5.1173 +// //       typedef typename AugGraph::NodeMap<bool> ReachedMap;
  5.1174 +// //       BfsIterator4< AugGraph, AugOutEdgeIt, ReachedMap > bfs(res_graph);
  5.1175 +// //       for(typename std::list<Node>::const_iterator i=S.begin(); 
  5.1176 +// // 	  i!=S.end(); ++i) {
  5.1177 +// // 	bfs.pushAndSetReached(*i);
  5.1178 +// //       }
  5.1179 +// //       //bfs.pushAndSetReached(s);
  5.1180 +	
  5.1181 +// //       typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
  5.1182 +// //       //filled up with invalid iterators
  5.1183 +      
  5.1184 +// //       typename AugGraph::NodeMap<Number> free(res_graph);
  5.1185 +	
  5.1186 +// //       //searching for augmenting path
  5.1187 +// //       while ( !bfs.finished() ) { 
  5.1188 +// // 	AugOutEdgeIt e=/*AugOutEdgeIt*/(bfs);
  5.1189 +// // 	if (e.valid() && bfs.isBNodeNewlyReached()) {
  5.1190 +// // 	  Node v=res_graph.tail(e);
  5.1191 +// // 	  Node w=res_graph.head(e);
  5.1192 +// // 	  pred.set(w, e);
  5.1193 +// // 	  if (pred.get(v).valid()) {
  5.1194 +// // 	    free.set(w, std::min(free.get(v), e.free()));
  5.1195 +// // 	  } else {
  5.1196 +// // 	    free.set(w, e.free()); 
  5.1197 +// // 	  }
  5.1198 +// // 	  if (TMap.get(res_graph.head(e))) { 
  5.1199 +// // 	    _augment=true; 
  5.1200 +// // 	    reached_t_node=res_graph.head(e);
  5.1201 +// // 	    break; 
  5.1202 +// // 	  }
  5.1203 +// // 	}
  5.1204 +	
  5.1205 +// // 	++bfs;
  5.1206 +// //       } //end of searching augmenting path
  5.1207 +
  5.1208 +// //       if (_augment) {
  5.1209 +// // 	Node n=reached_t_node;
  5.1210 +// // 	Number augment_value=free.get(reached_t_node);
  5.1211 +// // 	while (pred.get(n).valid()) { 
  5.1212 +// // 	  AugEdge e=pred.get(n);
  5.1213 +// // 	  e.augment(augment_value); 
  5.1214 +// // 	  n=res_graph.tail(e);
  5.1215 +// // 	}
  5.1216 +// //       }
  5.1217 +
  5.1218 +// //       return _augment;
  5.1219 +// //     }
  5.1220 +// //     void run() {
  5.1221 +// //       while (augment()) { } 
  5.1222 +// //     }
  5.1223 +// //     Number flowValue() { 
  5.1224 +// //       Number a=0;
  5.1225 +// //       for(typename std::list<Node>::const_iterator i=S.begin(); 
  5.1226 +// // 	  i!=S.end(); ++i) { 
  5.1227 +// // 	for(OutEdgeIt e=G.template first<OutEdgeIt>(*i); e.valid(); ++e) {
  5.1228 +// // 	  a+=flow.get(e);
  5.1229 +// // 	}
  5.1230 +// // 	for(InEdgeIt e=G.template first<InEdgeIt>(*i); e.valid(); ++e) {
  5.1231 +// // 	  a-=flow.get(e);
  5.1232 +// // 	}
  5.1233 +// //       }
  5.1234 +// //       return a;
  5.1235 +// //     }
  5.1236 +// //   };
  5.1237 +
  5.1238 +
  5.1239 +} // namespace hugo
  5.1240 +
  5.1241 +#endif //HUGO_EDMONDS_KARP_H
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/work/marci/experiment/edmonds_karp_1.h	Sat Apr 03 17:26:46 2004 +0000
     6.3 @@ -0,0 +1,1240 @@
     6.4 +// -*- c++ -*-
     6.5 +#ifndef HUGO_EDMONDS_KARP_H
     6.6 +#define HUGO_EDMONDS_KARP_H
     6.7 +
     6.8 +#include <algorithm>
     6.9 +#include <list>
    6.10 +#include <iterator>
    6.11 +
    6.12 +#include <bfs_iterator_1.h>
    6.13 +#include <invalid.h>
    6.14 +#include <graph_wrapper_1.h>
    6.15 +
    6.16 +namespace hugo {
    6.17 +
    6.18 +  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
    6.19 +  class ResGraph {
    6.20 +  public:
    6.21 +    typedef typename Graph::Node Node;
    6.22 +    typedef typename Graph::NodeIt NodeIt;
    6.23 +  private:
    6.24 +    typedef typename Graph::SymEdgeIt OldSymEdgeIt;
    6.25 +    const Graph& G;
    6.26 +    FlowMap& flow;
    6.27 +    const CapacityMap& capacity;
    6.28 +  public:
    6.29 +    ResGraph(const Graph& _G, FlowMap& _flow, 
    6.30 +	     const CapacityMap& _capacity) : 
    6.31 +      G(_G), flow(_flow), capacity(_capacity) { }
    6.32 +
    6.33 +    class Edge; 
    6.34 +    class OutEdgeIt; 
    6.35 +    friend class Edge; 
    6.36 +    friend class OutEdgeIt; 
    6.37 +
    6.38 +    class Edge {
    6.39 +      friend class ResGraph<Graph, Number, FlowMap, CapacityMap>;
    6.40 +    protected:
    6.41 +      const ResGraph<Graph, Number, FlowMap, CapacityMap>* resG;
    6.42 +      OldSymEdgeIt sym;
    6.43 +    public:
    6.44 +      Edge() { } 
    6.45 +      //Edge(const Edge& e) : resG(e.resG), sym(e.sym) { }
    6.46 +      Number free() const { 
    6.47 +	if (resG->G.aNode(sym)==resG->G.tail(sym)) { 
    6.48 +	  return (resG->capacity.get(sym)-resG->flow.get(sym)); 
    6.49 +	} else { 
    6.50 +	  return (resG->flow.get(sym)); 
    6.51 +	}
    6.52 +      }
    6.53 +      bool valid() const { return sym.valid(); }
    6.54 +      void augment(Number a) const {
    6.55 +	if (resG->G.aNode(sym)==resG->G.tail(sym)) { 
    6.56 +	  resG->flow.set(sym, resG->flow.get(sym)+a);
    6.57 +	  //resG->flow[sym]+=a;
    6.58 +	} else { 
    6.59 +	  resG->flow.set(sym, resG->flow.get(sym)-a);
    6.60 +	  //resG->flow[sym]-=a;
    6.61 +	}
    6.62 +      }
    6.63 +    };
    6.64 +
    6.65 +    class OutEdgeIt : public Edge {
    6.66 +      friend class ResGraph<Graph, Number, FlowMap, CapacityMap>;
    6.67 +    public:
    6.68 +      OutEdgeIt() { }
    6.69 +      //OutEdgeIt(const OutEdgeIt& e) { resG=e.resG; sym=e.sym; }
    6.70 +    private:
    6.71 +      OutEdgeIt(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _resG, Node v) { 
    6.72 +      	resG=&_resG;
    6.73 +	sym=resG->G.template first<OldSymEdgeIt>(v);
    6.74 +	while( sym.valid() && !(free()>0) ) { ++sym; }
    6.75 +      }
    6.76 +    public:
    6.77 +      OutEdgeIt& operator++() { 
    6.78 +	++sym; 
    6.79 +	while( sym.valid() && !(free()>0) ) { ++sym; }
    6.80 +	return *this; 
    6.81 +      }
    6.82 +    };
    6.83 +
    6.84 +    void /*getF*/first(OutEdgeIt& e, Node v) const { 
    6.85 +      e=OutEdgeIt(*this, v); 
    6.86 +    }
    6.87 +    void /*getF*/first(NodeIt& v) const { G./*getF*/first(v); }
    6.88 +    
    6.89 +    template< typename It >
    6.90 +    It first() const { 
    6.91 +      It e;      
    6.92 +      /*getF*/first(e);
    6.93 +      return e; 
    6.94 +    }
    6.95 +
    6.96 +    template< typename It >
    6.97 +    It first(Node v) const { 
    6.98 +      It e;
    6.99 +      /*getF*/first(e, v);
   6.100 +      return e; 
   6.101 +    }
   6.102 +
   6.103 +    Node tail(Edge e) const { return G.aNode(e.sym); }
   6.104 +    Node head(Edge e) const { return G.bNode(e.sym); }
   6.105 +
   6.106 +    Node aNode(OutEdgeIt e) const { return G.aNode(e.sym); }
   6.107 +    Node bNode(OutEdgeIt e) const { return G.bNode(e.sym); }
   6.108 +
   6.109 +    int id(Node v) const { return G.id(v); }
   6.110 +
   6.111 +    template <typename S>
   6.112 +    class NodeMap {
   6.113 +      typename Graph::NodeMap<S> node_map; 
   6.114 +    public:
   6.115 +      NodeMap(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(_G.G) { }
   6.116 +      NodeMap(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _G, S a) : node_map(_G.G, a) { }
   6.117 +      void set(Node nit, S a) { node_map.set(nit, a); }
   6.118 +      S get(Node nit) const { return node_map.get(nit); }
   6.119 +      S& operator[](Node nit) { return node_map[nit]; } 
   6.120 +      const S& operator[](Node nit) const { return node_map[nit]; } 
   6.121 +    };
   6.122 +
   6.123 +  };
   6.124 +
   6.125 +
   6.126 +  template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
   6.127 +  class ResGraph2 {
   6.128 +  public:
   6.129 +    typedef typename Graph::Node Node;
   6.130 +    typedef typename Graph::NodeIt NodeIt;
   6.131 +  private:
   6.132 +    //typedef typename Graph::SymEdgeIt OldSymEdgeIt;
   6.133 +    typedef typename Graph::OutEdgeIt OldOutEdgeIt;
   6.134 +    typedef typename Graph::InEdgeIt OldInEdgeIt;
   6.135 +    
   6.136 +    const Graph& G;
   6.137 +    FlowMap& flow;
   6.138 +    const CapacityMap& capacity;
   6.139 +  public:
   6.140 +    ResGraph2(const Graph& _G, FlowMap& _flow, 
   6.141 +	     const CapacityMap& _capacity) : 
   6.142 +      G(_G), flow(_flow), capacity(_capacity) { }
   6.143 +
   6.144 +    class Edge; 
   6.145 +    class OutEdgeIt; 
   6.146 +    friend class Edge; 
   6.147 +    friend class OutEdgeIt; 
   6.148 +
   6.149 +    class Edge {
   6.150 +      friend class ResGraph2<Graph, Number, FlowMap, CapacityMap>;
   6.151 +    protected:
   6.152 +      const ResGraph2<Graph, Number, FlowMap, CapacityMap>* resG;
   6.153 +      //OldSymEdgeIt sym;
   6.154 +      OldOutEdgeIt out;
   6.155 +      OldInEdgeIt in;
   6.156 +      bool out_or_in; //true, iff out
   6.157 +    public:
   6.158 +      Edge() : out_or_in(true) { } 
   6.159 +      Number free() const { 
   6.160 +	if (out_or_in) { 
   6.161 +	  return (resG->capacity.get(out)-resG->flow.get(out)); 
   6.162 +	} else { 
   6.163 +	  return (resG->flow.get(in)); 
   6.164 +	}
   6.165 +      }
   6.166 +      bool valid() const { 
   6.167 +	return out_or_in && out.valid() || in.valid(); }
   6.168 +      void augment(Number a) const {
   6.169 +	if (out_or_in) { 
   6.170 +	  resG->flow.set(out, resG->flow.get(out)+a);
   6.171 +	} else { 
   6.172 +	  resG->flow.set(in, resG->flow.get(in)-a);
   6.173 +	}
   6.174 +      }
   6.175 +    };
   6.176 +
   6.177 +    class OutEdgeIt : public Edge {
   6.178 +      friend class ResGraph2<Graph, Number, FlowMap, CapacityMap>;
   6.179 +    public:
   6.180 +      OutEdgeIt() { }
   6.181 +    private:
   6.182 +      OutEdgeIt(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _resG, Node v) { 
   6.183 +      	resG=&_resG;
   6.184 +	out=resG->G.template first<OldOutEdgeIt>(v);
   6.185 +	while( out.valid() && !(free()>0) ) { ++out; }
   6.186 +	if (!out.valid()) {
   6.187 +	  out_or_in=0;
   6.188 +	  in=resG->G.template first<OldInEdgeIt>(v);
   6.189 +	  while( in.valid() && !(free()>0) ) { ++in; }
   6.190 +	}
   6.191 +      }
   6.192 +    public:
   6.193 +      OutEdgeIt& operator++() { 
   6.194 +	if (out_or_in) {
   6.195 +	  Node v=resG->G.aNode(out);
   6.196 +	  ++out;
   6.197 +	  while( out.valid() && !(free()>0) ) { ++out; }
   6.198 +	  if (!out.valid()) {
   6.199 +	    out_or_in=0;
   6.200 +	    in=resG->G.template first<OldInEdgeIt>(v);
   6.201 +	    while( in.valid() && !(free()>0) ) { ++in; }
   6.202 +	  }
   6.203 +	} else {
   6.204 +	  ++in;
   6.205 +	  while( in.valid() && !(free()>0) ) { ++in; } 
   6.206 +	}
   6.207 +	return *this; 
   6.208 +      }
   6.209 +    };
   6.210 +
   6.211 +    void /*getF*/first(OutEdgeIt& e, Node v) const { 
   6.212 +      e=OutEdgeIt(*this, v); 
   6.213 +    }
   6.214 +    void /*getF*/first(NodeIt& v) const { G./*getF*/first(v); }
   6.215 +    
   6.216 +    template< typename It >
   6.217 +    It first() const { 
   6.218 +      It e;
   6.219 +      /*getF*/first(e);
   6.220 +      return e; 
   6.221 +    }
   6.222 +
   6.223 +    template< typename It >
   6.224 +    It first(Node v) const { 
   6.225 +      It e;
   6.226 +      /*getF*/first(e, v);
   6.227 +      return e; 
   6.228 +    }
   6.229 +
   6.230 +    Node tail(Edge e) const { 
   6.231 +      return ((e.out_or_in) ? G.aNode(e.out) : G.aNode(e.in)); }
   6.232 +    Node head(Edge e) const { 
   6.233 +      return ((e.out_or_in) ? G.bNode(e.out) : G.bNode(e.in)); }
   6.234 +
   6.235 +    Node aNode(OutEdgeIt e) const { 
   6.236 +      return ((e.out_or_in) ? G.aNode(e.out) : G.aNode(e.in)); }
   6.237 +    Node bNode(OutEdgeIt e) const { 
   6.238 +      return ((e.out_or_in) ? G.bNode(e.out) : G.bNode(e.in)); }
   6.239 +
   6.240 +    int id(Node v) const { return G.id(v); }
   6.241 +
   6.242 +    template <typename S>
   6.243 +    class NodeMap {
   6.244 +      typename Graph::NodeMap<S> node_map; 
   6.245 +    public:
   6.246 +      NodeMap(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(_G.G) { }
   6.247 +      NodeMap(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _G, S a) : node_map(_G.G, a) { }
   6.248 +      void set(Node nit, S a) { node_map.set(nit, a); }
   6.249 +      S get(Node nit) const { return node_map.get(nit); }
   6.250 +    };
   6.251 +  };
   6.252 +
   6.253 +
   6.254 +  template <typename GraphWrapper, typename Number, typename FlowMap, typename CapacityMap>
   6.255 +  class MaxFlow {
   6.256 +  protected:
   6.257 +    typedef GraphWrapper GW;
   6.258 +    typedef typename GW::Node Node;
   6.259 +    typedef typename GW::Edge Edge;
   6.260 +    typedef typename GW::EdgeIt EdgeIt;
   6.261 +    typedef typename GW::OutEdgeIt OutEdgeIt;
   6.262 +    typedef typename GW::InEdgeIt InEdgeIt;
   6.263 +    //const Graph* G;
   6.264 +    //GW gw;
   6.265 +    const GW* g;
   6.266 +    Node s;
   6.267 +    Node t;
   6.268 +    FlowMap* flow;
   6.269 +    const CapacityMap* capacity;
   6.270 +    typedef ResGraphWrapper<const GW, Number, FlowMap, CapacityMap > ResGW;
   6.271 +    typedef typename ResGW::OutEdgeIt ResGWOutEdgeIt;
   6.272 +    typedef typename ResGW::Edge ResGWEdge;
   6.273 +  public:
   6.274 +
   6.275 +    MaxFlow(const GW& _g, Node _s, Node _t, FlowMap& _flow, const CapacityMap& _capacity) : 
   6.276 +      g(&_g), s(_s), t(_t), flow(&_flow), capacity(&_capacity) { }
   6.277 +
   6.278 +    bool augmentOnShortestPath() {
   6.279 +      ResGW res_graph(*g, *flow, *capacity);
   6.280 +      bool _augment=false;
   6.281 +      
   6.282 +      typedef typename ResGW::NodeMap<bool> ReachedMap;
   6.283 +      BfsIterator5< ResGW, ReachedMap > bfs(res_graph);
   6.284 +      bfs.pushAndSetReached(s);
   6.285 +	
   6.286 +      typename ResGW::NodeMap<ResGWEdge> pred(res_graph); 
   6.287 +      pred.set(s, INVALID);
   6.288 +      
   6.289 +      typename ResGW::NodeMap<Number> free(res_graph);
   6.290 +	
   6.291 +      //searching for augmenting path
   6.292 +      while ( !bfs.finished() ) { 
   6.293 +	ResGWOutEdgeIt e=bfs;
   6.294 +	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   6.295 +	  Node v=res_graph.tail(e);
   6.296 +	  Node w=res_graph.head(e);
   6.297 +	  pred.set(w, e);
   6.298 +	  if (res_graph.valid(pred.get(v))) {
   6.299 +	    free.set(w, std::min(free.get(v), res_graph.resCap(e)));
   6.300 +	  } else {
   6.301 +	    free.set(w, res_graph.resCap(e)); 
   6.302 +	  }
   6.303 +	  if (res_graph.head(e)==t) { _augment=true; break; }
   6.304 +	}
   6.305 +	
   6.306 +	++bfs;
   6.307 +      } //end of searching augmenting path
   6.308 +
   6.309 +      if (_augment) {
   6.310 +	Node n=t;
   6.311 +	Number augment_value=free.get(t);
   6.312 +	while (res_graph.valid(pred.get(n))) { 
   6.313 +	  ResGWEdge e=pred.get(n);
   6.314 +	  res_graph.augment(e, augment_value); 
   6.315 +	  n=res_graph.tail(e);
   6.316 +	}
   6.317 +      }
   6.318 +
   6.319 +      return _augment;
   6.320 +    }
   6.321 +
   6.322 +    template<typename MapGraphWrapper> 
   6.323 +    class DistanceMap {
   6.324 +    protected:
   6.325 +      const MapGraphWrapper* g;
   6.326 +      typename MapGraphWrapper::NodeMap<int> dist; 
   6.327 +    public:
   6.328 +      DistanceMap(MapGraphWrapper& _g) : g(&_g), dist(*g, g->nodeNum()) { }
   6.329 +      void set(const typename MapGraphWrapper::Node& n, int a) { dist[n]=a; }
   6.330 +      int get(const typename MapGraphWrapper::Node& n) const { return dist[n]; }
   6.331 +      bool get(const typename MapGraphWrapper::Edge& e) const { 
   6.332 +	return (dist.get(g->tail(e))<dist.get(g->head(e))); 
   6.333 +      }
   6.334 +    };
   6.335 +
   6.336 +    template<typename MutableGraph> bool augmentOnBlockingFlow() {      
   6.337 +      typedef MutableGraph MG;
   6.338 +      bool _augment=false;
   6.339 +
   6.340 +      ResGW res_graph(*g, *flow, *capacity);
   6.341 +
   6.342 +      typedef typename ResGW::NodeMap<bool> ReachedMap;
   6.343 +      BfsIterator5< ResGW, ReachedMap > bfs(res_graph);
   6.344 +
   6.345 +      bfs.pushAndSetReached(s);
   6.346 +      //typename ResGW::NodeMap<int> dist(res_graph); //filled up with 0's
   6.347 +      DistanceMap<ResGW> dist(res_graph);
   6.348 +      while ( !bfs.finished() ) { 
   6.349 +	ResGWOutEdgeIt e=bfs;
   6.350 +	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   6.351 +	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
   6.352 +	}
   6.353 +	++bfs;
   6.354 +      } //computing distances from s in the residual graph
   6.355 +
   6.356 +      MG F;
   6.357 +      typedef SubGraphWrapper<ResGW, DistanceMap<ResGW> > FilterResGW;
   6.358 +      FilterResGW filter_res_graph(res_graph, dist);
   6.359 +      typename ResGW::NodeMap<typename MG::Node> res_graph_to_F(res_graph);
   6.360 +      {
   6.361 +	typename ResGW::NodeIt n;
   6.362 +	for(res_graph.first(n); res_graph.valid(n); res_graph.next(n)) {
   6.363 +	  res_graph_to_F.set(n, F.addNode());
   6.364 +	}
   6.365 +      }
   6.366 +
   6.367 +      typename MG::Node sF=res_graph_to_F.get(s);
   6.368 +      typename MG::Node tF=res_graph_to_F.get(t);
   6.369 +      typename MG::EdgeMap<ResGWEdge> original_edge(F);
   6.370 +      typename MG::EdgeMap<Number> residual_capacity(F);
   6.371 +
   6.372 +      //Making F to the graph containing the edges of the residual graph 
   6.373 +      //which are in some shortest paths
   6.374 +      {
   6.375 +	typename FilterResGW::EdgeIt e;
   6.376 +	for(filter_res_graph.first(e); filter_res_graph.valid(e); filter_res_graph.next(e)) {
   6.377 +	  //if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
   6.378 +	  typename MG::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
   6.379 +	  original_edge.update();
   6.380 +	  original_edge.set(f, e);
   6.381 +	  residual_capacity.update();
   6.382 +	  residual_capacity.set(f, res_graph.resCap(e));
   6.383 +	  //} 
   6.384 +	}
   6.385 +      }
   6.386 +
   6.387 +      bool __augment=true;
   6.388 +
   6.389 +      while (__augment) {
   6.390 +	__augment=false;
   6.391 +	//computing blocking flow with dfs
   6.392 +	typedef typename TrivGraphWrapper<MG>::NodeMap<bool> BlockingReachedMap;
   6.393 +	DfsIterator5< TrivGraphWrapper<MG>, BlockingReachedMap > dfs(F);
   6.394 +	typename MG::NodeMap<typename MG::Edge> pred(F);
   6.395 +	pred.set(sF, INVALID);
   6.396 +	//invalid iterators for sources
   6.397 +
   6.398 +	typename MG::NodeMap<Number> free(F);
   6.399 +
   6.400 +	dfs.pushAndSetReached(sF);      
   6.401 +	while (!dfs.finished()) {
   6.402 +	  ++dfs;
   6.403 +	  if (F.valid(/*typename MG::OutEdgeIt*/(dfs))) {
   6.404 +	    if (dfs.isBNodeNewlyReached()) {
   6.405 +	      typename MG::Node v=F.aNode(dfs);
   6.406 +	      typename MG::Node w=F.bNode(dfs);
   6.407 +	      pred.set(w, dfs);
   6.408 +	      if (F.valid(pred.get(v))) {
   6.409 +		free.set(w, std::min(free.get(v), residual_capacity.get(dfs)));
   6.410 +	      } else {
   6.411 +		free.set(w, residual_capacity.get(dfs)); 
   6.412 +	      }
   6.413 +	      if (w==tF) { 
   6.414 +		__augment=true; 
   6.415 +		_augment=true;
   6.416 +		break; 
   6.417 +	      }
   6.418 +	      
   6.419 +	    } else {
   6.420 +	      F.erase(/*typename MG::OutEdgeIt*/(dfs));
   6.421 +	    }
   6.422 +	  } 
   6.423 +	}
   6.424 +
   6.425 +	if (__augment) {
   6.426 +	  typename MG::Node n=tF;
   6.427 +	  Number augment_value=free.get(tF);
   6.428 +	  while (F.valid(pred.get(n))) { 
   6.429 +	    typename MG::Edge e=pred.get(n);
   6.430 +	    res_graph.augment(original_edge.get(e), augment_value); 
   6.431 +	    n=F.tail(e);
   6.432 +	    if (residual_capacity.get(e)==augment_value) 
   6.433 +	      F.erase(e); 
   6.434 +	    else 
   6.435 +	      residual_capacity.set(e, residual_capacity.get(e)-augment_value);
   6.436 +	  }
   6.437 +	}
   6.438 +	
   6.439 +      }
   6.440 +            
   6.441 +      return _augment;
   6.442 +    }
   6.443 +
   6.444 +    template<typename MutableGraph> bool augmentOnBlockingFlow1() {      
   6.445 +      typedef MutableGraph MG;
   6.446 +      bool _augment=false;
   6.447 +
   6.448 +      ResGW res_graph(*g, *flow, *capacity);
   6.449 +
   6.450 +      //bfs for distances on the residual graph
   6.451 +      typedef typename ResGW::NodeMap<bool> ReachedMap;
   6.452 +      BfsIterator5< ResGW, ReachedMap > bfs(res_graph);
   6.453 +      bfs.pushAndSetReached(s);
   6.454 +      typename ResGW::NodeMap<int> dist(res_graph); //filled up with 0's
   6.455 +
   6.456 +      //F will contain the physical copy of the residual graph
   6.457 +      //with the set of edges which are on shortest paths
   6.458 +      MG F;
   6.459 +      typename ResGW::NodeMap<typename MG::Node> res_graph_to_F(res_graph);
   6.460 +      {
   6.461 +	typename ResGW::NodeIt n;
   6.462 +	for(res_graph.first(n); res_graph.valid(n); res_graph.next(n)) {
   6.463 +	  res_graph_to_F.set(n, F.addNode());
   6.464 +	}
   6.465 +      }
   6.466 +
   6.467 +      typename MG::Node sF=res_graph_to_F.get(s);
   6.468 +      typename MG::Node tF=res_graph_to_F.get(t);
   6.469 +      typename MG::EdgeMap<ResGWEdge> original_edge(F);
   6.470 +      typename MG::EdgeMap<Number> residual_capacity(F);
   6.471 +
   6.472 +      while ( !bfs.finished() ) { 
   6.473 +	ResGWOutEdgeIt e=bfs;
   6.474 +	if (res_graph.valid(e)) {
   6.475 +	  if (bfs.isBNodeNewlyReached()) {
   6.476 +	    dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
   6.477 +	    typename MG::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
   6.478 +	    original_edge.update();
   6.479 +	    original_edge.set(f, e);
   6.480 +	    residual_capacity.update();
   6.481 +	    residual_capacity.set(f, res_graph.resCap(e));
   6.482 +	  } else {
   6.483 +	    if (dist.get(res_graph.head(e))==(dist.get(res_graph.tail(e))+1)) {
   6.484 +	      typename MG::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
   6.485 +	      original_edge.update();
   6.486 +	      original_edge.set(f, e);
   6.487 +	      residual_capacity.update();
   6.488 +	      residual_capacity.set(f, res_graph.resCap(e));
   6.489 +	    }
   6.490 +	  }
   6.491 +	}
   6.492 +	++bfs;
   6.493 +      } //computing distances from s in the residual graph
   6.494 +
   6.495 +      bool __augment=true;
   6.496 +
   6.497 +      while (__augment) {
   6.498 +	__augment=false;
   6.499 +	//computing blocking flow with dfs
   6.500 +	typedef typename TrivGraphWrapper<MG>::NodeMap<bool> BlockingReachedMap;
   6.501 +	DfsIterator5< TrivGraphWrapper<MG>, BlockingReachedMap > dfs(F);
   6.502 +	typename MG::NodeMap<typename MG::Edge> pred(F);
   6.503 +	pred.set(sF, INVALID);
   6.504 +	//invalid iterators for sources
   6.505 +
   6.506 +	typename MG::NodeMap<Number> free(F);
   6.507 +
   6.508 +	dfs.pushAndSetReached(sF);      
   6.509 +	while (!dfs.finished()) {
   6.510 +	  ++dfs;
   6.511 +	  if (F.valid(/*typename MG::OutEdgeIt*/(dfs))) {
   6.512 +	    if (dfs.isBNodeNewlyReached()) {
   6.513 +	      typename MG::Node v=F.aNode(dfs);
   6.514 +	      typename MG::Node w=F.bNode(dfs);
   6.515 +	      pred.set(w, dfs);
   6.516 +	      if (F.valid(pred.get(v))) {
   6.517 +		free.set(w, std::min(free.get(v), residual_capacity.get(dfs)));
   6.518 +	      } else {
   6.519 +		free.set(w, residual_capacity.get(dfs)); 
   6.520 +	      }
   6.521 +	      if (w==tF) { 
   6.522 +		__augment=true; 
   6.523 +		_augment=true;
   6.524 +		break; 
   6.525 +	      }
   6.526 +	      
   6.527 +	    } else {
   6.528 +	      F.erase(/*typename MG::OutEdgeIt*/(dfs));
   6.529 +	    }
   6.530 +	  } 
   6.531 +	}
   6.532 +
   6.533 +	if (__augment) {
   6.534 +	  typename MG::Node n=tF;
   6.535 +	  Number augment_value=free.get(tF);
   6.536 +	  while (F.valid(pred.get(n))) { 
   6.537 +	    typename MG::Edge e=pred.get(n);
   6.538 +	    res_graph.augment(original_edge.get(e), augment_value); 
   6.539 +	    n=F.tail(e);
   6.540 +	    if (residual_capacity.get(e)==augment_value) 
   6.541 +	      F.erase(e); 
   6.542 +	    else 
   6.543 +	      residual_capacity.set(e, residual_capacity.get(e)-augment_value);
   6.544 +	  }
   6.545 +	}
   6.546 +	
   6.547 +      }
   6.548 +            
   6.549 +      return _augment;
   6.550 +    }
   6.551 +
   6.552 +    bool augmentOnBlockingFlow2() {
   6.553 +      bool _augment=false;
   6.554 +
   6.555 +      ResGW res_graph(*g, *flow, *capacity);
   6.556 +
   6.557 +      typedef typename ResGW::NodeMap<bool> ReachedMap;
   6.558 +      BfsIterator5< ResGW, ReachedMap > bfs(res_graph);
   6.559 +
   6.560 +      bfs.pushAndSetReached(s);
   6.561 +      DistanceMap<ResGW> dist(res_graph);
   6.562 +      while ( !bfs.finished() ) { 
   6.563 + 	ResGWOutEdgeIt e=bfs;
   6.564 + 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   6.565 + 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
   6.566 + 	}
   6.567 +	++bfs;
   6.568 +      } //computing distances from s in the residual graph
   6.569 +
   6.570 +      //Subgraph containing the edges on some shortest paths
   6.571 +      typedef SubGraphWrapper<ResGW, DistanceMap<ResGW> > FilterResGW;
   6.572 +      FilterResGW filter_res_graph(res_graph, dist);
   6.573 +
   6.574 +      //Subgraph, which is able to delete edges which are already 
   6.575 +      //met by the dfs
   6.576 +      typename FilterResGW::NodeMap<typename FilterResGW::OutEdgeIt> 
   6.577 + 	first_out_edges(filter_res_graph);
   6.578 +      typename FilterResGW::NodeIt v;
   6.579 +      for(filter_res_graph.first(v); filter_res_graph.valid(v); 
   6.580 + 	  filter_res_graph.next(v)) 
   6.581 +      {
   6.582 + 	typename FilterResGW::OutEdgeIt e;
   6.583 + 	filter_res_graph.first(e, v);
   6.584 + 	first_out_edges.set(v, e);
   6.585 +      }
   6.586 +      typedef ErasingFirstGraphWrapper<FilterResGW, typename FilterResGW::
   6.587 +	NodeMap<typename FilterResGW::OutEdgeIt> > ErasingResGW;
   6.588 +      ErasingResGW erasing_res_graph(filter_res_graph, first_out_edges);
   6.589 +
   6.590 +      bool __augment=true;
   6.591 +
   6.592 +      while (__augment) {
   6.593 +
   6.594 + 	__augment=false;
   6.595 + 	//computing blocking flow with dfs
   6.596 +	typedef typename ErasingResGW::NodeMap<bool> BlockingReachedMap;
   6.597 + 	DfsIterator5< ErasingResGW, BlockingReachedMap > 
   6.598 + 	  dfs(erasing_res_graph);
   6.599 + 	typename ErasingResGW::NodeMap<typename ErasingResGW::OutEdgeIt> 
   6.600 + 	  pred(erasing_res_graph); 
   6.601 + 	pred.set(s, INVALID);
   6.602 + 	//invalid iterators for sources
   6.603 +
   6.604 + 	typename ErasingResGW::NodeMap<Number> free(erasing_res_graph);
   6.605 +
   6.606 + 	dfs.pushAndSetReached(s);
   6.607 + 	while (!dfs.finished()) {
   6.608 + 	  ++dfs;
   6.609 + 	  if (erasing_res_graph.valid(
   6.610 + 		/*typename ErasingResGW::OutEdgeIt*/(dfs))) 
   6.611 + 	  { 
   6.612 + 	    if (dfs.isBNodeNewlyReached()) {
   6.613 +	  
   6.614 + 	      typename ErasingResGW::Node v=erasing_res_graph.aNode(dfs);
   6.615 + 	      typename ErasingResGW::Node w=erasing_res_graph.bNode(dfs);
   6.616 +
   6.617 + 	      pred.set(w, /*typename ErasingResGW::OutEdgeIt*/(dfs));
   6.618 + 	      if (erasing_res_graph.valid(pred.get(v))) {
   6.619 + 		free.set(w, std::min(free.get(v), res_graph.resCap(dfs)));
   6.620 + 	      } else {
   6.621 + 		free.set(w, res_graph.resCap(dfs)); 
   6.622 + 	      }
   6.623 +	      
   6.624 + 	      if (w==t) { 
   6.625 + 		__augment=true; 
   6.626 + 		_augment=true;
   6.627 + 		break; 
   6.628 + 	      }
   6.629 +	    } else {
   6.630 +	      erasing_res_graph.erase(dfs);
   6.631 +	    }
   6.632 +	  }
   6.633 +	}	
   6.634 +
   6.635 + 	if (__augment) {
   6.636 + 	  typename ErasingResGW::Node n=t;
   6.637 + 	  Number augment_value=free.get(n);
   6.638 + 	  while (erasing_res_graph.valid(pred.get(n))) { 
   6.639 + 	    typename ErasingResGW::OutEdgeIt e=pred.get(n);
   6.640 + 	    res_graph.augment(e, augment_value);
   6.641 + 	    n=erasing_res_graph.tail(e);
   6.642 + 	    if (res_graph.resCap(e)==0)
   6.643 + 	      erasing_res_graph.erase(e);
   6.644 + 	  }
   6.645 + 	}
   6.646 +      
   6.647 +      } //while (__augment) 
   6.648 +            
   6.649 +      return _augment;
   6.650 +    }
   6.651 +
   6.652 +//     bool augmentOnBlockingFlow2() {
   6.653 +//       bool _augment=false;
   6.654 +
   6.655 +//       //typedef ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> EAugGraph;
   6.656 +//       typedef FilterGraphWrapper< ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > EAugGraph;
   6.657 +//       typedef typename EAugGraph::OutEdgeIt EAugOutEdgeIt;
   6.658 +//       typedef typename EAugGraph::Edge EAugEdge;
   6.659 +
   6.660 +//       EAugGraph res_graph(*G, *flow, *capacity);
   6.661 +
   6.662 +//       //typedef typename EAugGraph::NodeMap<bool> ReachedMap;
   6.663 +//       BfsIterator5< 
   6.664 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>, 
   6.665 +// 	/*typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt,*/ 
   6.666 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<bool> > bfs(res_graph);
   6.667 +      
   6.668 +//       bfs.pushAndSetReached(s);
   6.669 +
   6.670 +//       typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::
   6.671 +// 	NodeMap<int>& dist=res_graph.dist;
   6.672 +
   6.673 +//       while ( !bfs.finished() ) {
   6.674 +// 	typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt e=bfs;
   6.675 +// 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   6.676 +// 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
   6.677 +// 	}
   6.678 +// 	++bfs;	
   6.679 +//       } //computing distances from s in the residual graph
   6.680 +
   6.681 +//       bool __augment=true;
   6.682 +
   6.683 +//       while (__augment) {
   6.684 +
   6.685 +// 	__augment=false;
   6.686 +// 	//computing blocking flow with dfs
   6.687 +// 	typedef typename EAugGraph::NodeMap<bool> BlockingReachedMap;
   6.688 +// 	DfsIterator5< EAugGraph/*, EAugOutEdgeIt*/, BlockingReachedMap > 
   6.689 +// 	  dfs(res_graph);
   6.690 +// 	typename EAugGraph::NodeMap<EAugEdge> pred(res_graph); 
   6.691 +// 	pred.set(s, EAugEdge(INVALID));
   6.692 +// 	//invalid iterators for sources
   6.693 +
   6.694 +// 	typename EAugGraph::NodeMap<Number> free(res_graph);
   6.695 +
   6.696 +// 	dfs.pushAndSetReached(s);
   6.697 +// 	while (!dfs.finished()) {
   6.698 +// 	  ++dfs;
   6.699 +// 	  if (res_graph.valid(EAugOutEdgeIt(dfs))) { 
   6.700 +// 	    if (dfs.isBNodeNewlyReached()) {
   6.701 +	  
   6.702 +// 	      typename EAugGraph::Node v=res_graph.aNode(dfs);
   6.703 +// 	      typename EAugGraph::Node w=res_graph.bNode(dfs);
   6.704 +
   6.705 +// 	      pred.set(w, EAugOutEdgeIt(dfs));
   6.706 +// 	      if (res_graph.valid(pred.get(v))) {
   6.707 +// 		free.set(w, std::min(free.get(v), res_graph.free(dfs)));
   6.708 +// 	      } else {
   6.709 +// 		free.set(w, res_graph.free(dfs)); 
   6.710 +// 	      }
   6.711 +	      
   6.712 +// 	      if (w==t) { 
   6.713 +// 		__augment=true; 
   6.714 +// 		_augment=true;
   6.715 +// 		break; 
   6.716 +// 	      }
   6.717 +// 	    } else {
   6.718 +// 	      res_graph.erase(dfs);
   6.719 +// 	    }
   6.720 +// 	  } 
   6.721 +
   6.722 +// 	}
   6.723 +
   6.724 +// 	if (__augment) {
   6.725 +// 	  typename EAugGraph::Node n=t;
   6.726 +// 	  Number augment_value=free.get(t);
   6.727 +// 	  while (res_graph.valid(pred.get(n))) { 
   6.728 +// 	    EAugEdge e=pred.get(n);
   6.729 +// 	    res_graph.augment(e, augment_value);
   6.730 +// 	    n=res_graph.tail(e);
   6.731 +// 	    if (res_graph.free(e)==0)
   6.732 +// 	      res_graph.erase(e);
   6.733 +// 	  }
   6.734 +// 	}
   6.735 +      
   6.736 +//       }
   6.737 +            
   6.738 +//       return _augment;
   6.739 +//     }
   6.740 +
   6.741 +    void run() {
   6.742 +      //int num_of_augmentations=0;
   6.743 +      while (augmentOnShortestPath()) { 
   6.744 +	//while (augmentOnBlockingFlow<MutableGraph>()) { 
   6.745 +	//std::cout << ++num_of_augmentations << " ";
   6.746 +	//std::cout<<std::endl;
   6.747 +      } 
   6.748 +    }
   6.749 +
   6.750 +    template<typename MutableGraph> void run() {
   6.751 +      //int num_of_augmentations=0;
   6.752 +      //while (augmentOnShortestPath()) { 
   6.753 +	while (augmentOnBlockingFlow<MutableGraph>()) { 
   6.754 +	//std::cout << ++num_of_augmentations << " ";
   6.755 +	//std::cout<<std::endl;
   6.756 +      } 
   6.757 +    }
   6.758 +
   6.759 +    Number flowValue() { 
   6.760 +      Number a=0;
   6.761 +      OutEdgeIt e;
   6.762 +      for(g->first(e, s); g->valid(e); g->next(e)) {
   6.763 +	a+=flow->get(e);
   6.764 +      }
   6.765 +      return a;
   6.766 +    }
   6.767 +
   6.768 +  };
   6.769 +
   6.770 +
   6.771 +//   template <typename Graph, typename Number, typename FlowMap, typename CapacityMap>
   6.772 +//   class MaxMatching {
   6.773 +//   public:
   6.774 +//     typedef typename Graph::Node Node;
   6.775 +//     typedef typename Graph::NodeIt NodeIt;
   6.776 +//     typedef typename Graph::Edge Edge;
   6.777 +//     typedef typename Graph::EdgeIt EdgeIt;
   6.778 +//     typedef typename Graph::OutEdgeIt OutEdgeIt;
   6.779 +//     typedef typename Graph::InEdgeIt InEdgeIt;
   6.780 +
   6.781 +//     typedef typename Graph::NodeMap<bool> SMap;
   6.782 +//     typedef typename Graph::NodeMap<bool> TMap;
   6.783 +//   private:
   6.784 +//     const Graph* G;
   6.785 +//     SMap* S;
   6.786 +//     TMap* T;
   6.787 +//     //Node s;
   6.788 +//     //Node t;
   6.789 +//     FlowMap* flow;
   6.790 +//     const CapacityMap* capacity;
   6.791 +//     typedef ResGraphWrapper<Graph, Number, FlowMap, CapacityMap > AugGraph;
   6.792 +//     typedef typename AugGraph::OutEdgeIt AugOutEdgeIt;
   6.793 +//     typedef typename AugGraph::Edge AugEdge;
   6.794 +//     typename Graph::NodeMap<int> used; //0
   6.795 +
   6.796 +//   public:
   6.797 +//     MaxMatching(const Graph& _G, SMap& _S, TMap& _T, FlowMap& _flow, const CapacityMap& _capacity) : 
   6.798 +//       G(&_G), S(&_S), T(&_T), flow(&_flow), capacity(&_capacity), used(_G) { }
   6.799 +//     bool augmentOnShortestPath() {
   6.800 +//       AugGraph res_graph(*G, *flow, *capacity);
   6.801 +//       bool _augment=false;
   6.802 +      
   6.803 +//       typedef typename AugGraph::NodeMap<bool> ReachedMap;
   6.804 +//       BfsIterator5< AugGraph, /*AugOutEdgeIt,*/ ReachedMap > bfs(res_graph);
   6.805 +//       typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
   6.806 +//       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
   6.807 +// 	if ((S->get(s)) && (used.get(s)<1) ) {
   6.808 +// 	  //Number u=0;
   6.809 +// 	  //for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
   6.810 +// 	  //u+=flow->get(e);
   6.811 +// 	  //if (u<1) {
   6.812 +// 	    bfs.pushAndSetReached(s);
   6.813 +// 	    pred.set(s, AugEdge(INVALID));
   6.814 +// 	    //}
   6.815 +// 	}
   6.816 +//       }
   6.817 +      
   6.818 +//       typename AugGraph::NodeMap<Number> free(res_graph);
   6.819 +	
   6.820 +//       Node n;
   6.821 +//       //searching for augmenting path
   6.822 +//       while ( !bfs.finished() ) { 
   6.823 +// 	AugOutEdgeIt e=bfs;
   6.824 +// 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   6.825 +// 	  Node v=res_graph.tail(e);
   6.826 +// 	  Node w=res_graph.head(e);
   6.827 +// 	  pred.set(w, e);
   6.828 +// 	  if (res_graph.valid(pred.get(v))) {
   6.829 +// 	    free.set(w, std::min(free.get(v), res_graph.free(e)));
   6.830 +// 	  } else {
   6.831 +// 	    free.set(w, res_graph.free(e)); 
   6.832 +// 	  }
   6.833 +// 	  n=res_graph.head(e);
   6.834 +// 	  if (T->get(n) && (used.get(n)<1) ) { 
   6.835 +// 	    //Number u=0;
   6.836 +// 	    //for(InEdgeIt f=G->template first<InEdgeIt>(n); G->valid(f); G->next(f))
   6.837 +// 	    //u+=flow->get(f);
   6.838 +// 	    //if (u<1) {
   6.839 +// 	      _augment=true; 
   6.840 +// 	      break; 
   6.841 +// 	      //}
   6.842 +// 	  }
   6.843 +// 	}
   6.844 +	
   6.845 +// 	++bfs;
   6.846 +//       } //end of searching augmenting path
   6.847 +
   6.848 +//       if (_augment) {
   6.849 +// 	//Node n=t;
   6.850 +// 	used.set(n, 1); //mind2 vegen jav
   6.851 +// 	Number augment_value=free.get(n);
   6.852 +// 	while (res_graph.valid(pred.get(n))) { 
   6.853 +// 	  AugEdge e=pred.get(n);
   6.854 +// 	  res_graph.augment(e, augment_value); 
   6.855 +// 	  n=res_graph.tail(e);
   6.856 +// 	}
   6.857 +// 	used.set(n, 1); //mind2 vegen jav
   6.858 +//       }
   6.859 +
   6.860 +//       return _augment;
   6.861 +//     }
   6.862 +
   6.863 +// //     template<typename MutableGraph> bool augmentOnBlockingFlow() {      
   6.864 +// //       bool _augment=false;
   6.865 +
   6.866 +// //       AugGraph res_graph(*G, *flow, *capacity);
   6.867 +
   6.868 +// //       typedef typename AugGraph::NodeMap<bool> ReachedMap;
   6.869 +// //       BfsIterator4< AugGraph, AugOutEdgeIt, ReachedMap > bfs(res_graph);
   6.870 +
   6.871 +
   6.872 +
   6.873 +
   6.874 +
   6.875 +// //       //typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
   6.876 +// //       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
   6.877 +// // 	if (S->get(s)) {
   6.878 +// // 	  Number u=0;
   6.879 +// // 	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
   6.880 +// // 	    u+=flow->get(e);
   6.881 +// // 	  if (u<1) {
   6.882 +// // 	    bfs.pushAndSetReached(s);
   6.883 +// // 	    //pred.set(s, AugEdge(INVALID));
   6.884 +// // 	  }
   6.885 +// // 	}
   6.886 +// //       }
   6.887 +
   6.888 +
   6.889 +
   6.890 +
   6.891 +// //       //bfs.pushAndSetReached(s);
   6.892 +// //       typename AugGraph::NodeMap<int> dist(res_graph); //filled up with 0's
   6.893 +// //       while ( !bfs.finished() ) { 
   6.894 +// // 	AugOutEdgeIt e=bfs;
   6.895 +// // 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
   6.896 +// // 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
   6.897 +// // 	}
   6.898 +	
   6.899 +// // 	++bfs;
   6.900 +// //       } //computing distances from s in the residual graph
   6.901 +
   6.902 +// //       MutableGraph F;
   6.903 +// //       typename AugGraph::NodeMap<typename MutableGraph::Node> 
   6.904 +// // 	res_graph_to_F(res_graph);
   6.905 +// //       for(typename AugGraph::NodeIt n=res_graph.template first<typename AugGraph::NodeIt>(); res_graph.valid(n); res_graph.next(n)) {
   6.906 +// // 	res_graph_to_F.set(n, F.addNode());
   6.907 +// //       }
   6.908 +      
   6.909 +// //       typename MutableGraph::Node sF=res_graph_to_F.get(s);
   6.910 +// //       typename MutableGraph::Node tF=res_graph_to_F.get(t);
   6.911 +
   6.912 +// //       typename MutableGraph::EdgeMap<AugEdge> original_edge(F);
   6.913 +// //       typename MutableGraph::EdgeMap<Number> residual_capacity(F);
   6.914 +
   6.915 +// //       //Making F to the graph containing the edges of the residual graph 
   6.916 +// //       //which are in some shortest paths
   6.917 +// //       for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); res_graph.valid(e); res_graph.next(e)) {
   6.918 +// // 	if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
   6.919 +// // 	  typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
   6.920 +// // 	  original_edge.update();
   6.921 +// // 	  original_edge.set(f, e);
   6.922 +// // 	  residual_capacity.update();
   6.923 +// // 	  residual_capacity.set(f, res_graph.free(e));
   6.924 +// // 	} 
   6.925 +// //       }
   6.926 +
   6.927 +// //       bool __augment=true;
   6.928 +
   6.929 +// //       while (__augment) {
   6.930 +// // 	__augment=false;
   6.931 +// // 	//computing blocking flow with dfs
   6.932 +// // 	typedef typename MutableGraph::NodeMap<bool> BlockingReachedMap;
   6.933 +// // 	DfsIterator4< MutableGraph, typename MutableGraph::OutEdgeIt, BlockingReachedMap > dfs(F);
   6.934 +// // 	typename MutableGraph::NodeMap<typename MutableGraph::Edge> pred(F);
   6.935 +// // 	pred.set(sF, typename MutableGraph::Edge(INVALID));
   6.936 +// // 	//invalid iterators for sources
   6.937 +
   6.938 +// // 	typename MutableGraph::NodeMap<Number> free(F);
   6.939 +
   6.940 +// // 	dfs.pushAndSetReached(sF);      
   6.941 +// // 	while (!dfs.finished()) {
   6.942 +// // 	  ++dfs;
   6.943 +// // 	  if (F.valid(typename MutableGraph::OutEdgeIt(dfs))) {
   6.944 +// // 	    if (dfs.isBNodeNewlyReached()) {
   6.945 +// // 	      typename MutableGraph::Node v=F.aNode(dfs);
   6.946 +// // 	      typename MutableGraph::Node w=F.bNode(dfs);
   6.947 +// // 	      pred.set(w, dfs);
   6.948 +// // 	      if (F.valid(pred.get(v))) {
   6.949 +// // 		free.set(w, std::min(free.get(v), residual_capacity.get(dfs)));
   6.950 +// // 	      } else {
   6.951 +// // 		free.set(w, residual_capacity.get(dfs)); 
   6.952 +// // 	      }
   6.953 +// // 	      if (w==tF) { 
   6.954 +// // 		__augment=true; 
   6.955 +// // 		_augment=true;
   6.956 +// // 		break; 
   6.957 +// // 	      }
   6.958 +	      
   6.959 +// // 	    } else {
   6.960 +// // 	      F.erase(typename MutableGraph::OutEdgeIt(dfs));
   6.961 +// // 	    }
   6.962 +// // 	  } 
   6.963 +// // 	}
   6.964 +
   6.965 +// // 	if (__augment) {
   6.966 +// // 	  typename MutableGraph::Node n=tF;
   6.967 +// // 	  Number augment_value=free.get(tF);
   6.968 +// // 	  while (F.valid(pred.get(n))) { 
   6.969 +// // 	    typename MutableGraph::Edge e=pred.get(n);
   6.970 +// // 	    res_graph.augment(original_edge.get(e), augment_value); 
   6.971 +// // 	    n=F.tail(e);
   6.972 +// // 	    if (residual_capacity.get(e)==augment_value) 
   6.973 +// // 	      F.erase(e); 
   6.974 +// // 	    else 
   6.975 +// // 	      residual_capacity.set(e, residual_capacity.get(e)-augment_value);
   6.976 +// // 	  }
   6.977 +// // 	}
   6.978 +	
   6.979 +// //       }
   6.980 +            
   6.981 +// //       return _augment;
   6.982 +// //     }
   6.983 +//     bool augmentOnBlockingFlow2() {
   6.984 +//       bool _augment=false;
   6.985 +
   6.986 +//       //typedef ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> EAugGraph;
   6.987 +//       typedef FilterGraphWrapper< ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > EAugGraph;
   6.988 +//       typedef typename EAugGraph::OutEdgeIt EAugOutEdgeIt;
   6.989 +//       typedef typename EAugGraph::Edge EAugEdge;
   6.990 +
   6.991 +//       EAugGraph res_graph(*G, *flow, *capacity);
   6.992 +
   6.993 +//       //typedef typename EAugGraph::NodeMap<bool> ReachedMap;
   6.994 +//       BfsIterator5< 
   6.995 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>, 
   6.996 +// 	/*typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt,*/ 
   6.997 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<bool> > bfs(res_graph);
   6.998 +
   6.999 +
  6.1000 +//       //typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
  6.1001 +//       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
  6.1002 +// 	if (S->get(s)) {
  6.1003 +// 	  Number u=0;
  6.1004 +// 	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
  6.1005 +// 	    u+=flow->get(e);
  6.1006 +// 	  if (u<1) {
  6.1007 +// 	    bfs.pushAndSetReached(s);
  6.1008 +// 	    //pred.set(s, AugEdge(INVALID));
  6.1009 +// 	  }
  6.1010 +// 	}
  6.1011 +//       }
  6.1012 +
  6.1013 +      
  6.1014 +//       //bfs.pushAndSetReached(s);
  6.1015 +
  6.1016 +//       typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::
  6.1017 +// 	NodeMap<int>& dist=res_graph.dist;
  6.1018 +
  6.1019 +//       while ( !bfs.finished() ) {
  6.1020 +// 	typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt e=bfs;
  6.1021 +// 	if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
  6.1022 +// 	  dist.set(res_graph.head(e), dist.get(res_graph.tail(e))+1);
  6.1023 +// 	}
  6.1024 +// 	++bfs;	
  6.1025 +//       } //computing distances from s in the residual graph
  6.1026 +
  6.1027 +//       bool __augment=true;
  6.1028 +
  6.1029 +//       while (__augment) {
  6.1030 +
  6.1031 +// 	__augment=false;
  6.1032 +// 	//computing blocking flow with dfs
  6.1033 +// 	typedef typename EAugGraph::NodeMap<bool> BlockingReachedMap;
  6.1034 +// 	DfsIterator5< EAugGraph/*, EAugOutEdgeIt*/, BlockingReachedMap > 
  6.1035 +// 	  dfs(res_graph);
  6.1036 +// 	typename EAugGraph::NodeMap<EAugEdge> pred(res_graph, INVALID); 
  6.1037 +// 	//pred.set(s, EAugEdge(INVALID));
  6.1038 +// 	//invalid iterators for sources
  6.1039 +
  6.1040 +// 	typename EAugGraph::NodeMap<Number> free(res_graph);
  6.1041 +
  6.1042 +
  6.1043 +// 	//typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
  6.1044 +//       for(NodeIt s=G->template first<NodeIt>(); G->valid(s); G->next(s)) {
  6.1045 +// 	if (S->get(s)) {
  6.1046 +// 	  Number u=0;
  6.1047 +// 	  for(OutEdgeIt e=G->template first<OutEdgeIt>(s); G->valid(e); G->next(e))
  6.1048 +// 	    u+=flow->get(e);
  6.1049 +// 	  if (u<1) {
  6.1050 +// 	    dfs.pushAndSetReached(s);
  6.1051 +// 	    //pred.set(s, AugEdge(INVALID));
  6.1052 +// 	  }
  6.1053 +// 	}
  6.1054 +//       }
  6.1055 +
  6.1056 +
  6.1057 +
  6.1058 +//       //dfs.pushAndSetReached(s);
  6.1059 +//       typename EAugGraph::Node n;
  6.1060 +// 	while (!dfs.finished()) {
  6.1061 +// 	  ++dfs;
  6.1062 +// 	  if (res_graph.valid(EAugOutEdgeIt(dfs))) { 
  6.1063 +// 	    if (dfs.isBNodeNewlyReached()) {
  6.1064 +	  
  6.1065 +// 	      typename EAugGraph::Node v=res_graph.aNode(dfs);
  6.1066 +// 	      typename EAugGraph::Node w=res_graph.bNode(dfs);
  6.1067 +
  6.1068 +// 	      pred.set(w, EAugOutEdgeIt(dfs));
  6.1069 +// 	      if (res_graph.valid(pred.get(v))) {
  6.1070 +// 		free.set(w, std::min(free.get(v), res_graph.free(dfs)));
  6.1071 +// 	      } else {
  6.1072 +// 		free.set(w, res_graph.free(dfs)); 
  6.1073 +// 	      }
  6.1074 +	     
  6.1075 +// 	      n=w;
  6.1076 +// 	      if (T->get(w)) {
  6.1077 +// 		Number u=0;
  6.1078 +// 		for(InEdgeIt f=G->template first<InEdgeIt>(n); G->valid(f); G->next(f))
  6.1079 +// 		  u+=flow->get(f);
  6.1080 +// 		if (u<1) {
  6.1081 +// 		  __augment=true; 
  6.1082 +// 		  _augment=true;
  6.1083 +// 		  break; 
  6.1084 +// 		}
  6.1085 +// 	      }
  6.1086 +// 	    } else {
  6.1087 +// 	      res_graph.erase(dfs);
  6.1088 +// 	    }
  6.1089 +// 	  } 
  6.1090 +
  6.1091 +// 	}
  6.1092 +
  6.1093 +// 	if (__augment) {
  6.1094 +// 	  // typename EAugGraph::Node n=t;
  6.1095 +// 	  Number augment_value=free.get(n);
  6.1096 +// 	  while (res_graph.valid(pred.get(n))) { 
  6.1097 +// 	    EAugEdge e=pred.get(n);
  6.1098 +// 	    res_graph.augment(e, augment_value);
  6.1099 +// 	    n=res_graph.tail(e);
  6.1100 +// 	    if (res_graph.free(e)==0)
  6.1101 +// 	      res_graph.erase(e);
  6.1102 +// 	  }
  6.1103 +// 	}
  6.1104 +      
  6.1105 +//       }
  6.1106 +            
  6.1107 +//       return _augment;
  6.1108 +//     }
  6.1109 +//     void run() {
  6.1110 +//       //int num_of_augmentations=0;
  6.1111 +//       while (augmentOnShortestPath()) { 
  6.1112 +// 	//while (augmentOnBlockingFlow<MutableGraph>()) { 
  6.1113 +// 	//std::cout << ++num_of_augmentations << " ";
  6.1114 +// 	//std::cout<<std::endl;
  6.1115 +//       } 
  6.1116 +//     }
  6.1117 +// //     template<typename MutableGraph> void run() {
  6.1118 +// //       //int num_of_augmentations=0;
  6.1119 +// //       //while (augmentOnShortestPath()) { 
  6.1120 +// // 	while (augmentOnBlockingFlow<MutableGraph>()) { 
  6.1121 +// // 	//std::cout << ++num_of_augmentations << " ";
  6.1122 +// // 	//std::cout<<std::endl;
  6.1123 +// //       } 
  6.1124 +// //     } 
  6.1125 +//     Number flowValue() { 
  6.1126 +//       Number a=0;
  6.1127 +//       EdgeIt e;
  6.1128 +//       for(G->/*getF*/first(e); G->valid(e); G->next(e)) {
  6.1129 +// 	a+=flow->get(e);
  6.1130 +//       }
  6.1131 +//       return a;
  6.1132 +//     }
  6.1133 +//   };
  6.1134 +
  6.1135 +
  6.1136 +
  6.1137 +
  6.1138 +
  6.1139 +  
  6.1140 +// //   template <typename Graph, typename Number, typename FlowMap, typename CapacityMap>
  6.1141 +// //   class MaxFlow2 {
  6.1142 +// //   public:
  6.1143 +// //     typedef typename Graph::Node Node;
  6.1144 +// //     typedef typename Graph::Edge Edge;
  6.1145 +// //     typedef typename Graph::EdgeIt EdgeIt;
  6.1146 +// //     typedef typename Graph::OutEdgeIt OutEdgeIt;
  6.1147 +// //     typedef typename Graph::InEdgeIt InEdgeIt;
  6.1148 +// //   private:
  6.1149 +// //     const Graph& G;
  6.1150 +// //     std::list<Node>& S;
  6.1151 +// //     std::list<Node>& T;
  6.1152 +// //     FlowMap& flow;
  6.1153 +// //     const CapacityMap& capacity;
  6.1154 +// //     typedef ResGraphWrapper<Graph, Number, FlowMap, CapacityMap > AugGraph;
  6.1155 +// //     typedef typename AugGraph::OutEdgeIt AugOutEdgeIt;
  6.1156 +// //     typedef typename AugGraph::Edge AugEdge;
  6.1157 +// //     typename Graph::NodeMap<bool> SMap;
  6.1158 +// //     typename Graph::NodeMap<bool> TMap;
  6.1159 +// //   public:
  6.1160 +// //     MaxFlow2(const Graph& _G, std::list<Node>& _S, std::list<Node>& _T, FlowMap& _flow, const CapacityMap& _capacity) : G(_G), S(_S), T(_T), flow(_flow), capacity(_capacity), SMap(_G), TMap(_G) { 
  6.1161 +// //       for(typename std::list<Node>::const_iterator i=S.begin(); 
  6.1162 +// // 	  i!=S.end(); ++i) { 
  6.1163 +// // 	SMap.set(*i, true); 
  6.1164 +// //       }
  6.1165 +// //       for (typename std::list<Node>::const_iterator i=T.begin(); 
  6.1166 +// // 	   i!=T.end(); ++i) { 
  6.1167 +// // 	TMap.set(*i, true); 
  6.1168 +// //       }
  6.1169 +// //     }
  6.1170 +// //     bool augment() {
  6.1171 +// //       AugGraph res_graph(G, flow, capacity);
  6.1172 +// //       bool _augment=false;
  6.1173 +// //       Node reached_t_node;
  6.1174 +      
  6.1175 +// //       typedef typename AugGraph::NodeMap<bool> ReachedMap;
  6.1176 +// //       BfsIterator4< AugGraph, AugOutEdgeIt, ReachedMap > bfs(res_graph);
  6.1177 +// //       for(typename std::list<Node>::const_iterator i=S.begin(); 
  6.1178 +// // 	  i!=S.end(); ++i) {
  6.1179 +// // 	bfs.pushAndSetReached(*i);
  6.1180 +// //       }
  6.1181 +// //       //bfs.pushAndSetReached(s);
  6.1182 +	
  6.1183 +// //       typename AugGraph::NodeMap<AugEdge> pred(res_graph); 
  6.1184 +// //       //filled up with invalid iterators
  6.1185 +      
  6.1186 +// //       typename AugGraph::NodeMap<Number> free(res_graph);
  6.1187 +	
  6.1188 +// //       //searching for augmenting path
  6.1189 +// //       while ( !bfs.finished() ) { 
  6.1190 +// // 	AugOutEdgeIt e=/*AugOutEdgeIt*/(bfs);
  6.1191 +// // 	if (e.valid() && bfs.isBNodeNewlyReached()) {
  6.1192 +// // 	  Node v=res_graph.tail(e);
  6.1193 +// // 	  Node w=res_graph.head(e);
  6.1194 +// // 	  pred.set(w, e);
  6.1195 +// // 	  if (pred.get(v).valid()) {
  6.1196 +// // 	    free.set(w, std::min(free.get(v), e.free()));
  6.1197 +// // 	  } else {
  6.1198 +// // 	    free.set(w, e.free()); 
  6.1199 +// // 	  }
  6.1200 +// // 	  if (TMap.get(res_graph.head(e))) { 
  6.1201 +// // 	    _augment=true; 
  6.1202 +// // 	    reached_t_node=res_graph.head(e);
  6.1203 +// // 	    break; 
  6.1204 +// // 	  }
  6.1205 +// // 	}
  6.1206 +	
  6.1207 +// // 	++bfs;
  6.1208 +// //       } //end of searching augmenting path
  6.1209 +
  6.1210 +// //       if (_augment) {
  6.1211 +// // 	Node n=reached_t_node;
  6.1212 +// // 	Number augment_value=free.get(reached_t_node);
  6.1213 +// // 	while (pred.get(n).valid()) { 
  6.1214 +// // 	  AugEdge e=pred.get(n);
  6.1215 +// // 	  e.augment(augment_value); 
  6.1216 +// // 	  n=res_graph.tail(e);
  6.1217 +// // 	}
  6.1218 +// //       }
  6.1219 +
  6.1220 +// //       return _augment;
  6.1221 +// //     }
  6.1222 +// //     void run() {
  6.1223 +// //       while (augment()) { } 
  6.1224 +// //     }
  6.1225 +// //     Number flowValue() { 
  6.1226 +// //       Number a=0;
  6.1227 +// //       for(typename std::list<Node>::const_iterator i=S.begin(); 
  6.1228 +// // 	  i!=S.end(); ++i) { 
  6.1229 +// // 	for(OutEdgeIt e=G.template first<OutEdgeIt>(*i); e.valid(); ++e) {
  6.1230 +// // 	  a+=flow.get(e);
  6.1231 +// // 	}
  6.1232 +// // 	for(InEdgeIt e=G.template first<InEdgeIt>(*i); e.valid(); ++e) {
  6.1233 +// // 	  a-=flow.get(e);
  6.1234 +// // 	}
  6.1235 +// //       }
  6.1236 +// //       return a;
  6.1237 +// //     }
  6.1238 +// //   };
  6.1239 +
  6.1240 +
  6.1241 +} // namespace hugo
  6.1242 +
  6.1243 +#endif //HUGO_EDMONDS_KARP_H
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/work/marci/experiment/edmonds_karp_demo.cc	Sat Apr 03 17:26:46 2004 +0000
     7.3 @@ -0,0 +1,218 @@
     7.4 +// -*- c++ -*-
     7.5 +#include <iostream>
     7.6 +#include <fstream>
     7.7 +
     7.8 +#include <list_graph.h>
     7.9 +#include <smart_graph.h>
    7.10 +#include <dimacs.h>
    7.11 +#include <edmonds_karp.h>
    7.12 +#include <time_measure.h>
    7.13 +#include <graph_wrapper.h>
    7.14 +
    7.15 +class CM {
    7.16 +public:
    7.17 +  template<typename T> int get(T) const {return 1;}
    7.18 +};
    7.19 +
    7.20 +using namespace hugo;
    7.21 +
    7.22 +// Use a DIMACS max flow file as stdin.
    7.23 +// read_dimacs_demo < dimacs_max_flow_file
    7.24 +
    7.25 +
    7.26 +//   struct Ize {
    7.27 +//   };
    7.28 +  
    7.29 +//   struct Mize {
    7.30 +//     Ize bumm;
    7.31 +//   };
    7.32 +
    7.33 +//   template <typename B>
    7.34 +//     class Huha {
    7.35 +//     public:
    7.36 +//       int u;
    7.37 +//       B brr;
    7.38 +//     };
    7.39 +
    7.40 +
    7.41 +int main(int, char **) {
    7.42 +
    7.43 +  typedef ListGraph MutableGraph;
    7.44 +
    7.45 +  //typedef SmartGraph Graph;
    7.46 +  typedef ListGraph Graph;
    7.47 +  typedef Graph::Node Node;
    7.48 +  typedef Graph::EdgeIt EdgeIt;
    7.49 +
    7.50 +
    7.51 +//   Mize mize[10];
    7.52 +//   Mize bize[0];
    7.53 +//   Mize zize;
    7.54 +//   typedef Mize Tize[0];
    7.55 +
    7.56 +//   std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
    7.57 +//   std::cout << sizeof(bize) << std::endl;
    7.58 +
    7.59 +
    7.60 +//   Huha<Tize> k;
    7.61 +//   std::cout << sizeof(k) << std::endl;
    7.62 +
    7.63 +
    7.64 +//   struct Bumm {
    7.65 +//     //int a;
    7.66 +//     bool b;
    7.67 +//   };
    7.68 +
    7.69 +//   std::cout << sizeof(Bumm) << std::endl;
    7.70 +
    7.71 +
    7.72 +  Graph G;
    7.73 +  Node s, t;
    7.74 +  Graph::EdgeMap<int> cap(G);
    7.75 +  readDimacsMaxFlow(std::cin, G, s, t, cap);
    7.76 +
    7.77 +//   typedef TrivGraphWrapper<Graph> TGW;
    7.78 +//   TGW gw(G);
    7.79 +//   TGW::NodeIt sw;
    7.80 +//   gw./*getF*/first(sw);
    7.81 +//   std::cout << "p1:" << gw.nodeNum() << std::endl;
    7.82 +//   gw.erase(sw);
    7.83 +//   std::cout << "p2:" << gw.nodeNum() << std::endl;
    7.84 +
    7.85 +//   typedef const Graph cLG;
    7.86 +//   typedef TrivGraphWrapper<const cLG> CTGW;
    7.87 +//   CTGW cgw(G);
    7.88 +//   CTGW::NodeIt csw;
    7.89 +//   cgw./*getF*/first(csw);
    7.90 +//   std::cout << "p1:" << cgw.nodeNum() << std::endl;
    7.91 +//   //cgw.erase(csw);
    7.92 +//   std::cout << "p2:" << cgw.nodeNum() << std::endl;
    7.93 +
    7.94 +
    7.95 +  {
    7.96 +    typedef TrivGraphWrapper<const Graph> GW;
    7.97 +    GW gw(G);
    7.98 +    std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
    7.99 +    GW::EdgeMap<int> flow(gw); //0 flow
   7.100 +
   7.101 +    Timer ts;
   7.102 +    ts.reset();
   7.103 +
   7.104 +    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
   7.105 +    EMW cw(cap);
   7.106 +    MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
   7.107 +    int i=0;
   7.108 +    while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { 
   7.109 +//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
   7.110 +//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   7.111 +//     }
   7.112 +//     std::cout<<std::endl;
   7.113 +      ++i; 
   7.114 +    }
   7.115 +
   7.116 +//   std::cout << "maximum flow: "<< std::endl;
   7.117 +//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
   7.118 +//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   7.119 +//   }
   7.120 +//   std::cout<<std::endl;
   7.121 +    std::cout << "elapsed time: " << ts << std::endl;
   7.122 +    std::cout << "number of augmentation phases: " << i << std::endl; 
   7.123 +    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
   7.124 +  }
   7.125 +
   7.126 +  {
   7.127 +    typedef TrivGraphWrapper<const Graph> GW;
   7.128 +    GW gw(G);
   7.129 +    std::cout << "edmonds karp demo (physical blocking flow 1 augmentation)..." << std::endl;
   7.130 +    GW::EdgeMap<int> flow(gw); //0 flow
   7.131 +
   7.132 +    Timer ts;
   7.133 +    ts.reset();
   7.134 +
   7.135 +    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
   7.136 +    EMW cw(cap);
   7.137 +    MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
   7.138 +    int i=0;
   7.139 +    while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { 
   7.140 +//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
   7.141 +//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   7.142 +//     }
   7.143 +//     std::cout<<std::endl;
   7.144 +      ++i; 
   7.145 +    }
   7.146 +
   7.147 +//   std::cout << "maximum flow: "<< std::endl;
   7.148 +//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
   7.149 +//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   7.150 +//   }
   7.151 +//   std::cout<<std::endl;
   7.152 +    std::cout << "elapsed time: " << ts << std::endl;
   7.153 +    std::cout << "number of augmentation phases: " << i << std::endl; 
   7.154 +    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
   7.155 +  }
   7.156 +
   7.157 +  {
   7.158 +    typedef TrivGraphWrapper<const Graph> GW;
   7.159 +    GW gw(G);
   7.160 +    std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
   7.161 +    GW::EdgeMap<int> flow(gw); //0 flow
   7.162 +
   7.163 +    Timer ts;
   7.164 +    ts.reset();
   7.165 +
   7.166 +    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
   7.167 +    EMW cw(cap);
   7.168 +    MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
   7.169 +    int i=0;
   7.170 +    while (max_flow_test.augmentOnBlockingFlow2()) { 
   7.171 +//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
   7.172 +//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   7.173 +//     }
   7.174 +//     std::cout<<std::endl;
   7.175 +      ++i; 
   7.176 +    }
   7.177 +
   7.178 +//   std::cout << "maximum flow: "<< std::endl;
   7.179 +//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
   7.180 +//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   7.181 +//   }
   7.182 +//   std::cout<<std::endl;
   7.183 +    std::cout << "elapsed time: " << ts << std::endl;
   7.184 +    std::cout << "number of augmentation phases: " << i << std::endl; 
   7.185 +    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
   7.186 +  }
   7.187 +
   7.188 +  {
   7.189 +    typedef TrivGraphWrapper<const Graph> GW;
   7.190 +    GW gw(G);
   7.191 +    std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
   7.192 +    GW::EdgeMap<int> flow(gw); //0 flow
   7.193 +
   7.194 +    Timer ts;
   7.195 +    ts.reset();
   7.196 +
   7.197 +    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
   7.198 +    EMW cw(cap);
   7.199 +    MaxFlow<GW, int, GW::EdgeMap<int>, EMW> max_flow_test(gw, s, t, flow, cw);
   7.200 +    int i=0;
   7.201 +    while (max_flow_test.augmentOnShortestPath()) { 
   7.202 +//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
   7.203 +//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   7.204 +//     }
   7.205 +//     std::cout<<std::endl;
   7.206 +      ++i; 
   7.207 +    }
   7.208 +
   7.209 +//   std::cout << "maximum flow: "<< std::endl;
   7.210 +//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
   7.211 +//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   7.212 +//   }
   7.213 +//   std::cout<<std::endl;
   7.214 +    std::cout << "elapsed time: " << ts << std::endl;
   7.215 +    std::cout << "number of augmentation phases: " << i << std::endl; 
   7.216 +    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
   7.217 +  }
   7.218 +
   7.219 +
   7.220 +  return 0;
   7.221 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/work/marci/experiment/edmonds_karp_demo_1.cc	Sat Apr 03 17:26:46 2004 +0000
     8.3 @@ -0,0 +1,218 @@
     8.4 +// -*- c++ -*-
     8.5 +#include <iostream>
     8.6 +#include <fstream>
     8.7 +
     8.8 +#include <list_graph.h>
     8.9 +//#include <smart_graph.h>
    8.10 +#include <dimacs.h>
    8.11 +#include <edmonds_karp_1.h>
    8.12 +#include <time_measure.h>
    8.13 +#include <graph_wrapper_1.h>
    8.14 +
    8.15 +class CM {
    8.16 +public:
    8.17 +  template<typename T> int get(T) const {return 1;}
    8.18 +};
    8.19 +
    8.20 +using namespace hugo;
    8.21 +
    8.22 +// Use a DIMACS max flow file as stdin.
    8.23 +// read_dimacs_demo < dimacs_max_flow_file
    8.24 +
    8.25 +
    8.26 +//   struct Ize {
    8.27 +//   };
    8.28 +  
    8.29 +//   struct Mize {
    8.30 +//     Ize bumm;
    8.31 +//   };
    8.32 +
    8.33 +//   template <typename B>
    8.34 +//     class Huha {
    8.35 +//     public:
    8.36 +//       int u;
    8.37 +//       B brr;
    8.38 +//     };
    8.39 +
    8.40 +
    8.41 +int main(int, char **) {
    8.42 +
    8.43 +  typedef ListGraph MutableGraph;
    8.44 +
    8.45 +  //typedef SmartGraph Graph;
    8.46 +  typedef ListGraph Graph;
    8.47 +  typedef Graph::Node Node;
    8.48 +  typedef Graph::EdgeIt EdgeIt;
    8.49 +
    8.50 +
    8.51 +//   Mize mize[10];
    8.52 +//   Mize bize[0];
    8.53 +//   Mize zize;
    8.54 +//   typedef Mize Tize[0];
    8.55 +
    8.56 +//   std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
    8.57 +//   std::cout << sizeof(bize) << std::endl;
    8.58 +
    8.59 +
    8.60 +//   Huha<Tize> k;
    8.61 +//   std::cout << sizeof(k) << std::endl;
    8.62 +
    8.63 +
    8.64 +//   struct Bumm {
    8.65 +//     //int a;
    8.66 +//     bool b;
    8.67 +//   };
    8.68 +
    8.69 +//   std::cout << sizeof(Bumm) << std::endl;
    8.70 +
    8.71 +
    8.72 +  Graph G;
    8.73 +  Node s, t;
    8.74 +  Graph::EdgeMap<int> cap(G);
    8.75 +  readDimacsMaxFlow(std::cin, G, s, t, cap);
    8.76 +
    8.77 +//   typedef TrivGraphWrapper<Graph> TGW;
    8.78 +//   TGW gw(G);
    8.79 +//   TGW::NodeIt sw;
    8.80 +//   gw./*getF*/first(sw);
    8.81 +//   std::cout << "p1:" << gw.nodeNum() << std::endl;
    8.82 +//   gw.erase(sw);
    8.83 +//   std::cout << "p2:" << gw.nodeNum() << std::endl;
    8.84 +
    8.85 +//   typedef const Graph cLG;
    8.86 +//   typedef TrivGraphWrapper<const cLG> CTGW;
    8.87 +//   CTGW cgw(G);
    8.88 +//   CTGW::NodeIt csw;
    8.89 +//   cgw./*getF*/first(csw);
    8.90 +//   std::cout << "p1:" << cgw.nodeNum() << std::endl;
    8.91 +//   //cgw.erase(csw);
    8.92 +//   std::cout << "p2:" << cgw.nodeNum() << std::endl;
    8.93 +
    8.94 +
    8.95 +  {
    8.96 +    typedef TrivGraphWrapper<const Graph> GW;
    8.97 +    GW gw(G);
    8.98 +    std::cout << "edmonds karp demo (physical blocking flow augmentation)..." << std::endl;
    8.99 +    GW::EdgeMap<int> flow(gw); //0 flow
   8.100 +
   8.101 +    Timer ts;
   8.102 +    ts.reset();
   8.103 +
   8.104 +    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
   8.105 +    EMW cw(cap);
   8.106 +    MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
   8.107 +    int i=0;
   8.108 +    while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { 
   8.109 +//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
   8.110 +//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   8.111 +//     }
   8.112 +//     std::cout<<std::endl;
   8.113 +      ++i; 
   8.114 +    }
   8.115 +
   8.116 +//   std::cout << "maximum flow: "<< std::endl;
   8.117 +//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
   8.118 +//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   8.119 +//   }
   8.120 +//   std::cout<<std::endl;
   8.121 +    std::cout << "elapsed time: " << ts << std::endl;
   8.122 +    std::cout << "number of augmentation phases: " << i << std::endl; 
   8.123 +    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
   8.124 +  }
   8.125 +
   8.126 +  {
   8.127 +    typedef TrivGraphWrapper<const Graph> GW;
   8.128 +    GW gw(G);
   8.129 +    std::cout << "edmonds karp demo (physical blocking flow 1 augmentation)..." << std::endl;
   8.130 +    GW::EdgeMap<int> flow(gw); //0 flow
   8.131 +
   8.132 +    Timer ts;
   8.133 +    ts.reset();
   8.134 +
   8.135 +    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
   8.136 +    EMW cw(cap);
   8.137 +    MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
   8.138 +    int i=0;
   8.139 +    while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { 
   8.140 +//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
   8.141 +//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   8.142 +//     }
   8.143 +//     std::cout<<std::endl;
   8.144 +      ++i; 
   8.145 +    }
   8.146 +
   8.147 +//   std::cout << "maximum flow: "<< std::endl;
   8.148 +//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
   8.149 +//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   8.150 +//   }
   8.151 +//   std::cout<<std::endl;
   8.152 +    std::cout << "elapsed time: " << ts << std::endl;
   8.153 +    std::cout << "number of augmentation phases: " << i << std::endl; 
   8.154 +    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
   8.155 +  }
   8.156 +
   8.157 +  {
   8.158 +    typedef TrivGraphWrapper<const Graph> GW;
   8.159 +    GW gw(G);
   8.160 +    std::cout << "edmonds karp demo (on-the-fly blocking flow augmentation)..." << std::endl;
   8.161 +    GW::EdgeMap<int> flow(gw); //0 flow
   8.162 +
   8.163 +    Timer ts;
   8.164 +    ts.reset();
   8.165 +
   8.166 +    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
   8.167 +    EMW cw(cap);
   8.168 +    MaxFlow<GW, int, GW::EdgeMap<int>, EMW > max_flow_test(gw, s, t, flow, cw);
   8.169 +    int i=0;
   8.170 +    while (max_flow_test.augmentOnBlockingFlow2()) { 
   8.171 +//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
   8.172 +//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   8.173 +//     }
   8.174 +//     std::cout<<std::endl;
   8.175 +      ++i; 
   8.176 +    }
   8.177 +
   8.178 +//   std::cout << "maximum flow: "<< std::endl;
   8.179 +//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
   8.180 +//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   8.181 +//   }
   8.182 +//   std::cout<<std::endl;
   8.183 +    std::cout << "elapsed time: " << ts << std::endl;
   8.184 +    std::cout << "number of augmentation phases: " << i << std::endl; 
   8.185 +    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
   8.186 +  }
   8.187 +
   8.188 +  {
   8.189 +    typedef TrivGraphWrapper<const Graph> GW;
   8.190 +    GW gw(G);
   8.191 +    std::cout << "edmonds karp demo (on-the-fly shortest path augmentation)..." << std::endl;
   8.192 +    GW::EdgeMap<int> flow(gw); //0 flow
   8.193 +
   8.194 +    Timer ts;
   8.195 +    ts.reset();
   8.196 +
   8.197 +    typedef GW::EdgeMapWrapper< Graph::EdgeMap<int>, int > EMW;
   8.198 +    EMW cw(cap);
   8.199 +    MaxFlow<GW, int, GW::EdgeMap<int>, EMW> max_flow_test(gw, s, t, flow, cw);
   8.200 +    int i=0;
   8.201 +    while (max_flow_test.augmentOnShortestPath()) { 
   8.202 +//     for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) { 
   8.203 +//       std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   8.204 +//     }
   8.205 +//     std::cout<<std::endl;
   8.206 +      ++i; 
   8.207 +    }
   8.208 +
   8.209 +//   std::cout << "maximum flow: "<< std::endl;
   8.210 +//   for(EdgeIt e=G.first<EdgeIt>(); e.valid(); ++e) { 
   8.211 +//     std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
   8.212 +//   }
   8.213 +//   std::cout<<std::endl;
   8.214 +    std::cout << "elapsed time: " << ts << std::endl;
   8.215 +    std::cout << "number of augmentation phases: " << i << std::endl; 
   8.216 +    std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
   8.217 +  }
   8.218 +
   8.219 +
   8.220 +  return 0;
   8.221 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/work/marci/experiment/graph_wrapper.h	Sat Apr 03 17:26:46 2004 +0000
     9.3 @@ -0,0 +1,1707 @@
     9.4 +// -*- c++ -*-
     9.5 +#ifndef HUGO_GRAPH_WRAPPER_H
     9.6 +#define HUGO_GRAPH_WRAPPER_H
     9.7 +
     9.8 +#include <invalid.h>
     9.9 +
    9.10 +namespace hugo {
    9.11 +
    9.12 +  template<typename Graph>
    9.13 +  class TrivGraphWrapper {
    9.14 +  protected:
    9.15 +    Graph* graph;
    9.16 +  
    9.17 +  public:
    9.18 +    typedef Graph BaseGraph;
    9.19 +
    9.20 +    typedef typename Graph::Node Node;
    9.21 +    class NodeIt : public Graph::NodeIt { 
    9.22 +    public:
    9.23 +      NodeIt() { }
    9.24 +      NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { }
    9.25 +      NodeIt(const Invalid& i) : Graph::NodeIt(i) { }
    9.26 +      NodeIt(const TrivGraphWrapper<Graph>& _G) : 
    9.27 +	Graph::NodeIt(*(_G.graph)) { }
    9.28 +    };
    9.29 +    typedef typename Graph::Edge Edge;
    9.30 +    //typedef typename Graph::OutEdgeIt OutEdgeIt;
    9.31 +    class OutEdgeIt : public Graph::OutEdgeIt { 
    9.32 +    public:
    9.33 +      OutEdgeIt() { }
    9.34 +      OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { }
    9.35 +      OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { }
    9.36 +      OutEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) : 
    9.37 +	Graph::OutEdgeIt(*(_G.graph), n) { }
    9.38 +    };
    9.39 +    //typedef typename Graph::InEdgeIt InEdgeIt;
    9.40 +    class InEdgeIt : public Graph::InEdgeIt { 
    9.41 +    public:
    9.42 +      InEdgeIt() { }
    9.43 +      InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { }
    9.44 +      InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { }
    9.45 +      InEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) : 
    9.46 +	Graph::InEdgeIt(*(_G.graph), n) { }
    9.47 +    };
    9.48 +    //typedef typename Graph::SymEdgeIt SymEdgeIt;
    9.49 +    //typedef typename Graph::EdgeIt EdgeIt;
    9.50 +    class EdgeIt : public Graph::EdgeIt { 
    9.51 +    public:
    9.52 +      EdgeIt() { }
    9.53 +      EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { }
    9.54 +      EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { }
    9.55 +      EdgeIt(const TrivGraphWrapper<Graph>& _G) : 
    9.56 +	Graph::EdgeIt(*(_G.graph)) { }
    9.57 +    };
    9.58 +
    9.59 +    //TrivGraphWrapper() : graph(0) { }
    9.60 +    TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
    9.61 +
    9.62 +//    void setGraph(Graph& _graph) { graph = &_graph; }
    9.63 +//    Graph& getGraph() const { return (*graph); }
    9.64 +
    9.65 +    NodeIt& first(NodeIt& i) const { 
    9.66 +      i=NodeIt(*this);
    9.67 +      return i;
    9.68 +    }
    9.69 +    EdgeIt& first(EdgeIt& i) const { 
    9.70 +      i=EdgeIt(*this);
    9.71 +      return i;
    9.72 +    }
    9.73 +//     template<typename I> I& first(I& i) const { 
    9.74 +//       //return graph->first(i); 
    9.75 +//       i=I(*this);
    9.76 +//       return i;
    9.77 +//     }
    9.78 +    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
    9.79 +      i=OutEdgeIt(*this, p);
    9.80 +      return i;
    9.81 +    }
    9.82 +    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
    9.83 +      i=InEdgeIt(*this, p);
    9.84 +      return i;
    9.85 +    }
    9.86 +//     template<typename I, typename P> I& first(I& i, const P& p) const { 
    9.87 +//       //return graph->first(i, p);
    9.88 +//       i=I(*this, p);
    9.89 +//       return i;
    9.90 +//     }
    9.91 +    
    9.92 +//    template<typename I> I getNext(const I& i) const { 
    9.93 +//      return graph->getNext(i); }
    9.94 +    template<typename I> I& next(I &i) const { graph->next(i); return i; }    
    9.95 +
    9.96 +    template< typename It > It first() const { 
    9.97 +      It e; first(e); return e; }
    9.98 +
    9.99 +    template< typename It > It first(const Node& v) const { 
   9.100 +      It e; first(e, v); return e; }
   9.101 +
   9.102 +    Node head(const Edge& e) const { return graph->head(e); }
   9.103 +    Node tail(const Edge& e) const { return graph->tail(e); }
   9.104 +
   9.105 +    template<typename I> bool valid(const I& i) const 
   9.106 +      { return graph->valid(i); }
   9.107 +  
   9.108 +    //template<typename I> void setInvalid(const I &i);
   9.109 +    //{ return graph->setInvalid(i); }
   9.110 +
   9.111 +    int nodeNum() const { return graph->nodeNum(); }
   9.112 +    int edgeNum() const { return graph->edgeNum(); }
   9.113 +  
   9.114 +    template<typename I> Node aNode(const I& e) const { 
   9.115 +      return graph->aNode(e); }
   9.116 +    template<typename I> Node bNode(const I& e) const { 
   9.117 +      return graph->bNode(e); }
   9.118 +  
   9.119 +    Node addNode() const { return graph->addNode(); }
   9.120 +    Edge addEdge(const Node& tail, const Node& head) const { 
   9.121 +      return graph->addEdge(tail, head); }
   9.122 +  
   9.123 +    template<typename I> void erase(const I& i) const { graph->erase(i); }
   9.124 +  
   9.125 +    void clear() const { graph->clear(); }
   9.126 +    
   9.127 +    template<typename T> class NodeMap : public Graph::NodeMap<T> { 
   9.128 +    public:
   9.129 +      NodeMap(const TrivGraphWrapper<Graph>& _G) :  
   9.130 +	Graph::NodeMap<T>(*(_G.graph)) { }
   9.131 +      NodeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
   9.132 +	Graph::NodeMap<T>(*(_G.graph), a) { }
   9.133 +    };
   9.134 +
   9.135 +    template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
   9.136 +    public:
   9.137 +      EdgeMap(const TrivGraphWrapper<Graph>& _G) :  
   9.138 +	Graph::EdgeMap<T>(*(_G.graph)) { }
   9.139 +      EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
   9.140 +	Graph::EdgeMap<T>(*(_G.graph), a) { }
   9.141 +    };
   9.142 +
   9.143 +    template<typename Map, typename T> class NodeMapWrapper {
   9.144 +    protected:
   9.145 +      Map* map;
   9.146 +    public:
   9.147 +      NodeMapWrapper(Map& _map) : map(&_map) { }
   9.148 +      //template<typename T> 
   9.149 +      void set(Node n, T a) { map->set(n, a); }
   9.150 +      //template<typename T>
   9.151 +      T get(Node n) const { return map->get(n); }
   9.152 +    };
   9.153 +
   9.154 +    template<typename Map, typename T> class EdgeMapWrapper {
   9.155 +    protected:
   9.156 +      Map* map;
   9.157 +    public:
   9.158 +      EdgeMapWrapper(Map& _map) : map(&_map) { }
   9.159 +      //template<typename T> 
   9.160 +      void set(Edge n, T a) { map->set(n, a); }
   9.161 +      //template<typename T>
   9.162 +      T get(Edge n) const { return map->get(n); }
   9.163 +    };
   9.164 +  };
   9.165 +
   9.166 +  template<typename GraphWrapper>
   9.167 +  class GraphWrapperSkeleton {
   9.168 +  protected:
   9.169 +    GraphWrapper gw;
   9.170 +  
   9.171 +  public:
   9.172 +    //typedef typename GraphWrapper::BaseGraph BaseGraph;
   9.173 +
   9.174 +//     typedef typename GraphWrapper::Node Node;
   9.175 +//     typedef typename GraphWrapper::NodeIt NodeIt;
   9.176 +
   9.177 +//     typedef typename GraphWrapper::Edge Edge;
   9.178 +//     typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
   9.179 +//     typedef typename GraphWrapper::InEdgeIt InEdgeIt;
   9.180 +//     //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
   9.181 +//     typedef typename GraphWrapper::EdgeIt EdgeIt;
   9.182 +
   9.183 +    typedef typename GraphWrapper::Node Node;
   9.184 +    class NodeIt : public GraphWrapper::NodeIt { 
   9.185 +    public:
   9.186 +      NodeIt() { }
   9.187 +      NodeIt(const typename GraphWrapper::NodeIt& n) : 
   9.188 +	GraphWrapper::NodeIt(n) { }
   9.189 +      NodeIt(const Invalid& i) : GraphWrapper::NodeIt(i) { }
   9.190 +      NodeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
   9.191 +	GraphWrapper::NodeIt(_G.gw) { }
   9.192 +    };
   9.193 +    typedef typename GraphWrapper::Edge Edge;
   9.194 +    //typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
   9.195 +    class OutEdgeIt : public GraphWrapper::OutEdgeIt { 
   9.196 +    public:
   9.197 +      OutEdgeIt() { }
   9.198 +      OutEdgeIt(const typename GraphWrapper::OutEdgeIt& e) : 
   9.199 +	GraphWrapper::OutEdgeIt(e) { }
   9.200 +      OutEdgeIt(const Invalid& i) : GraphWrapper::OutEdgeIt(i) { }
   9.201 +      OutEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 
   9.202 +	GraphWrapper::OutEdgeIt(_G.gw, n) { }
   9.203 +    };
   9.204 +    //typedef typename GraphWrapper::InEdgeIt InEdgeIt;
   9.205 +    class InEdgeIt : public GraphWrapper::InEdgeIt { 
   9.206 +    public:
   9.207 +      InEdgeIt() { }
   9.208 +      InEdgeIt(const typename GraphWrapper::InEdgeIt& e) : 
   9.209 +	GraphWrapper::InEdgeIt(e) { }
   9.210 +      InEdgeIt(const Invalid& i) : GraphWrapper::InEdgeIt(i) { }
   9.211 +      InEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 
   9.212 +	GraphWrapper::InEdgeIt(_G.gw, n) { }
   9.213 +    };
   9.214 +    //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
   9.215 +    //typedef typename GraphWrapper::EdgeIt EdgeIt;
   9.216 +    class EdgeIt : public GraphWrapper::EdgeIt { 
   9.217 +    public:
   9.218 +      EdgeIt() { }
   9.219 +      EdgeIt(const typename GraphWrapper::EdgeIt& e) : 
   9.220 +	GraphWrapper::EdgeIt(e) { }
   9.221 +      EdgeIt(const Invalid& i) : GraphWrapper::EdgeIt(i) { }
   9.222 +      EdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
   9.223 +	GraphWrapper::EdgeIt(_G.gw) { }
   9.224 +    };
   9.225 +
   9.226 +
   9.227 +    //GraphWrapperSkeleton() : gw() { }
   9.228 +    GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
   9.229 +
   9.230 +    //void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
   9.231 +    //BaseGraph& getGraph() const { return gw.getGraph(); }
   9.232 +    
   9.233 +    template<typename I> I& first(I& i) const {       
   9.234 +      i=I(*this);
   9.235 +      return i;
   9.236 +    }
   9.237 +    template<typename I, typename P> I& first(I& i, const P& p) const { 
   9.238 +      i=I(*this, p);
   9.239 +      return i; 
   9.240 +    }
   9.241 +    
   9.242 +//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
   9.243 +    template<typename I> I& next(I &i) const { gw.next(i); return i; }    
   9.244 +
   9.245 +    template< typename It > It first() const { 
   9.246 +      It e; this->first(e); return e; }
   9.247 +
   9.248 +    template< typename It > It first(const Node& v) const { 
   9.249 +      It e; this->first(e, v); return e; }
   9.250 +
   9.251 +    Node head(const Edge& e) const { return gw.head(e); }
   9.252 +    Node tail(const Edge& e) const { return gw.tail(e); }
   9.253 +
   9.254 +    template<typename I> bool valid(const I& i) const { return gw.valid(i); }
   9.255 +  
   9.256 +    //template<typename I> void setInvalid(const I &i);
   9.257 +    //{ return graph->setInvalid(i); }
   9.258 +
   9.259 +    int nodeNum() const { return gw.nodeNum(); }
   9.260 +    int edgeNum() const { return gw.edgeNum(); }
   9.261 +  
   9.262 +    template<typename I> Node aNode(const I& e) const { return gw.aNode(e); }
   9.263 +    template<typename I> Node bNode(const I& e) const { return gw.bNode(e); }
   9.264 +  
   9.265 +    Node addNode() const { return gw.addNode(); }
   9.266 +    Edge addEdge(const Node& tail, const Node& head) const { 
   9.267 +      return gw.addEdge(tail, head); }
   9.268 +  
   9.269 +    template<typename I> void erase(const I& i) const { gw.erase(i); }
   9.270 +  
   9.271 +    void clear() const { gw.clear(); }
   9.272 +    
   9.273 +    template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
   9.274 +    public:
   9.275 +      NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :  
   9.276 +	GraphWrapper::NodeMap<T>(_G.gw) { }
   9.277 +      NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) : 
   9.278 +	GraphWrapper::NodeMap<T>(_G.gw, a) { }
   9.279 +    };
   9.280 +
   9.281 +    template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> { 
   9.282 +    public:
   9.283 +      EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :  
   9.284 +	GraphWrapper::EdgeMap<T>(_G.gw) { }
   9.285 +      EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) : 
   9.286 +	GraphWrapper::EdgeMap<T>(_G.gw, a) { }
   9.287 +    };
   9.288 +  };
   9.289 +
   9.290 +//   template<typename Graph>
   9.291 +//   class RevGraphWrapper
   9.292 +//   {
   9.293 +//   protected:
   9.294 +//     Graph* graph;
   9.295 +  
   9.296 +//   public:
   9.297 +//     typedef Graph BaseGraph;
   9.298 +
   9.299 +//     typedef typename Graph::Node Node;    
   9.300 +//     typedef typename Graph::NodeIt NodeIt;
   9.301 +  
   9.302 +//     typedef typename Graph::Edge Edge;
   9.303 +//     typedef typename Graph::OutEdgeIt InEdgeIt;
   9.304 +//     typedef typename Graph::InEdgeIt OutEdgeIt;
   9.305 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
   9.306 +//     typedef typename Graph::EdgeIt EdgeIt;
   9.307 +
   9.308 +//     //RevGraphWrapper() : graph(0) { }
   9.309 +//     RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
   9.310 +
   9.311 +//     void setGraph(Graph& _graph) { graph = &_graph; }
   9.312 +//     Graph& getGraph() const { return (*graph); }
   9.313 +    
   9.314 +//     template<typename I> I& first(I& i) const { return graph->first(i); }
   9.315 +//     template<typename I, typename P> I& first(I& i, const P& p) const { 
   9.316 +//       return graph->first(i, p); }
   9.317 +
   9.318 +//     template<typename I> I getNext(const I& i) const { 
   9.319 +//       return graph->getNext(i); }
   9.320 +//     template<typename I> I& next(I &i) const { return graph->next(i); }    
   9.321 +
   9.322 +//     template< typename It > It first() const { 
   9.323 +//       It e; first(e); return e; }
   9.324 +
   9.325 +//     template< typename It > It first(const Node& v) const { 
   9.326 +//       It e; first(e, v); return e; }
   9.327 +
   9.328 +//     Node head(const Edge& e) const { return graph->tail(e); }
   9.329 +//     Node tail(const Edge& e) const { return graph->head(e); }
   9.330 +  
   9.331 +//     template<typename I> bool valid(const I& i) const 
   9.332 +//       { return graph->valid(i); }
   9.333 +  
   9.334 +//     //template<typename I> void setInvalid(const I &i);
   9.335 +//     //{ return graph->setInvalid(i); }
   9.336 +  
   9.337 +//     template<typename I> Node aNode(const I& e) const { 
   9.338 +//       return graph->aNode(e); }
   9.339 +//     template<typename I> Node bNode(const I& e) const { 
   9.340 +//       return graph->bNode(e); }
   9.341 +
   9.342 +//     Node addNode() const { return graph->addNode(); }
   9.343 +//     Edge addEdge(const Node& tail, const Node& head) const { 
   9.344 +//       return graph->addEdge(tail, head); }
   9.345 +  
   9.346 +//     int nodeNum() const { return graph->nodeNum(); }
   9.347 +//     int edgeNum() const { return graph->edgeNum(); }
   9.348 +  
   9.349 +//     template<typename I> void erase(const I& i) const { graph->erase(i); }
   9.350 +  
   9.351 +//     void clear() const { graph->clear(); }
   9.352 +
   9.353 +//     template<typename T> class NodeMap : public Graph::NodeMap<T> { 
   9.354 +//     public:
   9.355 +//       NodeMap(const RevGraphWrapper<Graph>& _G) : 
   9.356 +// 	Graph::NodeMap<T>(_G.getGraph()) { }
   9.357 +//       NodeMap(const RevGraphWrapper<Graph>& _G, T a) : 
   9.358 +// 	Graph::NodeMap<T>(_G.getGraph(), a) { }
   9.359 +//     };
   9.360 +
   9.361 +//     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
   9.362 +//     public:
   9.363 +//       EdgeMap(const RevGraphWrapper<Graph>& _G) : 
   9.364 +// 	Graph::EdgeMap<T>(_G.getGraph()) { }
   9.365 +//       EdgeMap(const RevGraphWrapper<Graph>& _G, T a) : 
   9.366 +// 	Graph::EdgeMap<T>(_G.getGraph(), a) { }
   9.367 +//     };
   9.368 +//   };
   9.369 +
   9.370 +//   template<typename /*Graph*/GraphWrapper
   9.371 +//   /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ >
   9.372 +//   class RevGraphWrapper : 
   9.373 +//     public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ {
   9.374 +//   protected:
   9.375 +//     //Graph* graph;
   9.376 +    
   9.377 +//   public:
   9.378 +//     //typedef Graph BaseGraph;
   9.379 +
   9.380 +//     //typedef typename Graph::Node Node;    
   9.381 +//     //typedef typename Graph::NodeIt NodeIt;
   9.382 +  
   9.383 +//     //typedef typename Graph::Edge Edge;
   9.384 +//     typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::OutEdgeIt InEdgeIt;
   9.385 +//     typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::InEdgeIt OutEdgeIt;
   9.386 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
   9.387 +//     //typedef typename Graph::EdgeIt EdgeIt;
   9.388 +
   9.389 +//     //RevGraphWrapper() : graph(0) { }
   9.390 +//     RevGraphWrapper(GraphWrapper _gw/*BaseGraph& _graph*/) : GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/(_gw/*TrivGraphWrapper<Graph>(_graph)*/) { }
   9.391 +    
   9.392 +//     //void setGraph(Graph& _graph) { graph = &_graph; }
   9.393 +//     //Graph& getGraph() const { return (*graph); }
   9.394 +    
   9.395 +//     //template<typename I> I& first(I& i) const { return graph->first(i); }
   9.396 +//     //template<typename I, typename P> I& first(I& i, const P& p) const { 
   9.397 +//     //  return graph->first(i, p); }
   9.398 +
   9.399 +//     //template<typename I> I getNext(const I& i) const { 
   9.400 +//     //  return graph->getNext(i); }
   9.401 +//     //template<typename I> I& next(I &i) const { return graph->next(i); }    
   9.402 +
   9.403 +//     //template< typename It > It first() const { 
   9.404 +//     //  It e; first(e); return e; }
   9.405 +
   9.406 +//     //template< typename It > It first(const Node& v) const { 
   9.407 +//     //  It e; first(e, v); return e; }
   9.408 +
   9.409 +//     //Node head(const Edge& e) const { return graph->tail(e); }
   9.410 +//     //Node tail(const Edge& e) const { return graph->head(e); }
   9.411 +  
   9.412 +//     //template<typename I> bool valid(const I& i) const 
   9.413 +//     //  { return graph->valid(i); }
   9.414 +  
   9.415 +//     //template<typename I> void setInvalid(const I &i);
   9.416 +//     //{ return graph->setInvalid(i); }
   9.417 +  
   9.418 +//     //template<typename I> Node aNode(const I& e) const { 
   9.419 +//     //  return graph->aNode(e); }
   9.420 +//     //template<typename I> Node bNode(const I& e) const { 
   9.421 +//     //  return graph->bNode(e); }
   9.422 +
   9.423 +//     //Node addNode() const { return graph->addNode(); }
   9.424 +//     //Edge addEdge(const Node& tail, const Node& head) const { 
   9.425 +//     //  return graph->addEdge(tail, head); }
   9.426 +  
   9.427 +//     //int nodeNum() const { return graph->nodeNum(); }
   9.428 +//     //int edgeNum() const { return graph->edgeNum(); }
   9.429 +  
   9.430 +//     //template<typename I> void erase(const I& i) const { graph->erase(i); }
   9.431 +  
   9.432 +//     //void clear() const { graph->clear(); }
   9.433 +
   9.434 +//     template<typename T> class NodeMap : 
   9.435 +//       public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T> 
   9.436 +//     { 
   9.437 +//     public:
   9.438 +//       NodeMap(const RevGraphWrapper<GraphWrapper>& _gw) : 
   9.439 +// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw) { }
   9.440 +//       NodeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : 
   9.441 +// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw, a) { }
   9.442 +//     };
   9.443 +    
   9.444 +//     template<typename T> class EdgeMap : 
   9.445 +//       public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T> { 
   9.446 +//     public:
   9.447 +//       EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw) : 
   9.448 +// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw) { }
   9.449 +//       EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : 
   9.450 +// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw, a) { }
   9.451 +//     };
   9.452 +//   };
   9.453 +
   9.454 +  template<typename GraphWrapper>
   9.455 +  class RevGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
   9.456 +  public:
   9.457 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
   9.458 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
   9.459 +    //FIXME 
   9.460 +    //If GraphWrapper::OutEdgeIt is not defined
   9.461 +    //and we do not want to use RevGraphWrapper::InEdgeIt,
   9.462 +    //this won't work, because of typedef
   9.463 +    //OR
   9.464 +    //graphs have to define their non-existing iterators to void
   9.465 +    //Unfortunately all the typedefs are instantiated in templates, 
   9.466 +    //unlike other stuff
   9.467 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt InEdgeIt;
   9.468 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt OutEdgeIt;
   9.469 +
   9.470 +    RevGraphWrapper(GraphWrapper _gw) : 
   9.471 +      GraphWrapperSkeleton<GraphWrapper>(_gw) { }  
   9.472 +
   9.473 +    Node head(const Edge& e) const 
   9.474 +      { return GraphWrapperSkeleton<GraphWrapper>::tail(e); }
   9.475 +    Node tail(const Edge& e) const 
   9.476 +      { return GraphWrapperSkeleton<GraphWrapper>::head(e); }
   9.477 +  };
   9.478 +
   9.479 +  //Subgraph on the same node-set and partial edge-set
   9.480 +  template<typename GraphWrapper, typename EdgeFilterMap>
   9.481 +  class SubGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
   9.482 +  protected:
   9.483 +    EdgeFilterMap* filter_map;
   9.484 +  public:
   9.485 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
   9.486 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
   9.487 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
   9.488 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::EdgeIt EdgeIt;
   9.489 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt InEdgeIt;
   9.490 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OutEdgeIt;
   9.491 +
   9.492 +    SubGraphWrapper(GraphWrapper _gw, EdgeFilterMap& _filter_map) : 
   9.493 +      GraphWrapperSkeleton<GraphWrapper>(_gw), filter_map(&_filter_map) { }  
   9.494 +
   9.495 +    template<typename I> I& first(I& i) const { 
   9.496 +      gw.first(i); 
   9.497 +      while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
   9.498 +      return i;
   9.499 +    }
   9.500 +    template<typename I, typename P> I& first(I& i, const P& p) const { 
   9.501 +      gw.first(i, p); 
   9.502 +      while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
   9.503 +      return i;
   9.504 +    }
   9.505 +    
   9.506 +    //template<typename I> I getNext(const I& i) const { 
   9.507 +    //  return gw.getNext(i); 
   9.508 +    //}
   9.509 +    template<typename I> I& next(I &i) const { 
   9.510 +      gw.next(i); 
   9.511 +      while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
   9.512 +      return i;
   9.513 +    }
   9.514 +    
   9.515 +    template< typename It > It first() const { 
   9.516 +      It e; this->first(e); return e; }
   9.517 +    
   9.518 +    template< typename It > It first(const Node& v) const { 
   9.519 +      It e; this->first(e, v); return e; }
   9.520 +  };
   9.521 +
   9.522 +//   template<typename GraphWrapper>
   9.523 +//   class UndirGraphWrapper {
   9.524 +//   protected:
   9.525 +//     //Graph* graph;
   9.526 +//     GraphWrapper gw;
   9.527 +
   9.528 +//   public:
   9.529 +//     typedef GraphWrapper BaseGraph;
   9.530 +
   9.531 +//     typedef typename GraphWrapper::Node Node;
   9.532 +//     typedef typename GraphWrapper::NodeIt NodeIt;
   9.533 +
   9.534 +//     //typedef typename Graph::Edge Edge;
   9.535 +//     //typedef typename Graph::OutEdgeIt OutEdgeIt;
   9.536 +//     //typedef typename Graph::InEdgeIt InEdgeIt;
   9.537 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
   9.538 +//     //typedef typename Graph::EdgeIt EdgeIt;
   9.539 +
   9.540 +//     //private:
   9.541 +//     typedef typename GraphWrapper::Edge GraphEdge;
   9.542 +//     typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt;
   9.543 +//     typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt;
   9.544 +//     //public:
   9.545 +
   9.546 +//     //UndirGraphWrapper() : graph(0) { }
   9.547 +//     UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
   9.548 +
   9.549 +//     //void setGraph(Graph& _graph) { graph = &_graph; }
   9.550 +//     //Graph& getGraph() const { return (*graph); }
   9.551 +  
   9.552 +//     class Edge {
   9.553 +//       friend class UndirGraphWrapper<GraphWrapper>;
   9.554 +//       bool out_or_in; //true iff out
   9.555 +//       GraphOutEdgeIt out;
   9.556 +//       GraphInEdgeIt in;
   9.557 +//     public:
   9.558 +//       Edge() : out_or_in(), out(), in() { }
   9.559 +//       Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
   9.560 +//       operator GraphEdge() const {
   9.561 +// 	if (out_or_in) return(out); else return(in);
   9.562 +//       }
   9.563 +//       friend bool operator==(const Edge& u, const Edge& v) { 
   9.564 +// 	if (v.out_or_in) 
   9.565 +// 	  return (u.out_or_in && u.out==v.out);
   9.566 +// 	else
   9.567 +// 	  return (!u.out_or_in && u.in==v.in);
   9.568 +//       } 
   9.569 +//       friend bool operator!=(const Edge& u, const Edge& v) { 
   9.570 +// 	if (v.out_or_in) 
   9.571 +// 	  return (!u.out_or_in || u.out!=v.out);
   9.572 +// 	else
   9.573 +// 	  return (u.out_or_in || u.in!=v.in);
   9.574 +//       } 
   9.575 +//     };
   9.576 +
   9.577 +//     class OutEdgeIt : public Edge {
   9.578 +//       friend class UndirGraphWrapper<GraphWrapper>;
   9.579 +//     public:
   9.580 +//       OutEdgeIt() : Edge() { }
   9.581 +//       OutEdgeIt(const Invalid& i) : Edge(i) { }
   9.582 +//       OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) 
   9.583 +// 	: Edge() { 
   9.584 +// 	out_or_in=true;
   9.585 +// 	_G.gw.first(out, n);
   9.586 +// 	if (!(_G.gw.valid(out))) {
   9.587 +// 	  out_or_in=false;
   9.588 +// 	  _G.gw.first(in, n);
   9.589 +// 	}
   9.590 +//       }
   9.591 +//     };
   9.592 +
   9.593 +//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
   9.594 +//       e.out_or_in=true;
   9.595 +//       gw.first(e.out, n);
   9.596 +//       if (!(gw.valid(e.out))) {
   9.597 +// 	e.out_or_in=false;
   9.598 +// 	gw.first(e.in, n);
   9.599 +//       }
   9.600 +//       return e;
   9.601 +//     }
   9.602 +
   9.603 +//     OutEdgeIt& next(OutEdgeIt& e) const {
   9.604 +//       if (e.out_or_in) {
   9.605 +// 	Node n=gw.tail(e.out);
   9.606 +// 	gw.next(e.out);
   9.607 +// 	if (!gw.valid(e.out)) {
   9.608 +// 	  e.out_or_in=false;
   9.609 +// 	  gw.first(e.in, n);
   9.610 +// 	}
   9.611 +//       } else {
   9.612 +// 	gw.next(e.in);
   9.613 +//       }
   9.614 +//       return e;
   9.615 +//     }
   9.616 +
   9.617 +//     Node aNode(const OutEdgeIt& e) const { 
   9.618 +//       if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
   9.619 +//     Node bNode(const OutEdgeIt& e) const { 
   9.620 +//       if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
   9.621 +
   9.622 +//     typedef OutEdgeIt InEdgeIt; 
   9.623 +
   9.624 +//     template<typename I> I& first(I& i) const { return gw.first(i); }
   9.625 +// //     template<typename I, typename P> I& first(I& i, const P& p) const { 
   9.626 +// //       return graph->first(i, p); }
   9.627 +    
   9.628 +//     template<typename I> I getNext(const I& i) const { 
   9.629 +//       return gw.getNext(i); }
   9.630 +//     template<typename I> I& next(I &i) const { return gw.next(i); }    
   9.631 +
   9.632 +//     template< typename It > It first() const { 
   9.633 +//       It e; first(e); return e; }
   9.634 +
   9.635 +//     template< typename It > It first(const Node& v) const { 
   9.636 +//       It e; first(e, v); return e; }
   9.637 +
   9.638 +//     Node head(const Edge& e) const { return gw.head(e); }
   9.639 +//     Node tail(const Edge& e) const { return gw.tail(e); }
   9.640 +
   9.641 +//     template<typename I> bool valid(const I& i) const 
   9.642 +//       { return gw.valid(i); }
   9.643 +  
   9.644 +//     //template<typename I> void setInvalid(const I &i);
   9.645 +//     //{ return graph->setInvalid(i); }
   9.646 +
   9.647 +//     int nodeNum() const { return gw.nodeNum(); }
   9.648 +//     int edgeNum() const { return gw.edgeNum(); }
   9.649 +  
   9.650 +// //     template<typename I> Node aNode(const I& e) const { 
   9.651 +// //       return graph->aNode(e); }
   9.652 +// //     template<typename I> Node bNode(const I& e) const { 
   9.653 +// //       return graph->bNode(e); }
   9.654 +  
   9.655 +//     Node addNode() const { return gw.addNode(); }
   9.656 +// // FIXME: ez igy nem jo, mert nem
   9.657 +// //    Edge addEdge(const Node& tail, const Node& head) const { 
   9.658 +// //      return graph->addEdge(tail, head); }
   9.659 +  
   9.660 +//     template<typename I> void erase(const I& i) const { gw.erase(i); }
   9.661 +  
   9.662 +//     void clear() const { gw.clear(); }
   9.663 +    
   9.664 +//     template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
   9.665 +//     public:
   9.666 +//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
   9.667 +// 	GraphWrapper::NodeMap<T>(_G.gw) { }
   9.668 +//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
   9.669 +// 	GraphWrapper::NodeMap<T>(_G.gw, a) { }
   9.670 +//     };
   9.671 +
   9.672 +//     template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> { 
   9.673 +//     public:
   9.674 +//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
   9.675 +// 	GraphWrapper::EdgeMap<T>(_G.gw) { }
   9.676 +//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
   9.677 +// 	GraphWrapper::EdgeMap<T>(_G.gw, a) { }
   9.678 +//     };
   9.679 +//   };
   9.680 +
   9.681 +
   9.682 +  template<typename GraphWrapper>
   9.683 +  class UndirGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
   9.684 +  protected:
   9.685 +//    GraphWrapper gw;
   9.686 +
   9.687 +  public:
   9.688 +    //typedef GraphWrapper BaseGraph;
   9.689 +
   9.690 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
   9.691 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
   9.692 +
   9.693 +    //private:
   9.694 +    //FIXME ezeknek valojaban a GraphWrapper megfelelo dolgai kellene hogy 
   9.695 +    //legyenek, at kell irni
   9.696 +    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/
   9.697 +    GraphWrapper::Edge GraphEdge;
   9.698 +    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/ 
   9.699 +    GraphWrapper::OutEdgeIt GraphOutEdgeIt;
   9.700 +    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/ 
   9.701 +    GraphWrapper::InEdgeIt GraphInEdgeIt;
   9.702 +    //public:
   9.703 +
   9.704 +    //UndirGraphWrapper() : graph(0) { }
   9.705 +    UndirGraphWrapper(GraphWrapper _gw) : 
   9.706 +      GraphWrapperSkeleton<GraphWrapper>(_gw) { }  
   9.707 +
   9.708 +    //UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
   9.709 +
   9.710 +    //void setGraph(Graph& _graph) { graph = &_graph; }
   9.711 +    //Graph& getGraph() const { return (*graph); }
   9.712 +  
   9.713 +    class Edge {
   9.714 +      friend class UndirGraphWrapper<GraphWrapper>;
   9.715 +    protected:
   9.716 +      bool out_or_in; //true iff out
   9.717 +      GraphOutEdgeIt out;
   9.718 +      GraphInEdgeIt in;
   9.719 +    public:
   9.720 +      Edge() : out_or_in(), out(), in() { }
   9.721 +      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
   9.722 +      operator GraphEdge() const {
   9.723 +	if (out_or_in) return(out); else return(in);
   9.724 +      }
   9.725 +//FIXME
   9.726 +//2 edges are equal if they "refer" to the same physical edge 
   9.727 +//is it good?
   9.728 +      friend bool operator==(const Edge& u, const Edge& v) { 
   9.729 +	if (v.out_or_in) 
   9.730 +	  if (u.out_or_in) return (u.out==v.out); else return (u.out==v.in);
   9.731 +	//return (u.out_or_in && u.out==v.out);
   9.732 +	else
   9.733 +	  if (u.out_or_in) return (u.out==v.in); else return (u.in==v.in);
   9.734 +	//return (!u.out_or_in && u.in==v.in);
   9.735 +      } 
   9.736 +      friend bool operator!=(const Edge& u, const Edge& v) { 
   9.737 +	if (v.out_or_in) 
   9.738 +	  if (u.out_or_in) return (u.out!=v.out); else return (u.out!=v.in);
   9.739 +	//return (!u.out_or_in || u.out!=v.out);
   9.740 +	else
   9.741 +	  if (u.out_or_in) return (u.out!=v.in); else return (u.in!=v.in);
   9.742 +	//return (u.out_or_in || u.in!=v.in);
   9.743 +      } 
   9.744 +    };
   9.745 +
   9.746 +    class OutEdgeIt : public Edge {
   9.747 +      friend class UndirGraphWrapper<GraphWrapper>;
   9.748 +    public:
   9.749 +      OutEdgeIt() : Edge() { }
   9.750 +      OutEdgeIt(const Invalid& i) : Edge(i) { }
   9.751 +      OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) 
   9.752 +	: Edge() { 
   9.753 +	out_or_in=true; _G.gw.first(out, n);
   9.754 +	if (!(_G.gw.valid(out))) { out_or_in=false; _G.gw.first(in, n);	}
   9.755 +      }
   9.756 +    };
   9.757 +
   9.758 +    typedef OutEdgeIt InEdgeIt; 
   9.759 +
   9.760 +    class EdgeIt : public Edge {
   9.761 +      friend class UndirGraphWrapper<GraphWrapper>;
   9.762 +    protected:
   9.763 +      NodeIt v;
   9.764 +    public:
   9.765 +      EdgeIt() : Edge() { }
   9.766 +      EdgeIt(const Invalid& i) : Edge(i) { }
   9.767 +      EdgeIt(const UndirGraphWrapper<GraphWrapper>& _G) 
   9.768 +	: Edge() { 
   9.769 +	out_or_in=true;
   9.770 +	//Node v;
   9.771 +	_G.first(v);
   9.772 +	if (_G.valid(v)) _G.gw.first(out); else out=INVALID;
   9.773 +	while (_G.valid(v) && !_G.gw.valid(out)) { 
   9.774 +	  _G.gw.next(v); 
   9.775 +	  if (_G.valid(v)) _G.gw.first(out); 
   9.776 +	}
   9.777 +      }
   9.778 +    };
   9.779 +
   9.780 +    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
   9.781 +      e.out_or_in=true; gw.first(e.out, n);
   9.782 +      if (!(gw.valid(e.out))) { e.out_or_in=false; gw.first(e.in, n); }
   9.783 +      return e;
   9.784 +    }
   9.785 +
   9.786 +    EdgeIt& first(EdgeIt& e) const {
   9.787 +      e.out_or_in=true;
   9.788 +      //NodeIt v;
   9.789 +      first(e.v);
   9.790 +      if (valid(e.v)) gw.first(e.out, e.v); else e.out=INVALID;
   9.791 +      while (valid(e.v) && !gw.valid(e.out)) { 
   9.792 +	gw.next(e.v); 
   9.793 +	if (valid(e.v)) gw.first(e.out, e.v); 
   9.794 +      }
   9.795 +      return e;
   9.796 +    }
   9.797 +
   9.798 +    template<typename I> I& first(I& i) const { gw.first(i); return i; }
   9.799 +    template<typename I, typename P> I& first(I& i, const P& p) const { 
   9.800 +      gw.first(i, p); return i; }
   9.801 +
   9.802 +    OutEdgeIt& next(OutEdgeIt& e) const {
   9.803 +      if (e.out_or_in) {
   9.804 +	Node n=gw.tail(e.out);
   9.805 +	gw.next(e.out);
   9.806 +	if (!gw.valid(e.out)) { e.out_or_in=false; gw.first(e.in, n); }
   9.807 +      } else {
   9.808 +	gw.next(e.in);
   9.809 +      }
   9.810 +      return e;
   9.811 +    }
   9.812 +
   9.813 +    EdgeIt& next(EdgeIt& e) const {
   9.814 +      //NodeIt v=tail(e);
   9.815 +      gw.next(e.out);
   9.816 +      while (valid(e.v) && !gw.valid(e.out)) { 
   9.817 +	next(e.v); 
   9.818 +	if (valid(e.v)) gw.first(e.out, e.v); 
   9.819 +      }
   9.820 +      return e;
   9.821 +    }
   9.822 +
   9.823 +    template<typename I> I& next(I &i) const { return gw.next(i); }    
   9.824 +//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
   9.825 +
   9.826 +    template< typename It > It first() const { 
   9.827 +      It e; first(e); return e; }
   9.828 +
   9.829 +    template< typename It > It first(const Node& v) const { 
   9.830 +      It e; first(e, v); return e; }
   9.831 +
   9.832 +//    Node head(const Edge& e) const { return gw.head(e); }
   9.833 +//    Node tail(const Edge& e) const { return gw.tail(e); }
   9.834 +
   9.835 +//    template<typename I> bool valid(const I& i) const 
   9.836 +//      { return gw.valid(i); }
   9.837 +  
   9.838 +//    int nodeNum() const { return gw.nodeNum(); }
   9.839 +//    int edgeNum() const { return gw.edgeNum(); }
   9.840 +  
   9.841 +//     template<typename I> Node aNode(const I& e) const { 
   9.842 +//       return graph->aNode(e); }
   9.843 +//     template<typename I> Node bNode(const I& e) const { 
   9.844 +//       return graph->bNode(e); }
   9.845 +
   9.846 +    Node aNode(const OutEdgeIt& e) const { 
   9.847 +      if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
   9.848 +    Node bNode(const OutEdgeIt& e) const { 
   9.849 +      if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
   9.850 +  
   9.851 +//    Node addNode() const { return gw.addNode(); }
   9.852 +
   9.853 +// FIXME: ez igy nem jo, mert nem
   9.854 +//    Edge addEdge(const Node& tail, const Node& head) const { 
   9.855 +//      return graph->addEdge(tail, head); }
   9.856 +  
   9.857 +//    template<typename I> void erase(const I& i) const { gw.erase(i); }
   9.858 +  
   9.859 +//    void clear() const { gw.clear(); }
   9.860 +    
   9.861 +//     template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
   9.862 +//     public:
   9.863 +//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
   9.864 +// 	GraphWrapper::NodeMap<T>(_G.gw) { }
   9.865 +//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
   9.866 +// 	GraphWrapper::NodeMap<T>(_G.gw, a) { }
   9.867 +//     };
   9.868 +
   9.869 +//     template<typename T> class EdgeMap : 
   9.870 +//       public GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T> { 
   9.871 +//     public:
   9.872 +//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
   9.873 +// 	GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T>(_G.gw) { }
   9.874 +//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
   9.875 +// 	GraphWrapper::EdgeMap<T>(_G.gw, a) { }
   9.876 +//     };
   9.877 +   };
   9.878 +
   9.879 +
   9.880 +
   9.881 +
   9.882 +
   9.883 +//   template<typename Graph>
   9.884 +//   class SymGraphWrapper
   9.885 +//   {
   9.886 +//     Graph* graph;
   9.887 +  
   9.888 +//   public:
   9.889 +//     typedef Graph BaseGraph;
   9.890 +
   9.891 +//     typedef typename Graph::Node Node;
   9.892 +//     typedef typename Graph::Edge Edge;
   9.893 +  
   9.894 +//     typedef typename Graph::NodeIt NodeIt;
   9.895 +    
   9.896 +//     //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
   9.897 +//     //iranyitatlant, ami van
   9.898 +//     //mert csak 1 dolgot lehet be typedef-elni
   9.899 +//     typedef typename Graph::OutEdgeIt SymEdgeIt;
   9.900 +//     //typedef typename Graph::InEdgeIt SymEdgeIt;
   9.901 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
   9.902 +//     typedef typename Graph::EdgeIt EdgeIt;
   9.903 +
   9.904 +//     int nodeNum() const { return graph->nodeNum(); }
   9.905 +//     int edgeNum() const { return graph->edgeNum(); }
   9.906 +    
   9.907 +//     template<typename I> I& first(I& i) const { return graph->first(i); }
   9.908 +//     template<typename I, typename P> I& first(I& i, const P& p) const { 
   9.909 +//       return graph->first(i, p); }
   9.910 +//     //template<typename I> I next(const I i); { return graph->goNext(i); }
   9.911 +//     //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
   9.912 +
   9.913 +//     template< typename It > It first() const { 
   9.914 +//       It e; first(e); return e; }
   9.915 +
   9.916 +//     template< typename It > It first(Node v) const { 
   9.917 +//       It e; first(e, v); return e; }
   9.918 +
   9.919 +//     Node head(const Edge& e) const { return graph->head(e); }
   9.920 +//     Node tail(const Edge& e) const { return graph->tail(e); }
   9.921 +  
   9.922 +//     template<typename I> Node aNode(const I& e) const { 
   9.923 +//       return graph->aNode(e); }
   9.924 +//     template<typename I> Node bNode(const I& e) const { 
   9.925 +//       return graph->bNode(e); }
   9.926 +  
   9.927 +//     //template<typename I> bool valid(const I i);
   9.928 +//     //{ return graph->valid(i); }
   9.929 +  
   9.930 +//     //template<typename I> void setInvalid(const I &i);
   9.931 +//     //{ return graph->setInvalid(i); }
   9.932 +  
   9.933 +//     Node addNode() { return graph->addNode(); }
   9.934 +//     Edge addEdge(const Node& tail, const Node& head) { 
   9.935 +//       return graph->addEdge(tail, head); }
   9.936 +  
   9.937 +//     template<typename I> void erase(const I& i) { graph->erase(i); }
   9.938 +  
   9.939 +//     void clear() { graph->clear(); }
   9.940 +  
   9.941 +//     template<typename T> class NodeMap : public Graph::NodeMap<T> { };
   9.942 +//     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
   9.943 +  
   9.944 +//     void setGraph(Graph& _graph) { graph = &_graph; }
   9.945 +//     Graph& getGraph() { return (*graph); }
   9.946 +
   9.947 +//     //SymGraphWrapper() : graph(0) { }
   9.948 +//     SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
   9.949 +//   };
   9.950 +
   9.951 +
   9.952 +  template<typename GraphWrapper, typename Number, typename FlowMap, typename CapacityMap>
   9.953 +  class ResGraphWrapper : public GraphWrapperSkeleton<GraphWrapper>{
   9.954 +  public:
   9.955 +    //typedef Graph BaseGraph;
   9.956 +    //typedef TrivGraphWrapper<const Graph> GraphWrapper;
   9.957 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
   9.958 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
   9.959 +  private:
   9.960 +    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/
   9.961 +    GraphWrapper::OutEdgeIt OldOutEdgeIt;
   9.962 +    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/
   9.963 +    GraphWrapper::InEdgeIt OldInEdgeIt;
   9.964 +  protected:
   9.965 +    //const Graph* graph;
   9.966 +    //GraphWrapper gw;
   9.967 +    FlowMap* flow;
   9.968 +    const CapacityMap* capacity;
   9.969 +  public:
   9.970 +
   9.971 +    ResGraphWrapper(const GraphWrapper& _gw, FlowMap& _flow, 
   9.972 +		    const CapacityMap& _capacity) : 
   9.973 +      GraphWrapperSkeleton<GraphWrapper>(_gw), 
   9.974 +      flow(&_flow), capacity(&_capacity) { }
   9.975 +
   9.976 +    //void setGraph(const Graph& _graph) { graph = &_graph; }
   9.977 +    //const Graph& getGraph() const { return (*graph); }
   9.978 +
   9.979 +    class Edge; 
   9.980 +    class OutEdgeIt; 
   9.981 +    friend class Edge; 
   9.982 +    friend class OutEdgeIt; 
   9.983 +
   9.984 +    class Edge {
   9.985 +      friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
   9.986 +    protected:
   9.987 +      bool out_or_in; //true, iff out
   9.988 +      OldOutEdgeIt out;
   9.989 +      OldInEdgeIt in;
   9.990 +    public:
   9.991 +      Edge() : out_or_in(true) { } 
   9.992 +      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
   9.993 +//       bool valid() const { 
   9.994 +// 	return out_or_in && out.valid() || in.valid(); }
   9.995 +      friend bool operator==(const Edge& u, const Edge& v) { 
   9.996 +	if (v.out_or_in) 
   9.997 +	  return (u.out_or_in && u.out==v.out);
   9.998 +	else
   9.999 +	  return (!u.out_or_in && u.in==v.in);
  9.1000 +      } 
  9.1001 +      friend bool operator!=(const Edge& u, const Edge& v) { 
  9.1002 +	if (v.out_or_in) 
  9.1003 +	  return (!u.out_or_in || u.out!=v.out);
  9.1004 +	else
  9.1005 +	  return (u.out_or_in || u.in!=v.in);
  9.1006 +      } 
  9.1007 +    };
  9.1008 +
  9.1009 +
  9.1010 +    class OutEdgeIt : public Edge {
  9.1011 +      friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
  9.1012 +    public:
  9.1013 +      OutEdgeIt() { }
  9.1014 +      //FIXME
  9.1015 +      OutEdgeIt(const Edge& e) : Edge(e) { }
  9.1016 +      OutEdgeIt(const Invalid& i) : Edge(i) { }
  9.1017 +    protected:
  9.1018 +      OutEdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() { 
  9.1019 +	resG.gw.first(out, v);
  9.1020 +	while( resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }
  9.1021 +	if (!resG.gw.valid(out)) {
  9.1022 +	  out_or_in=0;
  9.1023 +	  resG.gw.first(in, v);
  9.1024 +	  while( resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }
  9.1025 +	}
  9.1026 +      }
  9.1027 +//     public:
  9.1028 +//       OutEdgeIt& operator++() { 
  9.1029 +// 	if (out_or_in) {
  9.1030 +// 	  Node v=/*resG->*/G->aNode(out);
  9.1031 +// 	  ++out;
  9.1032 +// 	  while( out.valid() && !(Edge::resCap()>0) ) { ++out; }
  9.1033 +// 	  if (!out.valid()) {
  9.1034 +// 	    out_or_in=0;
  9.1035 +// 	    G->first(in, v); 
  9.1036 +// 	    while( in.valid() && !(Edge::resCap()>0) ) { ++in; }
  9.1037 +// 	  }
  9.1038 +// 	} else {
  9.1039 +// 	  ++in;
  9.1040 +// 	  while( in.valid() && !(Edge::resCap()>0) ) { ++in; } 
  9.1041 +// 	}
  9.1042 +// 	return *this; 
  9.1043 +//       }
  9.1044 +    };
  9.1045 +
  9.1046 +    //FIXME This is just for having InEdgeIt
  9.1047 +    typedef void InEdgeIt;
  9.1048 +
  9.1049 +    class EdgeIt : public Edge {
  9.1050 +      friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
  9.1051 +      NodeIt v; 
  9.1052 +    public:
  9.1053 +      EdgeIt() { }
  9.1054 +      //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }
  9.1055 +      EdgeIt(const Invalid& i) : Edge(i) { }
  9.1056 +      EdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG) : Edge() { 
  9.1057 +	resG.gw.first(v);
  9.1058 +	if (resG.gw.valid(v)) resG.gw.first(out, v); else out=INVALID;
  9.1059 +	while (resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }
  9.1060 +	while (resG.gw.valid(v) && !resG.gw.valid(out)) { 
  9.1061 +	  resG.gw.next(v); 
  9.1062 +	  if (resG.gw.valid(v)) resG.gw.first(out, v); 
  9.1063 +	  while (resG.gw.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }
  9.1064 +	}
  9.1065 +	if (!resG.gw.valid(out)) {
  9.1066 +	  out_or_in=0;
  9.1067 +	  resG.gw.first(v);
  9.1068 +	  if (resG.gw.valid(v)) resG.gw.first(in, v); else in=INVALID;
  9.1069 +	  while (resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }
  9.1070 +	  while (resG.gw.valid(v) && !resG.gw.valid(in)) { 
  9.1071 +	    resG.gw.next(v); 
  9.1072 +	    if (resG.gw.valid(v)) resG.gw.first(in, v); 
  9.1073 +	    while (resG.gw.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }
  9.1074 +	  }
  9.1075 +	}
  9.1076 +      }
  9.1077 +//       EdgeIt& operator++() { 
  9.1078 +// 	if (out_or_in) {
  9.1079 +// 	  ++out;
  9.1080 +// 	  while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
  9.1081 +// 	  while (v.valid() && !out.valid()) { 
  9.1082 +// 	    ++v; 
  9.1083 +// 	    if (v.valid()) G->first(out, v); 
  9.1084 +// 	    while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
  9.1085 +// 	  }
  9.1086 +// 	  if (!out.valid()) {
  9.1087 +// 	    out_or_in=0;
  9.1088 +// 	    G->first(v);
  9.1089 +// 	    if (v.valid()) G->first(in, v); else in=OldInEdgeIt();
  9.1090 +// 	    while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
  9.1091 +// 	    while (v.valid() && !in.valid()) { 
  9.1092 +// 	      ++v; 
  9.1093 +// 	      if (v.valid()) G->first(in, v); 
  9.1094 +// 	      while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
  9.1095 +// 	    }  
  9.1096 +// 	  }
  9.1097 +// 	} else {
  9.1098 +// 	  ++in;
  9.1099 +// 	  while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
  9.1100 +// 	  while (v.valid() && !in.valid()) { 
  9.1101 +// 	    ++v; 
  9.1102 +// 	    if (v.valid()) G->first(in, v); 
  9.1103 +// 	    while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
  9.1104 +// 	  }
  9.1105 +// 	}
  9.1106 +// 	return *this;
  9.1107 +//       }
  9.1108 +    };
  9.1109 +
  9.1110 +    NodeIt& first(NodeIt& v) const { gw.first(v); return v; }
  9.1111 +    OutEdgeIt& first(OutEdgeIt& e, Node v) const { 
  9.1112 +      e=OutEdgeIt(*this, v); 
  9.1113 +      return e;
  9.1114 +    }
  9.1115 +    EdgeIt& first(EdgeIt& e) const { 
  9.1116 +      e=EdgeIt(*this); 
  9.1117 +      return e;
  9.1118 +    }
  9.1119 +   
  9.1120 +    NodeIt& next(NodeIt& n) const { return gw.next(n); }
  9.1121 +
  9.1122 +    OutEdgeIt& next(OutEdgeIt& e) const { 
  9.1123 +      if (e.out_or_in) {
  9.1124 +	Node v=gw.aNode(e.out);
  9.1125 +	gw.next(e.out);
  9.1126 +	while( gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }
  9.1127 +	if (!gw.valid(e.out)) {
  9.1128 +	  e.out_or_in=0;
  9.1129 +	  gw.first(e.in, v); 
  9.1130 +	  while( gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
  9.1131 +	}
  9.1132 +      } else {
  9.1133 +	gw.next(e.in);
  9.1134 +	while( gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); } 
  9.1135 +      }
  9.1136 +      return e;
  9.1137 +    }
  9.1138 +
  9.1139 +    EdgeIt& next(EdgeIt& e) const { 
  9.1140 +      if (e.out_or_in) {
  9.1141 +	gw.next(e.out);
  9.1142 +	while (gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }
  9.1143 +	  while (gw.valid(e.v) && !gw.valid(e.out)) { 
  9.1144 +	    gw.next(e.v); 
  9.1145 +	    if (gw.valid(e.v)) gw.first(e.out, e.v); 
  9.1146 +	    while (gw.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }
  9.1147 +	  }
  9.1148 +	  if (!gw.valid(e.out)) {
  9.1149 +	    e.out_or_in=0;
  9.1150 +	    gw.first(e.v);
  9.1151 +	    if (gw.valid(e.v)) gw.first(e.in, e.v); else e.in=INVALID;
  9.1152 +	    while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
  9.1153 +	    while (gw.valid(e.v) && !gw.valid(e.in)) { 
  9.1154 +	      gw.next(e.v); 
  9.1155 +	      if (gw.valid(e.v)) gw.first(e.in, e.v); 
  9.1156 +	      while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
  9.1157 +	    }  
  9.1158 +	  }
  9.1159 +	} else {
  9.1160 +	  gw.next(e.in);
  9.1161 +	  while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
  9.1162 +	  while (gw.valid(e.v) && !gw.valid(e.in)) { 
  9.1163 +	    gw.next(e.v); 
  9.1164 +	    if (gw.valid(e.v)) gw.first(e.in, e.v); 
  9.1165 +	    while (gw.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }
  9.1166 +	  }
  9.1167 +	}
  9.1168 +	return e;
  9.1169 +      }
  9.1170 +    
  9.1171 +
  9.1172 +    template< typename It >
  9.1173 +    It first() const { 
  9.1174 +      It e;
  9.1175 +      first(e);
  9.1176 +      return e; 
  9.1177 +    }
  9.1178 +
  9.1179 +    template< typename It >
  9.1180 +    It first(Node v) const { 
  9.1181 +      It e;
  9.1182 +      first(e, v);
  9.1183 +      return e; 
  9.1184 +    }
  9.1185 +
  9.1186 +    Node tail(Edge e) const { 
  9.1187 +      return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); }
  9.1188 +    Node head(Edge e) const { 
  9.1189 +      return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); }
  9.1190 +
  9.1191 +    Node aNode(OutEdgeIt e) const { 
  9.1192 +      return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); }
  9.1193 +    Node bNode(OutEdgeIt e) const { 
  9.1194 +      return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); }
  9.1195 +
  9.1196 +    int nodeNum() const { return gw.nodeNum(); }
  9.1197 +    //FIXME
  9.1198 +    //int edgeNum() const { return gw.edgeNum(); }
  9.1199 +
  9.1200 +
  9.1201 +    int id(Node v) const { return gw.id(v); }
  9.1202 +
  9.1203 +    bool valid(Node n) const { return gw.valid(n); }
  9.1204 +    bool valid(Edge e) const { 
  9.1205 +      return e.out_or_in ? gw.valid(e.out) : gw.valid(e.in); }
  9.1206 +
  9.1207 +    void augment(const Edge& e, Number a) const {
  9.1208 +      if (e.out_or_in)  
  9.1209 +	flow->set(e.out, flow->get(e.out)+a);
  9.1210 +      else  
  9.1211 +	flow->set(e.in, flow->get(e.in)-a);
  9.1212 +    }
  9.1213 +
  9.1214 +    Number resCap(const Edge& e) const { 
  9.1215 +      if (e.out_or_in) 
  9.1216 +	return (capacity->get(e.out)-flow->get(e.out)); 
  9.1217 +      else 
  9.1218 +	return (flow->get(e.in)); 
  9.1219 +    }
  9.1220 +
  9.1221 +    Number resCap(OldOutEdgeIt out) const { 
  9.1222 +      return (capacity->get(out)-flow->get(out)); 
  9.1223 +    }
  9.1224 +    
  9.1225 +    Number resCap(OldInEdgeIt in) const { 
  9.1226 +      return (flow->get(in)); 
  9.1227 +    }
  9.1228 +
  9.1229 +//     template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
  9.1230 +//     public:
  9.1231 +//       NodeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G) 
  9.1232 +// 	: GraphWrapper::NodeMap<T>(_G.gw) { }
  9.1233 +//       NodeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G, 
  9.1234 +// 	      T a) : GraphWrapper::NodeMap<T>(_G.gw, a) { }
  9.1235 +//     };
  9.1236 +
  9.1237 +//     template <typename T>
  9.1238 +//     class NodeMap {
  9.1239 +//       typename Graph::NodeMap<T> node_map; 
  9.1240 +//     public:
  9.1241 +//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { }
  9.1242 +//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { }
  9.1243 +//       void set(Node nit, T a) { node_map.set(nit, a); }
  9.1244 +//       T get(Node nit) const { return node_map.get(nit); }
  9.1245 +//     };
  9.1246 +
  9.1247 +    template <typename T>
  9.1248 +    class EdgeMap {
  9.1249 +      typename GraphWrapper::EdgeMap<T> forward_map, backward_map; 
  9.1250 +    public:
  9.1251 +      EdgeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.gw), backward_map(_G.gw) { }
  9.1252 +      EdgeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.gw, a), backward_map(_G.gw, a) { }
  9.1253 +      void set(Edge e, T a) { 
  9.1254 +	if (e.out_or_in) 
  9.1255 +	  forward_map.set(e.out, a); 
  9.1256 +	else 
  9.1257 +	  backward_map.set(e.in, a); 
  9.1258 +      }
  9.1259 +      T get(Edge e) { 
  9.1260 +	if (e.out_or_in) 
  9.1261 +	  return forward_map.get(e.out); 
  9.1262 +	else 
  9.1263 +	  return backward_map.get(e.in); 
  9.1264 +      }
  9.1265 +    };
  9.1266 +  };
  9.1267 +
  9.1268 +  //Subgraph on the same node-set and partial edge-set
  9.1269 +  template<typename GraphWrapper, typename FirstOutEdgesMap>
  9.1270 +  class ErasingFirstGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> {
  9.1271 +  protected:
  9.1272 +    FirstOutEdgesMap* first_out_edges;
  9.1273 +  public:
  9.1274 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node;
  9.1275 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt;
  9.1276 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge;
  9.1277 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::EdgeIt EdgeIt;
  9.1278 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt InEdgeIt;
  9.1279 +    typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OutEdgeIt;
  9.1280 +
  9.1281 +    ErasingFirstGraphWrapper(GraphWrapper _gw, FirstOutEdgesMap& _first_out_edges) : 
  9.1282 +      GraphWrapperSkeleton<GraphWrapper>(_gw), first_out_edges(&_first_out_edges) { }  
  9.1283 +
  9.1284 +    template<typename I> I& first(I& i) const { 
  9.1285 +      gw.first(i); 
  9.1286 +      //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
  9.1287 +      return i;
  9.1288 +    }
  9.1289 +    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
  9.1290 +      e=first_out_edges->get(n);
  9.1291 +      return e;
  9.1292 +    }
  9.1293 +    template<typename I, typename P> I& first(I& i, const P& p) const { 
  9.1294 +      gw.first(i, p); 
  9.1295 +      //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
  9.1296 +      return i;
  9.1297 +    }
  9.1298 +    
  9.1299 +    //template<typename I> I getNext(const I& i) const { 
  9.1300 +    //  return gw.getNext(i); 
  9.1301 +    //}
  9.1302 +    template<typename I> I& next(I &i) const { 
  9.1303 +      gw.next(i); 
  9.1304 +      //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
  9.1305 +      return i;
  9.1306 +    }
  9.1307 +    
  9.1308 +    template< typename It > It first() const { 
  9.1309 +      It e; this->first(e); return e; }
  9.1310 +    
  9.1311 +    template< typename It > It first(const Node& v) const { 
  9.1312 +      It e; this->first(e, v); return e; }
  9.1313 +
  9.1314 +    void erase(const OutEdgeIt& e) const {
  9.1315 +      OutEdgeIt f=e;
  9.1316 +      this->next(f);
  9.1317 +      first_out_edges->set(this->tail(e), f);
  9.1318 +    }
  9.1319 +  };
  9.1320 +
  9.1321 +//   template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
  9.1322 +//   class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
  9.1323 +//   protected:
  9.1324 +//     ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
  9.1325 +//     //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
  9.1326 +//   public:
  9.1327 +//     ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow, 
  9.1328 +// 			   const CapacityMap& _capacity) : 
  9.1329 +//       ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), 
  9.1330 +//       first_out_edges(*this) /*, dist(*this)*/ { 
  9.1331 +//       for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) {
  9.1332 +// 	OutEdgeIt e;
  9.1333 +// 	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
  9.1334 +// 	first_out_edges.set(n, e);
  9.1335 +//       }
  9.1336 +//     }
  9.1337 +
  9.1338 +//     //void setGraph(Graph& _graph) { graph = &_graph; }
  9.1339 +//     //Graph& getGraph() const { return (*graph); }
  9.1340 +  
  9.1341 +//     //TrivGraphWrapper() : graph(0) { }
  9.1342 +//     //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { }
  9.1343 +
  9.1344 +//     //typedef Graph BaseGraph;
  9.1345 +
  9.1346 +//     //typedef typename Graph::Node Node;
  9.1347 +//     //typedef typename Graph::NodeIt NodeIt;
  9.1348 +
  9.1349 +//     //typedef typename Graph::Edge Edge;
  9.1350 +//     //typedef typename Graph::OutEdgeIt OutEdgeIt;
  9.1351 +//     //typedef typename Graph::InEdgeIt InEdgeIt;
  9.1352 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
  9.1353 +//     //typedef typename Graph::EdgeIt EdgeIt;
  9.1354 +
  9.1355 +//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
  9.1356 +//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
  9.1357 +
  9.1358 +//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
  9.1359 +//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
  9.1360 +//     //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
  9.1361 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
  9.1362 +//     //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
  9.1363 +
  9.1364 +//     NodeIt& first(NodeIt& n) const { 
  9.1365 +//       return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
  9.1366 +//     }
  9.1367 +
  9.1368 +//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { 
  9.1369 +//       e=first_out_edges.get(n);
  9.1370 +//       return e;
  9.1371 +//     }
  9.1372 +    
  9.1373 +//     //ROSSZ template<typename I> I& first(I& i) const { return first(i); }
  9.1374 +//     //ROSSZ template<typename I, typename P> I& first(I& i, const P& p) const { 
  9.1375 +//     //  return first(i, p); }
  9.1376 +    
  9.1377 +//     //template<typename I> I getNext(const I& i) const { 
  9.1378 +//     //  return gw.getNext(i); }
  9.1379 +//     //template<typename I> I& next(I &i) const { return gw.next(i); }    
  9.1380 +
  9.1381 +//     template< typename It > It first() const { 
  9.1382 +//       It e; first(e); return e; }
  9.1383 +
  9.1384 +//     template< typename It > It first(const Node& v) const { 
  9.1385 +//       It e; first(e, v); return e; }
  9.1386 +
  9.1387 +//     //Node head(const Edge& e) const { return gw.head(e); }
  9.1388 +//     //Node tail(const Edge& e) const { return gw.tail(e); }
  9.1389 +
  9.1390 +//     //template<typename I> bool valid(const I& i) const 
  9.1391 +//     //  { return gw.valid(i); }
  9.1392 +  
  9.1393 +//     //int nodeNum() const { return gw.nodeNum(); }
  9.1394 +//     //int edgeNum() const { return gw.edgeNum(); }
  9.1395 +  
  9.1396 +//     //template<typename I> Node aNode(const I& e) const { 
  9.1397 +//     //  return gw.aNode(e); }
  9.1398 +//     //template<typename I> Node bNode(const I& e) const { 
  9.1399 +//     //  return gw.bNode(e); }
  9.1400 +  
  9.1401 +//     //Node addNode() const { return gw.addNode(); }
  9.1402 +//     //Edge addEdge(const Node& tail, const Node& head) const { 
  9.1403 +//     //  return gw.addEdge(tail, head); }
  9.1404 +  
  9.1405 +//     //void erase(const OutEdgeIt& e) {
  9.1406 +//     //  first_out_edge(this->tail(e))=e;
  9.1407 +//     //}
  9.1408 +//     void erase(const Edge& e) {
  9.1409 +//       OutEdgeIt f(e);
  9.1410 +//       next(f);
  9.1411 +//       first_out_edges.set(this->tail(e), f);
  9.1412 +//     }
  9.1413 +//     //template<typename I> void erase(const I& i) const { gw.erase(i); }
  9.1414 +  
  9.1415 +//     //void clear() const { gw.clear(); }
  9.1416 +    
  9.1417 +//     template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { 
  9.1418 +//     public:
  9.1419 +//       NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : 
  9.1420 +// 	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
  9.1421 +//       NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : 
  9.1422 +// 	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
  9.1423 +//     };
  9.1424 +
  9.1425 +//     template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { 
  9.1426 +//     public:
  9.1427 +//       EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : 
  9.1428 +// 	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
  9.1429 +//       EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : 
  9.1430 +// 	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
  9.1431 +//     };
  9.1432 +//   };
  9.1433 +
  9.1434 +//   template<typename GraphWrapper> 
  9.1435 +//   class FilterGraphWrapper {
  9.1436 +//   };
  9.1437 +
  9.1438 +//   template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
  9.1439 +//   class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
  9.1440 +
  9.1441 +//     //Graph* graph;
  9.1442 +  
  9.1443 +//   public:
  9.1444 +//     //typedef Graph BaseGraph;
  9.1445 +
  9.1446 +//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
  9.1447 +//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
  9.1448 +
  9.1449 +//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
  9.1450 +//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
  9.1451 +//     //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
  9.1452 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
  9.1453 +//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
  9.1454 +
  9.1455 +//     //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
  9.1456 +    
  9.1457 +//   public:
  9.1458 +//     FilterGraphWrapper(const Graph& _G, FlowMap& _flow, 
  9.1459 +// 			   const CapacityMap& _capacity) : 
  9.1460 +//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, gw.nodeNum()) { 
  9.1461 +//     }
  9.1462 +
  9.1463 +//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
  9.1464 +//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
  9.1465 +//       while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e)))) 
  9.1466 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
  9.1467 +//       return e;
  9.1468 +//     }
  9.1469 +
  9.1470 +//     NodeIt& next(NodeIt& e) const {
  9.1471 +//       return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
  9.1472 +//     }
  9.1473 +
  9.1474 +//     OutEdgeIt& next(OutEdgeIt& e) const {
  9.1475 +//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
  9.1476 +//       while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e)))) 
  9.1477 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
  9.1478 +//       return e;
  9.1479 +//     }
  9.1480 +
  9.1481 +//     NodeIt& first(NodeIt& n) const {
  9.1482 +//       return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
  9.1483 +//     }
  9.1484 +
  9.1485 +//     void erase(const Edge& e) {
  9.1486 +//       OutEdgeIt f(e);
  9.1487 +//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
  9.1488 +//       while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f)))) 
  9.1489 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
  9.1490 +//       first_out_edges.set(this->tail(e), f);
  9.1491 +//     }
  9.1492 +
  9.1493 +//     //TrivGraphWrapper() : graph(0) { }
  9.1494 +//     //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
  9.1495 +
  9.1496 +//     //void setGraph(Graph& _graph) { graph = &_graph; }
  9.1497 +//     //Graph& getGraph() const { return (*graph); }
  9.1498 +    
  9.1499 +//     //template<typename I> I& first(I& i) const { return gw.first(i); }
  9.1500 +//     //template<typename I, typename P> I& first(I& i, const P& p) const { 
  9.1501 +//     //  return gw.first(i, p); }
  9.1502 +    
  9.1503 +//     //template<typename I> I getNext(const I& i) const { 
  9.1504 +//     //  return gw.getNext(i); }
  9.1505 +//     //template<typename I> I& next(I &i) const { return gw.next(i); }    
  9.1506 +
  9.1507 +//     template< typename It > It first() const { 
  9.1508 +//       It e; first(e); return e; }
  9.1509 +
  9.1510 +//     template< typename It > It first(const Node& v) const { 
  9.1511 +//       It e; first(e, v); return e; }
  9.1512 +
  9.1513 +//     //Node head(const Edge& e) const { return gw.head(e); }
  9.1514 +//     //Node tail(const Edge& e) const { return gw.tail(e); }
  9.1515 +
  9.1516 +//     //template<typename I> bool valid(const I& i) const 
  9.1517 +//     //  { return gw.valid(i); }
  9.1518 +  
  9.1519 +//     //template<typename I> void setInvalid(const I &i);
  9.1520 +//     //{ return gw.setInvalid(i); }
  9.1521 +
  9.1522 +//     //int nodeNum() const { return gw.nodeNum(); }
  9.1523 +//     //int edgeNum() const { return gw.edgeNum(); }
  9.1524 +  
  9.1525 +//     //template<typename I> Node aNode(const I& e) const { 
  9.1526 +//     //  return gw.aNode(e); }
  9.1527 +//     //template<typename I> Node bNode(const I& e) const { 
  9.1528 +//     //  return gw.bNode(e); }
  9.1529 +  
  9.1530 +//     //Node addNode() const { return gw.addNode(); }
  9.1531 +//     //Edge addEdge(const Node& tail, const Node& head) const { 
  9.1532 +//     //  return gw.addEdge(tail, head); }
  9.1533 +  
  9.1534 +//     //template<typename I> void erase(const I& i) const { gw.erase(i); }
  9.1535 +  
  9.1536 +//     //void clear() const { gw.clear(); }
  9.1537 +    
  9.1538 +//     template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { 
  9.1539 +//     public:
  9.1540 +//       NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : 
  9.1541 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
  9.1542 +//       NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : 
  9.1543 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
  9.1544 +//     };
  9.1545 +
  9.1546 +//     template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { 
  9.1547 +//     public:
  9.1548 +//       EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : 
  9.1549 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
  9.1550 +//       EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : 
  9.1551 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
  9.1552 +//     };
  9.1553 +
  9.1554 +//   public:
  9.1555 +//     ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
  9.1556 +
  9.1557 +//   };
  9.1558 +
  9.1559 +
  9.1560 +
  9.1561 +// // FIXME: comparison should be made better!!!
  9.1562 +//   template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
  9.1563 +//   class ResGraphWrapper
  9.1564 +//   {
  9.1565 +//     Graph* graph;
  9.1566 +  
  9.1567 +//   public:
  9.1568 +//     typedef Graph BaseGraph;
  9.1569 +
  9.1570 +//     typedef typename Graph::Node Node;
  9.1571 +//     typedef typename Graph::Edge Edge;
  9.1572 +  
  9.1573 +//     typedef typename Graph::NodeIt NodeIt;
  9.1574 +   
  9.1575 +//     class OutEdgeIt {
  9.1576 +//     public:
  9.1577 +//       //Graph::Node n;
  9.1578 +//       bool out_or_in;
  9.1579 +//       typename Graph::OutEdgeIt o;
  9.1580 +//       typename Graph::InEdgeIt i;   
  9.1581 +//     };
  9.1582 +//     class InEdgeIt {
  9.1583 +//     public:
  9.1584 +//       //Graph::Node n;
  9.1585 +//       bool out_or_in;
  9.1586 +//       typename Graph::OutEdgeIt o;
  9.1587 +//       typename Graph::InEdgeIt i;   
  9.1588 +//     };
  9.1589 +//     typedef typename Graph::SymEdgeIt SymEdgeIt;
  9.1590 +//     typedef typename Graph::EdgeIt EdgeIt;
  9.1591 +
  9.1592 +//     int nodeNum() const { return gw.nodeNum(); }
  9.1593 +//     int edgeNum() const { return gw.edgeNum(); }
  9.1594 +
  9.1595 +//     Node& first(Node& n) const { return gw.first(n); }
  9.1596 +
  9.1597 +//     // Edge and SymEdge  is missing!!!!
  9.1598 +//     // Edge <-> In/OutEdgeIt conversion is missing!!!!
  9.1599 +
  9.1600 +//     //FIXME
  9.1601 +//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const 
  9.1602 +//       {
  9.1603 +// 	e.n=n;
  9.1604 +// 	gw.first(e.o,n);
  9.1605 +// 	while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
  9.1606 +// 	  gw.goNext(e.o);
  9.1607 +// 	if(!gw.valid(e.o)) {
  9.1608 +// 	  gw.first(e.i,n);
  9.1609 +// 	  while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
  9.1610 +// 	    gw.goNext(e.i);
  9.1611 +// 	}
  9.1612 +// 	return e;
  9.1613 +//       }
  9.1614 +// /*
  9.1615 +//   OutEdgeIt &goNext(OutEdgeIt &e)
  9.1616 +//   {
  9.1617 +//   if(gw.valid(e.o)) {
  9.1618 +//   while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
  9.1619 +//   gw.goNext(e.o);
  9.1620 +//   if(gw.valid(e.o)) return e;
  9.1621 +//   else gw.first(e.i,e.n);
  9.1622 +//   }
  9.1623 +//   else {
  9.1624 +//   while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
  9.1625 +//   gw.goNext(e.i);
  9.1626 +//   return e;
  9.1627 +//   }
  9.1628 +//   }
  9.1629 +//   OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
  9.1630 +// */
  9.1631 +//     //bool valid(const OutEdgeIt e) { return gw.valid(e.o)||gw.valid(e.i);}
  9.1632 +
  9.1633 +//     //FIXME
  9.1634 +//     InEdgeIt& first(InEdgeIt& e, const Node& n) const 
  9.1635 +//       {
  9.1636 +// 	e.n=n;
  9.1637 +// 	gw.first(e.i,n);
  9.1638 +// 	while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
  9.1639 +// 	  gw.goNext(e.i);
  9.1640 +// 	if(!gw.valid(e.i)) {
  9.1641 +// 	  gw.first(e.o,n);
  9.1642 +// 	  while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
  9.1643 +// 	    gw.goNext(e.o);
  9.1644 +// 	}
  9.1645 +// 	return e;
  9.1646 +//       }
  9.1647 +// /*
  9.1648 +//   InEdgeIt &goNext(InEdgeIt &e)
  9.1649 +//   {
  9.1650 +//   if(gw.valid(e.i)) {
  9.1651 +//   while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
  9.1652 +//   gw.goNext(e.i);
  9.1653 +//   if(gw.valid(e.i)) return e;
  9.1654 +//   else gw.first(e.o,e.n);
  9.1655 +//   }
  9.1656 +//   else {
  9.1657 +//   while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
  9.1658 +//   gw.goNext(e.o);
  9.1659 +//   return e;
  9.1660 +//   }
  9.1661 +//   }
  9.1662 +//   InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
  9.1663 +// */
  9.1664 +//     //bool valid(const InEdgeIt e) { return gw.valid(e.i)||gw.valid(e.o);}
  9.1665 +
  9.1666 +//     //template<typename I> I &goNext(I &i); { return gw.goNext(i); }
  9.1667 +//     //template<typename I> I next(const I i); { return gw.goNext(i); }
  9.1668 +
  9.1669 +//     template< typename It > It first() const { 
  9.1670 +//       It e; first(e); return e; }
  9.1671 +
  9.1672 +//     template< typename It > It first(Node v) const { 
  9.1673 +//       It e; first(e, v); return e; }
  9.1674 +
  9.1675 +//     Node head(const Edge& e) const { return gw.head(e); }
  9.1676 +//     Node tail(const Edge& e) const { return gw.tail(e); }
  9.1677 +  
  9.1678 +//     template<typename I> Node aNode(const I& e) const { 
  9.1679 +//       return gw.aNode(e); }
  9.1680 +//     template<typename I> Node bNode(const I& e) const { 
  9.1681 +//       return gw.bNode(e); }
  9.1682 +  
  9.1683 +//     //template<typename I> bool valid(const I i);
  9.1684 +//     //{ return gw.valid(i); }
  9.1685 +  
  9.1686 +//     //template<typename I> void setInvalid(const I &i);
  9.1687 +//     //{ return gw.setInvalid(i); }
  9.1688 +  
  9.1689 +//     Node addNode() { return gw.addNode(); }
  9.1690 +//     Edge addEdge(const Node& tail, const Node& head) { 
  9.1691 +//       return gw.addEdge(tail, head); }
  9.1692 +  
  9.1693 +//     template<typename I> void erase(const I& i) { gw.erase(i); }
  9.1694 +  
  9.1695 +//     void clear() { gw.clear(); }
  9.1696 +  
  9.1697 +//     template<typename S> class NodeMap : public Graph::NodeMap<S> { };
  9.1698 +//     template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
  9.1699 +  
  9.1700 +//     void setGraph(Graph& _graph) { graph = &_graph; }
  9.1701 +//     Graph& getGraph() { return (*graph); }
  9.1702 +
  9.1703 +//     //ResGraphWrapper() : graph(0) { }
  9.1704 +//     ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
  9.1705 +//   };
  9.1706 +
  9.1707 +} //namespace hugo
  9.1708 +
  9.1709 +#endif //HUGO_GRAPH_WRAPPER_H
  9.1710 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/work/marci/experiment/graph_wrapper_1.h	Sat Apr 03 17:26:46 2004 +0000
    10.3 @@ -0,0 +1,1832 @@
    10.4 +// -*- c++ -*-
    10.5 +#ifndef HUGO_GRAPH_WRAPPER_H
    10.6 +#define HUGO_GRAPH_WRAPPER_H
    10.7 +
    10.8 +#include <invalid.h>
    10.9 +
   10.10 +namespace hugo {
   10.11 +
   10.12 +  template<typename Graph>
   10.13 +  class TrivGraphWrapper {
   10.14 +  protected:
   10.15 +    Graph* graph;
   10.16 +  
   10.17 +  public:
   10.18 +    typedef Graph BaseGraph;
   10.19 +
   10.20 +    typedef typename Graph::Node Node;
   10.21 +    class NodeIt : public Graph::NodeIt { 
   10.22 +    public:
   10.23 +      NodeIt() { }
   10.24 +      NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { }
   10.25 +      NodeIt(const Invalid& i) : Graph::NodeIt(i) { }
   10.26 +      NodeIt(const TrivGraphWrapper<Graph>& _G) : 
   10.27 +	Graph::NodeIt(*(_G.graph)) { }
   10.28 +    };
   10.29 +    typedef typename Graph::Edge Edge;
   10.30 +    //typedef typename Graph::OutEdgeIt OutEdgeIt;
   10.31 +    class OutEdgeIt : public Graph::OutEdgeIt { 
   10.32 +    public:
   10.33 +      OutEdgeIt() { }
   10.34 +      OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { }
   10.35 +      OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { }
   10.36 +      OutEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) : 
   10.37 +	Graph::OutEdgeIt(*(_G.graph), n) { }
   10.38 +    };
   10.39 +    //typedef typename Graph::InEdgeIt InEdgeIt;
   10.40 +    class InEdgeIt : public Graph::InEdgeIt { 
   10.41 +    public:
   10.42 +      InEdgeIt() { }
   10.43 +      InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { }
   10.44 +      InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { }
   10.45 +      InEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) : 
   10.46 +	Graph::InEdgeIt(*(_G.graph), n) { }
   10.47 +    };
   10.48 +    //typedef typename Graph::SymEdgeIt SymEdgeIt;
   10.49 +    //typedef typename Graph::EdgeIt EdgeIt;
   10.50 +    class EdgeIt : public Graph::EdgeIt { 
   10.51 +    public:
   10.52 +      EdgeIt() { }
   10.53 +      EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { }
   10.54 +      EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { }
   10.55 +      EdgeIt(const TrivGraphWrapper<Graph>& _G) : 
   10.56 +	Graph::EdgeIt(*(_G.graph)) { }
   10.57 +    };
   10.58 +
   10.59 +    //TrivGraphWrapper() : graph(0) { }
   10.60 +    TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
   10.61 +
   10.62 +//    void setGraph(Graph& _graph) { graph = &_graph; }
   10.63 +//    Graph& getGraph() const { return (*graph); }
   10.64 +
   10.65 +    NodeIt& first(NodeIt& i) const { 
   10.66 +      i=NodeIt(*this);
   10.67 +      return i;
   10.68 +    }
   10.69 +    EdgeIt& first(EdgeIt& i) const { 
   10.70 +      i=EdgeIt(*this);
   10.71 +      return i;
   10.72 +    }
   10.73 +//     template<typename I> I& first(I& i) const { 
   10.74 +//       //return graph->first(i); 
   10.75 +//       i=I(*this);
   10.76 +//       return i;
   10.77 +//     }
   10.78 +    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
   10.79 +      i=OutEdgeIt(*this, p);
   10.80 +      return i;
   10.81 +    }
   10.82 +    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
   10.83 +      i=InEdgeIt(*this, p);
   10.84 +      return i;
   10.85 +    }
   10.86 +//     template<typename I, typename P> I& first(I& i, const P& p) const { 
   10.87 +//       //return graph->first(i, p);
   10.88 +//       i=I(*this, p);
   10.89 +//       return i;
   10.90 +//     }
   10.91 +    
   10.92 +//    template<typename I> I getNext(const I& i) const { 
   10.93 +//      return graph->getNext(i); }
   10.94 +    template<typename I> I& next(I &i) const { graph->next(i); return i; }    
   10.95 +
   10.96 +    template< typename It > It first() const { 
   10.97 +      It e; first(e); return e; }
   10.98 +
   10.99 +    template< typename It > It first(const Node& v) const { 
  10.100 +      It e; first(e, v); return e; }
  10.101 +
  10.102 +    Node head(const Edge& e) const { return graph->head(e); }
  10.103 +    Node tail(const Edge& e) const { return graph->tail(e); }
  10.104 +
  10.105 +    template<typename I> bool valid(const I& i) const 
  10.106 +      { return graph->valid(i); }
  10.107 +  
  10.108 +    //template<typename I> void setInvalid(const I &i);
  10.109 +    //{ return graph->setInvalid(i); }
  10.110 +
  10.111 +    int nodeNum() const { return graph->nodeNum(); }
  10.112 +    int edgeNum() const { return graph->edgeNum(); }
  10.113 +  
  10.114 +    template<typename I> Node aNode(const I& e) const { 
  10.115 +      return graph->aNode(e); }
  10.116 +    template<typename I> Node bNode(const I& e) const { 
  10.117 +      return graph->bNode(e); }
  10.118 +  
  10.119 +    Node addNode() const { return graph->addNode(); }
  10.120 +    Edge addEdge(const Node& tail, const Node& head) const { 
  10.121 +      return graph->addEdge(tail, head); }
  10.122 +  
  10.123 +    template<typename I> void erase(const I& i) const { graph->erase(i); }
  10.124 +  
  10.125 +    void clear() const { graph->clear(); }
  10.126 +    
  10.127 +    template<typename T> class NodeMap : public Graph::NodeMap<T> { 
  10.128 +    public:
  10.129 +      NodeMap(const TrivGraphWrapper<Graph>& _G) :  
  10.130 +	Graph::NodeMap<T>(*(_G.graph)) { }
  10.131 +      NodeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
  10.132 +	Graph::NodeMap<T>(*(_G.graph), a) { }
  10.133 +    };
  10.134 +
  10.135 +    template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
  10.136 +    public:
  10.137 +      EdgeMap(const TrivGraphWrapper<Graph>& _G) :  
  10.138 +	Graph::EdgeMap<T>(*(_G.graph)) { }
  10.139 +      EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
  10.140 +	Graph::EdgeMap<T>(*(_G.graph), a) { }
  10.141 +    };
  10.142 +
  10.143 +    template<typename Map, typename T> class NodeMapWrapper {
  10.144 +    protected:
  10.145 +      Map* map;
  10.146 +    public:
  10.147 +      NodeMapWrapper(Map& _map) : map(&_map) { }
  10.148 +      //template<typename T> 
  10.149 +      void set(Node n, T a) { map->set(n, a); }
  10.150 +      //template<typename T>
  10.151 +      T get(Node n) const { return map->get(n); }
  10.152 +    };
  10.153 +
  10.154 +    template<typename Map, typename T> class EdgeMapWrapper {
  10.155 +    protected:
  10.156 +      Map* map;
  10.157 +    public:
  10.158 +      EdgeMapWrapper(Map& _map) : map(&_map) { }
  10.159 +      //template<typename T> 
  10.160 +      void set(Edge n, T a) { map->set(n, a); }
  10.161 +      //template<typename T>
  10.162 +      T get(Edge n) const { return map->get(n); }
  10.163 +    };
  10.164 +  };
  10.165 +
  10.166 +  template<typename GraphWrapper>
  10.167 +  class GraphWrapperSkeleton {
  10.168 +  protected:
  10.169 +    GraphWrapper gw;
  10.170 +  
  10.171 +  public:
  10.172 +    //typedef typename GraphWrapper::BaseGraph BaseGraph;
  10.173 +
  10.174 +//     typedef typename GraphWrapper::Node Node;
  10.175 +//     typedef typename GraphWrapper::NodeIt NodeIt;
  10.176 +
  10.177 +//     typedef typename GraphWrapper::Edge Edge;
  10.178 +//     typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
  10.179 +//     typedef typename GraphWrapper::InEdgeIt InEdgeIt;
  10.180 +//     //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
  10.181 +//     typedef typename GraphWrapper::EdgeIt EdgeIt;
  10.182 +
  10.183 +    typedef typename GraphWrapper::Node Node;
  10.184 +    class NodeIt : public GraphWrapper::NodeIt { 
  10.185 +    public:
  10.186 +      NodeIt() { }
  10.187 +      NodeIt(const typename GraphWrapper::NodeIt& n) : 
  10.188 +	GraphWrapper::NodeIt(n) { }
  10.189 +      NodeIt(const Invalid& i) : GraphWrapper::NodeIt(i) { }
  10.190 +      NodeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
  10.191 +	GraphWrapper::NodeIt(_G.gw) { }
  10.192 +    };
  10.193 +    typedef typename GraphWrapper::Edge Edge;
  10.194 +    //typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
  10.195 +    class OutEdgeIt : public GraphWrapper::OutEdgeIt { 
  10.196 +    public:
  10.197 +      OutEdgeIt() { }
  10.198 +      OutEdgeIt(const typename GraphWrapper::OutEdgeIt& e) : 
  10.199 +	GraphWrapper::OutEdgeIt(e) { }
  10.200 +      OutEdgeIt(const Invalid& i) : GraphWrapper::OutEdgeIt(i) { }
  10.201 +      OutEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 
  10.202 +	GraphWrapper::OutEdgeIt(_G.gw, n) { }
  10.203 +    };
  10.204 +    //typedef typename GraphWrapper::InEdgeIt InEdgeIt;
  10.205 +    class InEdgeIt : public GraphWrapper::InEdgeIt { 
  10.206 +    public:
  10.207 +      InEdgeIt() { }
  10.208 +      InEdgeIt(const typename GraphWrapper::InEdgeIt& e) : 
  10.209 +	GraphWrapper::InEdgeIt(e) { }
  10.210 +      InEdgeIt(const Invalid& i) : GraphWrapper::InEdgeIt(i) { }
  10.211 +      InEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 
  10.212 +	GraphWrapper::InEdgeIt(_G.gw, n) { }
  10.213 +    };
  10.214 +    //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
  10.215 +    //typedef typename GraphWrapper::EdgeIt EdgeIt;
  10.216 +    class EdgeIt : public GraphWrapper::EdgeIt { 
  10.217 +    public:
  10.218 +      EdgeIt() { }
  10.219 +      EdgeIt(const typename GraphWrapper::EdgeIt& e) : 
  10.220 +	GraphWrapper::EdgeIt(e) { }
  10.221 +      EdgeIt(const Invalid& i) : GraphWrapper::EdgeIt(i) { }
  10.222 +      EdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
  10.223 +	GraphWrapper::EdgeIt(_G.gw) { }
  10.224 +    };
  10.225 +
  10.226 +
  10.227 +    //GraphWrapperSkeleton() : gw() { }
  10.228 +    GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { }
  10.229 +
  10.230 +    //void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
  10.231 +    //BaseGraph& getGraph() const { return gw.getGraph(); }
  10.232 +    
  10.233 +    template<typename I> I& first(I& i) const {       
  10.234 +      i=I(*this);
  10.235 +      return i;
  10.236 +    }
  10.237 +    template<typename I, typename P> I& first(I& i, const P& p) const { 
  10.238 +      i=I(*this, p);
  10.239 +      return i; 
  10.240 +    }
  10.241 +    
  10.242 +//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
  10.243 +    template<typename I> I& next(I &i) const { gw.next(i); return i; }    
  10.244 +
  10.245 +    template< typename It > It first() const { 
  10.246 +      It e; this->first(e); return e; }
  10.247 +
  10.248 +    template< typename It > It first(const Node& v) const { 
  10.249 +      It e; this->first(e, v); return e; }
  10.250 +
  10.251 +    Node head(const Edge& e) const { return gw.head(e); }
  10.252 +    Node tail(const Edge& e) const { return gw.tail(e); }
  10.253 +
  10.254 +    template<typename I> bool valid(const I& i) const { return gw.valid(i); }
  10.255 +  
  10.256 +    //template<typename I> void setInvalid(const I &i);
  10.257 +    //{ return graph->setInvalid(i); }
  10.258 +
  10.259 +    int nodeNum() const { return gw.nodeNum(); }
  10.260 +    int edgeNum() const { return gw.edgeNum(); }
  10.261 +  
  10.262 +    template<typename I> Node aNode(const I& e) const { return gw.aNode(e); }
  10.263 +    template<typename I> Node bNode(const I& e) const { return gw.bNode(e); }
  10.264 +  
  10.265 +    Node addNode() const { return gw.addNode(); }
  10.266 +    Edge addEdge(const Node& tail, const Node& head) const { 
  10.267 +      return gw.addEdge(tail, head); }
  10.268 +  
  10.269 +    template<typename I> void erase(const I& i) const { gw.erase(i); }
  10.270 +  
  10.271 +    void clear() const { gw.clear(); }
  10.272 +    
  10.273 +    template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
  10.274 +    public:
  10.275 +      NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :  
  10.276 +	GraphWrapper::NodeMap<T>(_G.gw) { }
  10.277 +      NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) : 
  10.278 +	GraphWrapper::NodeMap<T>(_G.gw, a) { }
  10.279 +    };
  10.280 +
  10.281 +    template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> { 
  10.282 +    public:
  10.283 +      EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) :  
  10.284 +	GraphWrapper::EdgeMap<T>(_G.gw) { }
  10.285 +      EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) : 
  10.286 +	GraphWrapper::EdgeMap<T>(_G.gw, a) { }
  10.287 +    };
  10.288 +  };
  10.289 +
  10.290 +  template<typename GraphWrapper>
  10.291 +  class GraphWrapperSkeleton1 {
  10.292 +  protected:
  10.293 +    GraphWrapper* g;
  10.294 +  
  10.295 +  public:
  10.296 +    //typedef typename GraphWrapper::BaseGraph BaseGraph;
  10.297 +
  10.298 +//     typedef typename GraphWrapper::Node Node;
  10.299 +//     typedef typename GraphWrapper::NodeIt NodeIt;
  10.300 +
  10.301 +//     typedef typename GraphWrapper::Edge Edge;
  10.302 +//     typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
  10.303 +//     typedef typename GraphWrapper::InEdgeIt InEdgeIt;
  10.304 +//     //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
  10.305 +//     typedef typename GraphWrapper::EdgeIt EdgeIt;
  10.306 +
  10.307 +    typedef typename GraphWrapper::Node Node;
  10.308 +    class NodeIt : public GraphWrapper::NodeIt { 
  10.309 +    public:
  10.310 +      NodeIt() { }
  10.311 +      NodeIt(const typename GraphWrapper::NodeIt& n) : 
  10.312 +	GraphWrapper::NodeIt(n) { }
  10.313 +      NodeIt(const Invalid& i) : GraphWrapper::NodeIt(i) { }
  10.314 +      NodeIt(const GraphWrapperSkeleton1<GraphWrapper>& _G) : 
  10.315 +	GraphWrapper::NodeIt(*(_G.g)) { }
  10.316 +    };
  10.317 +    typedef typename GraphWrapper::Edge Edge;
  10.318 +    //typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
  10.319 +    class OutEdgeIt : public GraphWrapper::OutEdgeIt { 
  10.320 +    public:
  10.321 +      OutEdgeIt() { }
  10.322 +      OutEdgeIt(const typename GraphWrapper::OutEdgeIt& e) : 
  10.323 +	GraphWrapper::OutEdgeIt(e) { }
  10.324 +      OutEdgeIt(const Invalid& i) : GraphWrapper::OutEdgeIt(i) { }
  10.325 +      OutEdgeIt(const GraphWrapperSkeleton1<GraphWrapper>& _G, const Node& n) : 
  10.326 +	GraphWrapper::OutEdgeIt(*(_G.g), n) { }
  10.327 +    };
  10.328 +    //typedef typename GraphWrapper::InEdgeIt InEdgeIt;
  10.329 +    class InEdgeIt : public GraphWrapper::InEdgeIt { 
  10.330 +    public:
  10.331 +      InEdgeIt() { }
  10.332 +      InEdgeIt(const typename GraphWrapper::InEdgeIt& e) : 
  10.333 +	GraphWrapper::InEdgeIt(e) { }
  10.334 +      InEdgeIt(const Invalid& i) : GraphWrapper::InEdgeIt(i) { }
  10.335 +      InEdgeIt(const GraphWrapperSkeleton1<GraphWrapper>& _G, const Node& n) : 
  10.336 +	GraphWrapper::InEdgeIt(*(_G.g), n) { }
  10.337 +    };
  10.338 +    //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
  10.339 +    //typedef typename GraphWrapper::EdgeIt EdgeIt;
  10.340 +    class EdgeIt : public GraphWrapper::EdgeIt { 
  10.341 +    public:
  10.342 +      EdgeIt() { }
  10.343 +      EdgeIt(const typename GraphWrapper::EdgeIt& e) : 
  10.344 +	GraphWrapper::EdgeIt(e) { }
  10.345 +      EdgeIt(const Invalid& i) : GraphWrapper::EdgeIt(i) { }
  10.346 +      EdgeIt(const GraphWrapperSkeleton1<GraphWrapper>& _G) : 
  10.347 +	GraphWrapper::EdgeIt(*(_G.g)) { }
  10.348 +    };
  10.349 +
  10.350 +
  10.351 +    //GraphWrapperSkeleton() : gw() { }
  10.352 +    GraphWrapperSkeleton1(GraphWrapper& _gw) : g(&_gw) { }
  10.353 +
  10.354 +    //void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); }
  10.355 +    //BaseGraph& getGraph() const { return gw.getGraph(); }
  10.356 +    
  10.357 +    template<typename I> I& first(I& i) const {       
  10.358 +      i=I(*this);
  10.359 +      return i;
  10.360 +    }
  10.361 +    template<typename I, typename P> I& first(I& i, const P& p) const { 
  10.362 +      i=I(*this, p);
  10.363 +      return i; 
  10.364 +    }
  10.365 +    
  10.366 +//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
  10.367 +    template<typename I> I& next(I &i) const { g->next(i); return i; }    
  10.368 +
  10.369 +    template< typename It > It first() const { 
  10.370 +      It e; this->first(e); return e; }
  10.371 +
  10.372 +    template< typename It > It first(const Node& v) const { 
  10.373 +      It e; this->first(e, v); return e; }
  10.374 +
  10.375 +    Node head(const Edge& e) const { return g->head(e); }
  10.376 +    Node tail(const Edge& e) const { return g->tail(e); }
  10.377 +
  10.378 +    template<typename I> bool valid(const I& i) const { return g->valid(i); }
  10.379 +  
  10.380 +    //template<typename I> void setInvalid(const I &i);
  10.381 +    //{ return graph->setInvalid(i); }
  10.382 +
  10.383 +    int nodeNum() const { return g->nodeNum(); }
  10.384 +    int edgeNum() const { return g->edgeNum(); }
  10.385 +  
  10.386 +    template<typename I> Node aNode(const I& e) const { return g->aNode(e); }
  10.387 +    template<typename I> Node bNode(const I& e) const { return g->bNode(e); }
  10.388 +  
  10.389 +    Node addNode() const { return g->addNode(); }
  10.390 +    Edge addEdge(const Node& tail, const Node& head) const { 
  10.391 +      return g->addEdge(tail, head); }
  10.392 +  
  10.393 +    template<typename I> void erase(const I& i) const { g->erase(i); }
  10.394 +  
  10.395 +    void clear() const { g->clear(); }
  10.396 +    
  10.397 +    template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
  10.398 +    public:
  10.399 +      NodeMap(const GraphWrapperSkeleton1<GraphWrapper>& _G) :  
  10.400 +	GraphWrapper::NodeMap<T>(*(_G.g)) { }
  10.401 +      NodeMap(const GraphWrapperSkeleton1<GraphWrapper>& _G, T a) : 
  10.402 +	GraphWrapper::NodeMap<T>(*(_G.g), a) { }
  10.403 +    };
  10.404 +
  10.405 +    template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> { 
  10.406 +    public:
  10.407 +      EdgeMap(const GraphWrapperSkeleton1<GraphWrapper>& _G) :  
  10.408 +	GraphWrapper::EdgeMap<T>(*(_G.g)) { }
  10.409 +      EdgeMap(const GraphWrapperSkeleton1<GraphWrapper>& _G, T a) : 
  10.410 +	GraphWrapper::EdgeMap<T>(*(_G.g), a) { }
  10.411 +    };
  10.412 +  };
  10.413 +
  10.414 +
  10.415 +//   template<typename Graph>
  10.416 +//   class RevGraphWrapper
  10.417 +//   {
  10.418 +//   protected:
  10.419 +//     Graph* graph;
  10.420 +  
  10.421 +//   public:
  10.422 +//     typedef Graph BaseGraph;
  10.423 +
  10.424 +//     typedef typename Graph::Node Node;    
  10.425 +//     typedef typename Graph::NodeIt NodeIt;
  10.426 +  
  10.427 +//     typedef typename Graph::Edge Edge;
  10.428 +//     typedef typename Graph::OutEdgeIt InEdgeIt;
  10.429 +//     typedef typename Graph::InEdgeIt OutEdgeIt;
  10.430 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
  10.431 +//     typedef typename Graph::EdgeIt EdgeIt;
  10.432 +
  10.433 +//     //RevGraphWrapper() : graph(0) { }
  10.434 +//     RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
  10.435 +
  10.436 +//     void setGraph(Graph& _graph) { graph = &_graph; }
  10.437 +//     Graph& getGraph() const { return (*graph); }
  10.438 +    
  10.439 +//     template<typename I> I& first(I& i) const { return graph->first(i); }
  10.440 +//     template<typename I, typename P> I& first(I& i, const P& p) const { 
  10.441 +//       return graph->first(i, p); }
  10.442 +
  10.443 +//     template<typename I> I getNext(const I& i) const { 
  10.444 +//       return graph->getNext(i); }
  10.445 +//     template<typename I> I& next(I &i) const { return graph->next(i); }    
  10.446 +
  10.447 +//     template< typename It > It first() const { 
  10.448 +//       It e; first(e); return e; }
  10.449 +
  10.450 +//     template< typename It > It first(const Node& v) const { 
  10.451 +//       It e; first(e, v); return e; }
  10.452 +
  10.453 +//     Node head(const Edge& e) const { return graph->tail(e); }
  10.454 +//     Node tail(const Edge& e) const { return graph->head(e); }
  10.455 +  
  10.456 +//     template<typename I> bool valid(const I& i) const 
  10.457 +//       { return graph->valid(i); }
  10.458 +  
  10.459 +//     //template<typename I> void setInvalid(const I &i);
  10.460 +//     //{ return graph->setInvalid(i); }
  10.461 +  
  10.462 +//     template<typename I> Node aNode(const I& e) const { 
  10.463 +//       return graph->aNode(e); }
  10.464 +//     template<typename I> Node bNode(const I& e) const { 
  10.465 +//       return graph->bNode(e); }
  10.466 +
  10.467 +//     Node addNode() const { return graph->addNode(); }
  10.468 +//     Edge addEdge(const Node& tail, const Node& head) const { 
  10.469 +//       return graph->addEdge(tail, head); }
  10.470 +  
  10.471 +//     int nodeNum() const { return graph->nodeNum(); }
  10.472 +//     int edgeNum() const { return graph->edgeNum(); }
  10.473 +  
  10.474 +//     template<typename I> void erase(const I& i) const { graph->erase(i); }
  10.475 +  
  10.476 +//     void clear() const { graph->clear(); }
  10.477 +
  10.478 +//     template<typename T> class NodeMap : public Graph::NodeMap<T> { 
  10.479 +//     public:
  10.480 +//       NodeMap(const RevGraphWrapper<Graph>& _G) : 
  10.481 +// 	Graph::NodeMap<T>(_G.getGraph()) { }
  10.482 +//       NodeMap(const RevGraphWrapper<Graph>& _G, T a) : 
  10.483 +// 	Graph::NodeMap<T>(_G.getGraph(), a) { }
  10.484 +//     };
  10.485 +
  10.486 +//     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 
  10.487 +//     public:
  10.488 +//       EdgeMap(const RevGraphWrapper<Graph>& _G) : 
  10.489 +// 	Graph::EdgeMap<T>(_G.getGraph()) { }
  10.490 +//       EdgeMap(const RevGraphWrapper<Graph>& _G, T a) : 
  10.491 +// 	Graph::EdgeMap<T>(_G.getGraph(), a) { }
  10.492 +//     };
  10.493 +//   };
  10.494 +
  10.495 +//   template<typename /*Graph*/GraphWrapper
  10.496 +//   /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ >
  10.497 +//   class RevGraphWrapper : 
  10.498 +//     public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ {
  10.499 +//   protected:
  10.500 +//     //Graph* graph;
  10.501 +    
  10.502 +//   public:
  10.503 +//     //typedef Graph BaseGraph;
  10.504 +
  10.505 +//     //typedef typename Graph::Node Node;    
  10.506 +//     //typedef typename Graph::NodeIt NodeIt;
  10.507 +  
  10.508 +//     //typedef typename Graph::Edge Edge;
  10.509 +//     typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::OutEdgeIt InEdgeIt;
  10.510 +//     typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::InEdgeIt OutEdgeIt;
  10.511 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
  10.512 +//     //typedef typename Graph::EdgeIt EdgeIt;
  10.513 +
  10.514 +//     //RevGraphWrapper() : graph(0) { }
  10.515 +//     RevGraphWrapper(GraphWrapper _gw/*BaseGraph& _graph*/) : GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/(_gw/*TrivGraphWrapper<Graph>(_graph)*/) { }
  10.516 +    
  10.517 +//     //void setGraph(Graph& _graph) { graph = &_graph; }
  10.518 +//     //Graph& getGraph() const { return (*graph); }
  10.519 +    
  10.520 +//     //template<typename I> I& first(I& i) const { return graph->first(i); }
  10.521 +//     //template<typename I, typename P> I& first(I& i, const P& p) const { 
  10.522 +//     //  return graph->first(i, p); }
  10.523 +
  10.524 +//     //template<typename I> I getNext(const I& i) const { 
  10.525 +//     //  return graph->getNext(i); }
  10.526 +//     //template<typename I> I& next(I &i) const { return graph->next(i); }    
  10.527 +
  10.528 +//     //template< typename It > It first() const { 
  10.529 +//     //  It e; first(e); return e; }
  10.530 +
  10.531 +//     //template< typename It > It first(const Node& v) const { 
  10.532 +//     //  It e; first(e, v); return e; }
  10.533 +
  10.534 +//     //Node head(const Edge& e) const { return graph->tail(e); }
  10.535 +//     //Node tail(const Edge& e) const { return graph->head(e); }
  10.536 +  
  10.537 +//     //template<typename I> bool valid(const I& i) const 
  10.538 +//     //  { return graph->valid(i); }
  10.539 +  
  10.540 +//     //template<typename I> void setInvalid(const I &i);
  10.541 +//     //{ return graph->setInvalid(i); }
  10.542 +  
  10.543 +//     //template<typename I> Node aNode(const I& e) const { 
  10.544 +//     //  return graph->aNode(e); }
  10.545 +//     //template<typename I> Node bNode(const I& e) const { 
  10.546 +//     //  return graph->bNode(e); }
  10.547 +
  10.548 +//     //Node addNode() const { return graph->addNode(); }
  10.549 +//     //Edge addEdge(const Node& tail, const Node& head) const { 
  10.550 +//     //  return graph->addEdge(tail, head); }
  10.551 +  
  10.552 +//     //int nodeNum() const { return graph->nodeNum(); }
  10.553 +//     //int edgeNum() const { return graph->edgeNum(); }
  10.554 +  
  10.555 +//     //template<typename I> void erase(const I& i) const { graph->erase(i); }
  10.556 +  
  10.557 +//     //void clear() const { graph->clear(); }
  10.558 +
  10.559 +//     template<typename T> class NodeMap : 
  10.560 +//       public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T> 
  10.561 +//     { 
  10.562 +//     public:
  10.563 +//       NodeMap(const RevGraphWrapper<GraphWrapper>& _gw) : 
  10.564 +// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw) { }
  10.565 +//       NodeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : 
  10.566 +// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw, a) { }
  10.567 +//     };
  10.568 +    
  10.569 +//     template<typename T> class EdgeMap : 
  10.570 +//       public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T> { 
  10.571 +//     public:
  10.572 +//       EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw) : 
  10.573 +// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw) { }
  10.574 +//       EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : 
  10.575 +// 	GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw, a) { }
  10.576 +//     };
  10.577 +//   };
  10.578 +
  10.579 +  template<typename GraphWrapper>
  10.580 +  class RevGraphWrapper : public GraphWrapperSkeleton1<GraphWrapper> {
  10.581 +  public:
  10.582 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::Node Node;
  10.583 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::Edge Edge;
  10.584 +    //FIXME 
  10.585 +    //If GraphWrapper::OutEdgeIt is not defined
  10.586 +    //and we do not want to use RevGraphWrapper::InEdgeIt,
  10.587 +    //this won't work, because of typedef
  10.588 +    //OR
  10.589 +    //graphs have to define their non-existing iterators to void
  10.590 +    //Unfortunately all the typedefs are instantiated in templates, 
  10.591 +    //unlike other stuff
  10.592 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::OutEdgeIt InEdgeIt;
  10.593 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::InEdgeIt OutEdgeIt;
  10.594 +
  10.595 +    RevGraphWrapper(GraphWrapper& _gw) : 
  10.596 +      GraphWrapperSkeleton1<GraphWrapper>(_gw) { }  
  10.597 +
  10.598 +    Node head(const Edge& e) const 
  10.599 +      { return GraphWrapperSkeleton1<GraphWrapper>::tail(e); }
  10.600 +    Node tail(const Edge& e) const 
  10.601 +      { return GraphWrapperSkeleton1<GraphWrapper>::head(e); }
  10.602 +  };
  10.603 +
  10.604 +  //Subgraph on the same node-set and partial edge-set
  10.605 +  template<typename GraphWrapper, typename EdgeFilterMap>
  10.606 +  class SubGraphWrapper : public GraphWrapperSkeleton1<GraphWrapper> {
  10.607 +  protected:
  10.608 +    EdgeFilterMap* filter_map;
  10.609 +  public:
  10.610 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::Node Node;
  10.611 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::NodeIt NodeIt;
  10.612 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::Edge Edge;
  10.613 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::EdgeIt EdgeIt;
  10.614 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::InEdgeIt InEdgeIt;
  10.615 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::OutEdgeIt OutEdgeIt;
  10.616 +
  10.617 +    SubGraphWrapper(GraphWrapper& _gw, EdgeFilterMap& _filter_map) : 
  10.618 +      GraphWrapperSkeleton1<GraphWrapper>(_gw), filter_map(&_filter_map) { }  
  10.619 +
  10.620 +    template<typename I> I& first(I& i) const { 
  10.621 +      g->first(i); 
  10.622 +      while (g->valid(i) && !filter_map->get(i)) { g->next(i); }
  10.623 +      return i;
  10.624 +    }
  10.625 +    template<typename I, typename P> I& first(I& i, const P& p) const { 
  10.626 +      g->first(i, p); 
  10.627 +      while (g->valid(i) && !filter_map->get(i)) { g->next(i); }
  10.628 +      return i;
  10.629 +    }
  10.630 +    
  10.631 +    //template<typename I> I getNext(const I& i) const { 
  10.632 +    //  return gw.getNext(i); 
  10.633 +    //}
  10.634 +    template<typename I> I& next(I &i) const { 
  10.635 +      g->next(i); 
  10.636 +      while (g->valid(i) && !filter_map->get(i)) { g->next(i); }
  10.637 +      return i;
  10.638 +    }
  10.639 +    
  10.640 +    template< typename It > It first() const { 
  10.641 +      It e; this->first(e); return e; }
  10.642 +    
  10.643 +    template< typename It > It first(const Node& v) const { 
  10.644 +      It e; this->first(e, v); return e; }
  10.645 +  };
  10.646 +
  10.647 +//   template<typename GraphWrapper>
  10.648 +//   class UndirGraphWrapper {
  10.649 +//   protected:
  10.650 +//     //Graph* graph;
  10.651 +//     GraphWrapper gw;
  10.652 +
  10.653 +//   public:
  10.654 +//     typedef GraphWrapper BaseGraph;
  10.655 +
  10.656 +//     typedef typename GraphWrapper::Node Node;
  10.657 +//     typedef typename GraphWrapper::NodeIt NodeIt;
  10.658 +
  10.659 +//     //typedef typename Graph::Edge Edge;
  10.660 +//     //typedef typename Graph::OutEdgeIt OutEdgeIt;
  10.661 +//     //typedef typename Graph::InEdgeIt InEdgeIt;
  10.662 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
  10.663 +//     //typedef typename Graph::EdgeIt EdgeIt;
  10.664 +
  10.665 +//     //private:
  10.666 +//     typedef typename GraphWrapper::Edge GraphEdge;
  10.667 +//     typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt;
  10.668 +//     typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt;
  10.669 +//     //public:
  10.670 +
  10.671 +//     //UndirGraphWrapper() : graph(0) { }
  10.672 +//     UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
  10.673 +
  10.674 +//     //void setGraph(Graph& _graph) { graph = &_graph; }
  10.675 +//     //Graph& getGraph() const { return (*graph); }
  10.676 +  
  10.677 +//     class Edge {
  10.678 +//       friend class UndirGraphWrapper<GraphWrapper>;
  10.679 +//       bool out_or_in; //true iff out
  10.680 +//       GraphOutEdgeIt out;
  10.681 +//       GraphInEdgeIt in;
  10.682 +//     public:
  10.683 +//       Edge() : out_or_in(), out(), in() { }
  10.684 +//       Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
  10.685 +//       operator GraphEdge() const {
  10.686 +// 	if (out_or_in) return(out); else return(in);
  10.687 +//       }
  10.688 +//       friend bool operator==(const Edge& u, const Edge& v) { 
  10.689 +// 	if (v.out_or_in) 
  10.690 +// 	  return (u.out_or_in && u.out==v.out);
  10.691 +// 	else
  10.692 +// 	  return (!u.out_or_in && u.in==v.in);
  10.693 +//       } 
  10.694 +//       friend bool operator!=(const Edge& u, const Edge& v) { 
  10.695 +// 	if (v.out_or_in) 
  10.696 +// 	  return (!u.out_or_in || u.out!=v.out);
  10.697 +// 	else
  10.698 +// 	  return (u.out_or_in || u.in!=v.in);
  10.699 +//       } 
  10.700 +//     };
  10.701 +
  10.702 +//     class OutEdgeIt : public Edge {
  10.703 +//       friend class UndirGraphWrapper<GraphWrapper>;
  10.704 +//     public:
  10.705 +//       OutEdgeIt() : Edge() { }
  10.706 +//       OutEdgeIt(const Invalid& i) : Edge(i) { }
  10.707 +//       OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) 
  10.708 +// 	: Edge() { 
  10.709 +// 	out_or_in=true;
  10.710 +// 	_G.gw.first(out, n);
  10.711 +// 	if (!(_G.gw.valid(out))) {
  10.712 +// 	  out_or_in=false;
  10.713 +// 	  _G.gw.first(in, n);
  10.714 +// 	}
  10.715 +//       }
  10.716 +//     };
  10.717 +
  10.718 +//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
  10.719 +//       e.out_or_in=true;
  10.720 +//       gw.first(e.out, n);
  10.721 +//       if (!(gw.valid(e.out))) {
  10.722 +// 	e.out_or_in=false;
  10.723 +// 	gw.first(e.in, n);
  10.724 +//       }
  10.725 +//       return e;
  10.726 +//     }
  10.727 +
  10.728 +//     OutEdgeIt& next(OutEdgeIt& e) const {
  10.729 +//       if (e.out_or_in) {
  10.730 +// 	Node n=gw.tail(e.out);
  10.731 +// 	gw.next(e.out);
  10.732 +// 	if (!gw.valid(e.out)) {
  10.733 +// 	  e.out_or_in=false;
  10.734 +// 	  gw.first(e.in, n);
  10.735 +// 	}
  10.736 +//       } else {
  10.737 +// 	gw.next(e.in);
  10.738 +//       }
  10.739 +//       return e;
  10.740 +//     }
  10.741 +
  10.742 +//     Node aNode(const OutEdgeIt& e) const { 
  10.743 +//       if (e.out_or_in) return gw.tail(e); else return gw.head(e); }
  10.744 +//     Node bNode(const OutEdgeIt& e) const { 
  10.745 +//       if (e.out_or_in) return gw.head(e); else return gw.tail(e); }
  10.746 +
  10.747 +//     typedef OutEdgeIt InEdgeIt; 
  10.748 +
  10.749 +//     template<typename I> I& first(I& i) const { return gw.first(i); }
  10.750 +// //     template<typename I, typename P> I& first(I& i, const P& p) const { 
  10.751 +// //       return graph->first(i, p); }
  10.752 +    
  10.753 +//     template<typename I> I getNext(const I& i) const { 
  10.754 +//       return gw.getNext(i); }
  10.755 +//     template<typename I> I& next(I &i) const { return gw.next(i); }    
  10.756 +
  10.757 +//     template< typename It > It first() const { 
  10.758 +//       It e; first(e); return e; }
  10.759 +
  10.760 +//     template< typename It > It first(const Node& v) const { 
  10.761 +//       It e; first(e, v); return e; }
  10.762 +
  10.763 +//     Node head(const Edge& e) const { return gw.head(e); }
  10.764 +//     Node tail(const Edge& e) const { return gw.tail(e); }
  10.765 +
  10.766 +//     template<typename I> bool valid(const I& i) const 
  10.767 +//       { return gw.valid(i); }
  10.768 +  
  10.769 +//     //template<typename I> void setInvalid(const I &i);
  10.770 +//     //{ return graph->setInvalid(i); }
  10.771 +
  10.772 +//     int nodeNum() const { return gw.nodeNum(); }
  10.773 +//     int edgeNum() const { return gw.edgeNum(); }
  10.774 +  
  10.775 +// //     template<typename I> Node aNode(const I& e) const { 
  10.776 +// //       return graph->aNode(e); }
  10.777 +// //     template<typename I> Node bNode(const I& e) const { 
  10.778 +// //       return graph->bNode(e); }
  10.779 +  
  10.780 +//     Node addNode() const { return gw.addNode(); }
  10.781 +// // FIXME: ez igy nem jo, mert nem
  10.782 +// //    Edge addEdge(const Node& tail, const Node& head) const { 
  10.783 +// //      return graph->addEdge(tail, head); }
  10.784 +  
  10.785 +//     template<typename I> void erase(const I& i) const { gw.erase(i); }
  10.786 +  
  10.787 +//     void clear() const { gw.clear(); }
  10.788 +    
  10.789 +//     template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
  10.790 +//     public:
  10.791 +//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
  10.792 +// 	GraphWrapper::NodeMap<T>(_G.gw) { }
  10.793 +//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
  10.794 +// 	GraphWrapper::NodeMap<T>(_G.gw, a) { }
  10.795 +//     };
  10.796 +
  10.797 +//     template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> { 
  10.798 +//     public:
  10.799 +//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
  10.800 +// 	GraphWrapper::EdgeMap<T>(_G.gw) { }
  10.801 +//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
  10.802 +// 	GraphWrapper::EdgeMap<T>(_G.gw, a) { }
  10.803 +//     };
  10.804 +//   };
  10.805 +
  10.806 +
  10.807 +  template<typename GraphWrapper>
  10.808 +  class UndirGraphWrapper : public GraphWrapperSkeleton1<GraphWrapper> {
  10.809 +  protected:
  10.810 +//    GraphWrapper gw;
  10.811 +
  10.812 +  public:
  10.813 +    //typedef GraphWrapper BaseGraph;
  10.814 +
  10.815 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::Node Node;
  10.816 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::NodeIt NodeIt;
  10.817 +
  10.818 +    //private:
  10.819 +    //FIXME ezeknek valojaban a GraphWrapper megfelelo dolgai kellene hogy 
  10.820 +    //legyenek, at kell irni
  10.821 +    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/
  10.822 +    GraphWrapper::Edge GraphEdge;
  10.823 +    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/ 
  10.824 +    GraphWrapper::OutEdgeIt GraphOutEdgeIt;
  10.825 +    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/ 
  10.826 +    GraphWrapper::InEdgeIt GraphInEdgeIt;
  10.827 +    //public:
  10.828 +
  10.829 +    //UndirGraphWrapper() : graph(0) { }
  10.830 +    UndirGraphWrapper(GraphWrapper& _gw) : 
  10.831 +      GraphWrapperSkeleton1<GraphWrapper>(_gw) { }  
  10.832 +
  10.833 +    //UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { }
  10.834 +
  10.835 +    //void setGraph(Graph& _graph) { graph = &_graph; }
  10.836 +    //Graph& getGraph() const { return (*graph); }
  10.837 +  
  10.838 +    class Edge {
  10.839 +      friend class UndirGraphWrapper<GraphWrapper>;
  10.840 +    protected:
  10.841 +      bool out_or_in; //true iff out
  10.842 +      GraphOutEdgeIt out;
  10.843 +      GraphInEdgeIt in;
  10.844 +    public:
  10.845 +      Edge() : out_or_in(), out(), in() { }
  10.846 +      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
  10.847 +      operator GraphEdge() const {
  10.848 +	if (out_or_in) return(out); else return(in);
  10.849 +      }
  10.850 +//FIXME
  10.851 +//2 edges are equal if they "refer" to the same physical edge 
  10.852 +//is it good?
  10.853 +      friend bool operator==(const Edge& u, const Edge& v) { 
  10.854 +	if (v.out_or_in) 
  10.855 +	  if (u.out_or_in) return (u.out==v.out); else return (u.out==v.in);
  10.856 +	//return (u.out_or_in && u.out==v.out);
  10.857 +	else
  10.858 +	  if (u.out_or_in) return (u.out==v.in); else return (u.in==v.in);
  10.859 +	//return (!u.out_or_in && u.in==v.in);
  10.860 +      } 
  10.861 +      friend bool operator!=(const Edge& u, const Edge& v) { 
  10.862 +	if (v.out_or_in) 
  10.863 +	  if (u.out_or_in) return (u.out!=v.out); else return (u.out!=v.in);
  10.864 +	//return (!u.out_or_in || u.out!=v.out);
  10.865 +	else
  10.866 +	  if (u.out_or_in) return (u.out!=v.in); else return (u.in!=v.in);
  10.867 +	//return (u.out_or_in || u.in!=v.in);
  10.868 +      } 
  10.869 +    };
  10.870 +
  10.871 +    class OutEdgeIt : public Edge {
  10.872 +      friend class UndirGraphWrapper<GraphWrapper>;
  10.873 +    public:
  10.874 +      OutEdgeIt() : Edge() { }
  10.875 +      OutEdgeIt(const Invalid& i) : Edge(i) { }
  10.876 +      OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) 
  10.877 +	: Edge() { 
  10.878 +	out_or_in=true; _G.g->first(out, n);
  10.879 +	if (!(_G.g->valid(out))) { out_or_in=false; _G.g->first(in, n);	}
  10.880 +      }
  10.881 +    };
  10.882 +
  10.883 +    typedef OutEdgeIt InEdgeIt; 
  10.884 +
  10.885 +    class EdgeIt : public Edge {
  10.886 +      friend class UndirGraphWrapper<GraphWrapper>;
  10.887 +    protected:
  10.888 +      NodeIt v;
  10.889 +    public:
  10.890 +      EdgeIt() : Edge() { }
  10.891 +      EdgeIt(const Invalid& i) : Edge(i) { }
  10.892 +      EdgeIt(const UndirGraphWrapper<GraphWrapper>& _G) 
  10.893 +	: Edge() { 
  10.894 +	out_or_in=true;
  10.895 +	//Node v;
  10.896 +	_G.first(v);
  10.897 +	if (_G.valid(v)) _G.g->first(out); else out=INVALID;
  10.898 +	while (_G.valid(v) && !_G.g->valid(out)) { 
  10.899 +	  _G.g->next(v); 
  10.900 +	  if (_G.valid(v)) _G.g->first(out); 
  10.901 +	}
  10.902 +      }
  10.903 +    };
  10.904 +
  10.905 +    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
  10.906 +      e.out_or_in=true; g->first(e.out, n);
  10.907 +      if (!(g->valid(e.out))) { e.out_or_in=false; g->first(e.in, n); }
  10.908 +      return e;
  10.909 +    }
  10.910 +
  10.911 +    EdgeIt& first(EdgeIt& e) const {
  10.912 +      e.out_or_in=true;
  10.913 +      //NodeIt v;
  10.914 +      first(e.v);
  10.915 +      if (valid(e.v)) g->first(e.out, e.v); else e.out=INVALID;
  10.916 +      while (valid(e.v) && !g->valid(e.out)) { 
  10.917 +	g->next(e.v); 
  10.918 +	if (valid(e.v)) g->first(e.out, e.v); 
  10.919 +      }
  10.920 +      return e;
  10.921 +    }
  10.922 +
  10.923 +    template<typename I> I& first(I& i) const { g->first(i); return i; }
  10.924 +    template<typename I, typename P> I& first(I& i, const P& p) const { 
  10.925 +      g->first(i, p); return i; }
  10.926 +
  10.927 +    OutEdgeIt& next(OutEdgeIt& e) const {
  10.928 +      if (e.out_or_in) {
  10.929 +	Node n=g->tail(e.out);
  10.930 +	g->next(e.out);
  10.931 +	if (!g->valid(e.out)) { e.out_or_in=false; g->first(e.in, n); }
  10.932 +      } else {
  10.933 +	g->next(e.in);
  10.934 +      }
  10.935 +      return e;
  10.936 +    }
  10.937 +
  10.938 +    EdgeIt& next(EdgeIt& e) const {
  10.939 +      //NodeIt v=tail(e);
  10.940 +      g->next(e.out);
  10.941 +      while (valid(e.v) && !g->valid(e.out)) { 
  10.942 +	next(e.v); 
  10.943 +	if (valid(e.v)) g->first(e.out, e.v); 
  10.944 +      }
  10.945 +      return e;
  10.946 +    }
  10.947 +
  10.948 +    template<typename I> I& next(I &i) const { return g->next(i); }    
  10.949 +//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
  10.950 +
  10.951 +    template< typename It > It first() const { 
  10.952 +      It e; first(e); return e; }
  10.953 +
  10.954 +    template< typename It > It first(const Node& v) const { 
  10.955 +      It e; first(e, v); return e; }
  10.956 +
  10.957 +//    Node head(const Edge& e) const { return gw.head(e); }
  10.958 +//    Node tail(const Edge& e) const { return gw.tail(e); }
  10.959 +
  10.960 +//    template<typename I> bool valid(const I& i) const 
  10.961 +//      { return gw.valid(i); }
  10.962 +  
  10.963 +//    int nodeNum() const { return gw.nodeNum(); }
  10.964 +//    int edgeNum() const { return gw.edgeNum(); }
  10.965 +  
  10.966 +//     template<typename I> Node aNode(const I& e) const { 
  10.967 +//       return graph->aNode(e); }
  10.968 +//     template<typename I> Node bNode(const I& e) const { 
  10.969 +//       return graph->bNode(e); }
  10.970 +
  10.971 +    Node aNode(const OutEdgeIt& e) const { 
  10.972 +      if (e.out_or_in) return g->tail(e); else return g->head(e); }
  10.973 +    Node bNode(const OutEdgeIt& e) const { 
  10.974 +      if (e.out_or_in) return g->head(e); else return g->tail(e); }
  10.975 +  
  10.976 +//    Node addNode() const { return gw.addNode(); }
  10.977 +
  10.978 +// FIXME: ez igy nem jo, mert nem
  10.979 +//    Edge addEdge(const Node& tail, const Node& head) const { 
  10.980 +//      return graph->addEdge(tail, head); }
  10.981 +  
  10.982 +//    template<typename I> void erase(const I& i) const { gw.erase(i); }
  10.983 +  
  10.984 +//    void clear() const { gw.clear(); }
  10.985 +    
  10.986 +//     template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
  10.987 +//     public:
  10.988 +//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
  10.989 +// 	GraphWrapper::NodeMap<T>(_G.gw) { }
  10.990 +//       NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
  10.991 +// 	GraphWrapper::NodeMap<T>(_G.gw, a) { }
  10.992 +//     };
  10.993 +
  10.994 +//     template<typename T> class EdgeMap : 
  10.995 +//       public GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T> { 
  10.996 +//     public:
  10.997 +//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) : 
  10.998 +// 	GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T>(_G.gw) { }
  10.999 +//       EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : 
 10.1000 +// 	GraphWrapper::EdgeMap<T>(_G.gw, a) { }
 10.1001 +//     };
 10.1002 +   };
 10.1003 +
 10.1004 +
 10.1005 +
 10.1006 +
 10.1007 +
 10.1008 +//   template<typename Graph>
 10.1009 +//   class SymGraphWrapper
 10.1010 +//   {
 10.1011 +//     Graph* graph;
 10.1012 +  
 10.1013 +//   public:
 10.1014 +//     typedef Graph BaseGraph;
 10.1015 +
 10.1016 +//     typedef typename Graph::Node Node;
 10.1017 +//     typedef typename Graph::Edge Edge;
 10.1018 +  
 10.1019 +//     typedef typename Graph::NodeIt NodeIt;
 10.1020 +    
 10.1021 +//     //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
 10.1022 +//     //iranyitatlant, ami van
 10.1023 +//     //mert csak 1 dolgot lehet be typedef-elni
 10.1024 +//     typedef typename Graph::OutEdgeIt SymEdgeIt;
 10.1025 +//     //typedef typename Graph::InEdgeIt SymEdgeIt;
 10.1026 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
 10.1027 +//     typedef typename Graph::EdgeIt EdgeIt;
 10.1028 +
 10.1029 +//     int nodeNum() const { return graph->nodeNum(); }
 10.1030 +//     int edgeNum() const { return graph->edgeNum(); }
 10.1031 +    
 10.1032 +//     template<typename I> I& first(I& i) const { return graph->first(i); }
 10.1033 +//     template<typename I, typename P> I& first(I& i, const P& p) const { 
 10.1034 +//       return graph->first(i, p); }
 10.1035 +//     //template<typename I> I next(const I i); { return graph->goNext(i); }
 10.1036 +//     //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
 10.1037 +
 10.1038 +//     template< typename It > It first() const { 
 10.1039 +//       It e; first(e); return e; }
 10.1040 +
 10.1041 +//     template< typename It > It first(Node v) const { 
 10.1042 +//       It e; first(e, v); return e; }
 10.1043 +
 10.1044 +//     Node head(const Edge& e) const { return graph->head(e); }
 10.1045 +//     Node tail(const Edge& e) const { return graph->tail(e); }
 10.1046 +  
 10.1047 +//     template<typename I> Node aNode(const I& e) const { 
 10.1048 +//       return graph->aNode(e); }
 10.1049 +//     template<typename I> Node bNode(const I& e) const { 
 10.1050 +//       return graph->bNode(e); }
 10.1051 +  
 10.1052 +//     //template<typename I> bool valid(const I i);
 10.1053 +//     //{ return graph->valid(i); }
 10.1054 +  
 10.1055 +//     //template<typename I> void setInvalid(const I &i);
 10.1056 +//     //{ return graph->setInvalid(i); }
 10.1057 +  
 10.1058 +//     Node addNode() { return graph->addNode(); }
 10.1059 +//     Edge addEdge(const Node& tail, const Node& head) { 
 10.1060 +//       return graph->addEdge(tail, head); }
 10.1061 +  
 10.1062 +//     template<typename I> void erase(const I& i) { graph->erase(i); }
 10.1063 +  
 10.1064 +//     void clear() { graph->clear(); }
 10.1065 +  
 10.1066 +//     template<typename T> class NodeMap : public Graph::NodeMap<T> { };
 10.1067 +//     template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
 10.1068 +  
 10.1069 +//     void setGraph(Graph& _graph) { graph = &_graph; }
 10.1070 +//     Graph& getGraph() { return (*graph); }
 10.1071 +
 10.1072 +//     //SymGraphWrapper() : graph(0) { }
 10.1073 +//     SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
 10.1074 +//   };
 10.1075 +
 10.1076 +
 10.1077 +  template<typename GraphWrapper, typename Number, typename FlowMap, typename CapacityMap>
 10.1078 +  class ResGraphWrapper : public GraphWrapperSkeleton1<GraphWrapper>{
 10.1079 +  public:
 10.1080 +    //typedef Graph BaseGraph;
 10.1081 +    //typedef TrivGraphWrapper<const Graph> GraphWrapper;
 10.1082 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::Node Node;
 10.1083 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::NodeIt NodeIt;
 10.1084 +  private:
 10.1085 +    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/
 10.1086 +    GraphWrapper::OutEdgeIt OldOutEdgeIt;
 10.1087 +    typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/
 10.1088 +    GraphWrapper::InEdgeIt OldInEdgeIt;
 10.1089 +  protected:
 10.1090 +    //const Graph* graph;
 10.1091 +    //GraphWrapper gw;
 10.1092 +    FlowMap* flow;
 10.1093 +    const CapacityMap* capacity;
 10.1094 +  public:
 10.1095 +
 10.1096 +    ResGraphWrapper(GraphWrapper& _gw, FlowMap& _flow, 
 10.1097 +		    const CapacityMap& _capacity) : 
 10.1098 +      GraphWrapperSkeleton1<GraphWrapper>(_gw), 
 10.1099 +      flow(&_flow), capacity(&_capacity) { }
 10.1100 +
 10.1101 +    //void setGraph(const Graph& _graph) { graph = &_graph; }
 10.1102 +    //const Graph& getGraph() const { return (*graph); }
 10.1103 +
 10.1104 +    class Edge; 
 10.1105 +    class OutEdgeIt; 
 10.1106 +    friend class Edge; 
 10.1107 +    friend class OutEdgeIt; 
 10.1108 +
 10.1109 +    class Edge {
 10.1110 +      friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
 10.1111 +    protected:
 10.1112 +      bool out_or_in; //true, iff out
 10.1113 +      OldOutEdgeIt out;
 10.1114 +      OldInEdgeIt in;
 10.1115 +    public:
 10.1116 +      Edge() : out_or_in(true) { } 
 10.1117 +      Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
 10.1118 +//       bool valid() const { 
 10.1119 +// 	return out_or_in && out.valid() || in.valid(); }
 10.1120 +      friend bool operator==(const Edge& u, const Edge& v) { 
 10.1121 +	if (v.out_or_in) 
 10.1122 +	  return (u.out_or_in && u.out==v.out);
 10.1123 +	else
 10.1124 +	  return (!u.out_or_in && u.in==v.in);
 10.1125 +      } 
 10.1126 +      friend bool operator!=(const Edge& u, const Edge& v) { 
 10.1127 +	if (v.out_or_in) 
 10.1128 +	  return (!u.out_or_in || u.out!=v.out);
 10.1129 +	else
 10.1130 +	  return (u.out_or_in || u.in!=v.in);
 10.1131 +      } 
 10.1132 +    };
 10.1133 +
 10.1134 +
 10.1135 +    class OutEdgeIt : public Edge {
 10.1136 +      friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
 10.1137 +    public:
 10.1138 +      OutEdgeIt() { }
 10.1139 +      //FIXME
 10.1140 +      OutEdgeIt(const Edge& e) : Edge(e) { }
 10.1141 +      OutEdgeIt(const Invalid& i) : Edge(i) { }
 10.1142 +    protected:
 10.1143 +      OutEdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() { 
 10.1144 +	resG.g->first(out, v);
 10.1145 +	while( resG.g->valid(out) && !(resG.resCap(out)>0) ) { resG.g->next(out); }
 10.1146 +	if (!resG.g->valid(out)) {
 10.1147 +	  out_or_in=0;
 10.1148 +	  resG.g->first(in, v);
 10.1149 +	  while( resG.g->valid(in) && !(resG.resCap(in)>0) ) { resG.g->next(in); }
 10.1150 +	}
 10.1151 +      }
 10.1152 +//     public:
 10.1153 +//       OutEdgeIt& operator++() { 
 10.1154 +// 	if (out_or_in) {
 10.1155 +// 	  Node v=/*resG->*/G->aNode(out);
 10.1156 +// 	  ++out;
 10.1157 +// 	  while( out.valid() && !(Edge::resCap()>0) ) { ++out; }
 10.1158 +// 	  if (!out.valid()) {
 10.1159 +// 	    out_or_in=0;
 10.1160 +// 	    G->first(in, v); 
 10.1161 +// 	    while( in.valid() && !(Edge::resCap()>0) ) { ++in; }
 10.1162 +// 	  }
 10.1163 +// 	} else {
 10.1164 +// 	  ++in;
 10.1165 +// 	  while( in.valid() && !(Edge::resCap()>0) ) { ++in; } 
 10.1166 +// 	}
 10.1167 +// 	return *this; 
 10.1168 +//       }
 10.1169 +    };
 10.1170 +
 10.1171 +    //FIXME This is just for having InEdgeIt
 10.1172 +    typedef void InEdgeIt;
 10.1173 +
 10.1174 +    class EdgeIt : public Edge {
 10.1175 +      friend class ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>;
 10.1176 +      NodeIt v; 
 10.1177 +    public:
 10.1178 +      EdgeIt() { }
 10.1179 +      //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }
 10.1180 +      EdgeIt(const Invalid& i) : Edge(i) { }
 10.1181 +      EdgeIt(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& resG) : Edge() { 
 10.1182 +	resG.g->first(v);
 10.1183 +	if (resG.g->valid(v)) resG.g->first(out, v); else out=INVALID;
 10.1184 +	while (resG.g->valid(out) && !(resG.resCap(out)>0) ) { resG.g->next(out); }
 10.1185 +	while (resG.g->valid(v) && !resG.g->valid(out)) { 
 10.1186 +	  resG.g->next(v); 
 10.1187 +	  if (resG.g->valid(v)) resG.g->first(out, v); 
 10.1188 +	  while (resG.g->valid(out) && !(resG.resCap(out)>0) ) { resG.g->next(out); }
 10.1189 +	}
 10.1190 +	if (!resG.g->valid(out)) {
 10.1191 +	  out_or_in=0;
 10.1192 +	  resG.g->first(v);
 10.1193 +	  if (resG.g->valid(v)) resG.g->first(in, v); else in=INVALID;
 10.1194 +	  while (resG.g->valid(in) && !(resG.resCap(in)>0) ) { resG.g->next(in); }
 10.1195 +	  while (resG.g->valid(v) && !resG.g->valid(in)) { 
 10.1196 +	    resG.g->next(v); 
 10.1197 +	    if (resG.g->valid(v)) resG.g->first(in, v); 
 10.1198 +	    while (resG.g->valid(in) && !(resG.resCap(in)>0) ) { resG.g->next(in); }
 10.1199 +	  }
 10.1200 +	}
 10.1201 +      }
 10.1202 +//       EdgeIt& operator++() { 
 10.1203 +// 	if (out_or_in) {
 10.1204 +// 	  ++out;
 10.1205 +// 	  while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
 10.1206 +// 	  while (v.valid() && !out.valid()) { 
 10.1207 +// 	    ++v; 
 10.1208 +// 	    if (v.valid()) G->first(out, v); 
 10.1209 +// 	    while (out.valid() && !(Edge::resCap()>0) ) { ++out; }
 10.1210 +// 	  }
 10.1211 +// 	  if (!out.valid()) {
 10.1212 +// 	    out_or_in=0;
 10.1213 +// 	    G->first(v);
 10.1214 +// 	    if (v.valid()) G->first(in, v); else in=OldInEdgeIt();
 10.1215 +// 	    while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
 10.1216 +// 	    while (v.valid() && !in.valid()) { 
 10.1217 +// 	      ++v; 
 10.1218 +// 	      if (v.valid()) G->first(in, v); 
 10.1219 +// 	      while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
 10.1220 +// 	    }  
 10.1221 +// 	  }
 10.1222 +// 	} else {
 10.1223 +// 	  ++in;
 10.1224 +// 	  while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
 10.1225 +// 	  while (v.valid() && !in.valid()) { 
 10.1226 +// 	    ++v; 
 10.1227 +// 	    if (v.valid()) G->first(in, v); 
 10.1228 +// 	    while (in.valid() && !(Edge::resCap()>0) ) { ++in; }
 10.1229 +// 	  }
 10.1230 +// 	}
 10.1231 +// 	return *this;
 10.1232 +//       }
 10.1233 +    };
 10.1234 +
 10.1235 +    NodeIt& first(NodeIt& v) const { g->first(v); return v; }
 10.1236 +    OutEdgeIt& first(OutEdgeIt& e, Node v) const { 
 10.1237 +      e=OutEdgeIt(*this, v); 
 10.1238 +      return e;
 10.1239 +    }
 10.1240 +    EdgeIt& first(EdgeIt& e) const { 
 10.1241 +      e=EdgeIt(*this); 
 10.1242 +      return e;
 10.1243 +    }
 10.1244 +   
 10.1245 +    NodeIt& next(NodeIt& n) const { return g->next(n); }
 10.1246 +
 10.1247 +    OutEdgeIt& next(OutEdgeIt& e) const { 
 10.1248 +      if (e.out_or_in) {
 10.1249 +	Node v=g->aNode(e.out);
 10.1250 +	g->next(e.out);
 10.1251 +	while( g->valid(e.out) && !(resCap(e.out)>0) ) { g->next(e.out); }
 10.1252 +	if (!g->valid(e.out)) {
 10.1253 +	  e.out_or_in=0;
 10.1254 +	  g->first(e.in, v); 
 10.1255 +	  while( g->valid(e.in) && !(resCap(e.in)>0) ) { g->next(e.in); }
 10.1256 +	}
 10.1257 +      } else {
 10.1258 +	g->next(e.in);
 10.1259 +	while( g->valid(e.in) && !(resCap(e.in)>0) ) { g->next(e.in); } 
 10.1260 +      }
 10.1261 +      return e;
 10.1262 +    }
 10.1263 +
 10.1264 +    EdgeIt& next(EdgeIt& e) const { 
 10.1265 +      if (e.out_or_in) {
 10.1266 +	g->next(e.out);
 10.1267 +	while (g->valid(e.out) && !(resCap(e.out)>0) ) { g->next(e.out); }
 10.1268 +	  while (g->valid(e.v) && !g->valid(e.out)) { 
 10.1269 +	    g->next(e.v); 
 10.1270 +	    if (g->valid(e.v)) g->first(e.out, e.v); 
 10.1271 +	    while (g->valid(e.out) && !(resCap(e.out)>0) ) { g->next(e.out); }
 10.1272 +	  }
 10.1273 +	  if (!g->valid(e.out)) {
 10.1274 +	    e.out_or_in=0;
 10.1275 +	    g->first(e.v);
 10.1276 +	    if (g->valid(e.v)) g->first(e.in, e.v); else e.in=INVALID;
 10.1277 +	    while (g->valid(e.in) && !(resCap(e.in)>0) ) { g->next(e.in); }
 10.1278 +	    while (g->valid(e.v) && !g->valid(e.in)) { 
 10.1279 +	      g->next(e.v); 
 10.1280 +	      if (g->valid(e.v)) g->first(e.in, e.v); 
 10.1281 +	      while (g->valid(e.in) && !(resCap(e.in)>0) ) { g->next(e.in); }
 10.1282 +	    }  
 10.1283 +	  }
 10.1284 +	} else {
 10.1285 +	  g->next(e.in);
 10.1286 +	  while (g->valid(e.in) && !(resCap(e.in)>0) ) { g->next(e.in); }
 10.1287 +	  while (g->valid(e.v) && !g->valid(e.in)) { 
 10.1288 +	    g->next(e.v); 
 10.1289 +	    if (g->valid(e.v)) g->first(e.in, e.v); 
 10.1290 +	    while (g->valid(e.in) && !(resCap(e.in)>0) ) { g->next(e.in); }
 10.1291 +	  }
 10.1292 +	}
 10.1293 +	return e;
 10.1294 +      }
 10.1295 +    
 10.1296 +
 10.1297 +    template< typename It >
 10.1298 +    It first() const { 
 10.1299 +      It e;
 10.1300 +      first(e);
 10.1301 +      return e; 
 10.1302 +    }
 10.1303 +
 10.1304 +    template< typename It >
 10.1305 +    It first(Node v) const { 
 10.1306 +      It e;
 10.1307 +      first(e, v);
 10.1308 +      return e; 
 10.1309 +    }
 10.1310 +
 10.1311 +    Node tail(Edge e) const { 
 10.1312 +      return ((e.out_or_in) ? g->aNode(e.out) : g->aNode(e.in)); }
 10.1313 +    Node head(Edge e) const { 
 10.1314 +      return ((e.out_or_in) ? g->bNode(e.out) : g->bNode(e.in)); }
 10.1315 +
 10.1316 +    Node aNode(OutEdgeIt e) const { 
 10.1317 +      return ((e.out_or_in) ? g->aNode(e.out) : g->aNode(e.in)); }
 10.1318 +    Node bNode(OutEdgeIt e) const { 
 10.1319 +      return ((e.out_or_in) ? g->bNode(e.out) : g->bNode(e.in)); }
 10.1320 +
 10.1321 +    int nodeNum() const { return g->nodeNum(); }
 10.1322 +    //FIXME
 10.1323 +    //int edgeNum() const { return g->edgeNum(); }
 10.1324 +
 10.1325 +
 10.1326 +    int id(Node v) const { return g->id(v); }
 10.1327 +
 10.1328 +    bool valid(Node n) const { return g->valid(n); }
 10.1329 +    bool valid(Edge e) const { 
 10.1330 +      return e.out_or_in ? g->valid(e.out) : g->valid(e.in); }
 10.1331 +
 10.1332 +    void augment(const Edge& e, Number a) const {
 10.1333 +      if (e.out_or_in)  
 10.1334 +	flow->set(e.out, flow->get(e.out)+a);
 10.1335 +      else  
 10.1336 +	flow->set(e.in, flow->get(e.in)-a);
 10.1337 +    }
 10.1338 +
 10.1339 +    Number resCap(const Edge& e) const { 
 10.1340 +      if (e.out_or_in) 
 10.1341 +	return (capacity->get(e.out)-flow->get(e.out)); 
 10.1342 +      else 
 10.1343 +	return (flow->get(e.in)); 
 10.1344 +    }
 10.1345 +
 10.1346 +    Number resCap(OldOutEdgeIt out) const { 
 10.1347 +      return (capacity->get(out)-flow->get(out)); 
 10.1348 +    }
 10.1349 +    
 10.1350 +    Number resCap(OldInEdgeIt in) const { 
 10.1351 +      return (flow->get(in)); 
 10.1352 +    }
 10.1353 +
 10.1354 +//     template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 
 10.1355 +//     public:
 10.1356 +//       NodeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G) 
 10.1357 +// 	: GraphWrapper::NodeMap<T>(_G.gw) { }
 10.1358 +//       NodeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G, 
 10.1359 +// 	      T a) : GraphWrapper::NodeMap<T>(_G.gw, a) { }
 10.1360 +//     };
 10.1361 +
 10.1362 +//     template <typename T>
 10.1363 +//     class NodeMap {
 10.1364 +//       typename Graph::NodeMap<T> node_map; 
 10.1365 +//     public:
 10.1366 +//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { }
 10.1367 +//       NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { }
 10.1368 +//       void set(Node nit, T a) { node_map.set(nit, a); }
 10.1369 +//       T get(Node nit) const { return node_map.get(nit); }
 10.1370 +//     };
 10.1371 +
 10.1372 +    template <typename T>
 10.1373 +    class EdgeMap {
 10.1374 +      typename GraphWrapper::EdgeMap<T> forward_map, backward_map; 
 10.1375 +    public:
 10.1376 +      EdgeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.gw), backward_map(_G.gw) { }
 10.1377 +      EdgeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.gw, a), backward_map(_G.gw, a) { }
 10.1378 +      void set(Edge e, T a) { 
 10.1379 +	if (e.out_or_in) 
 10.1380 +	  forward_map.set(e.out, a); 
 10.1381 +	else 
 10.1382 +	  backward_map.set(e.in, a); 
 10.1383 +      }
 10.1384 +      T get(Edge e) { 
 10.1385 +	if (e.out_or_in) 
 10.1386 +	  return forward_map.get(e.out); 
 10.1387 +	else 
 10.1388 +	  return backward_map.get(e.in); 
 10.1389 +      }
 10.1390 +    };
 10.1391 +  };
 10.1392 +
 10.1393 +  //Subgraph on the same node-set and partial edge-set
 10.1394 +  template<typename GraphWrapper, typename FirstOutEdgesMap>
 10.1395 +  class ErasingFirstGraphWrapper : public GraphWrapperSkeleton1<GraphWrapper> {
 10.1396 +  protected:
 10.1397 +    FirstOutEdgesMap* first_out_edges;
 10.1398 +  public:
 10.1399 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::Node Node;
 10.1400 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::NodeIt NodeIt;
 10.1401 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::Edge Edge;
 10.1402 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::EdgeIt EdgeIt;
 10.1403 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::InEdgeIt InEdgeIt;
 10.1404 +    typedef typename GraphWrapperSkeleton1<GraphWrapper>::OutEdgeIt OutEdgeIt;
 10.1405 +
 10.1406 +    ErasingFirstGraphWrapper(GraphWrapper& _gw, FirstOutEdgesMap& _first_out_edges) : 
 10.1407 +      GraphWrapperSkeleton1<GraphWrapper>(_gw), first_out_edges(&_first_out_edges) { }  
 10.1408 +
 10.1409 +    template<typename I> I& first(I& i) const { 
 10.1410 +      g->first(i); 
 10.1411 +      //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
 10.1412 +      return i;
 10.1413 +    }
 10.1414 +    OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
 10.1415 +      e=first_out_edges->get(n);
 10.1416 +      return e;
 10.1417 +    }
 10.1418 +    template<typename I, typename P> I& first(I& i, const P& p) const { 
 10.1419 +      g->first(i, p); 
 10.1420 +      //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
 10.1421 +      return i;
 10.1422 +    }
 10.1423 +    
 10.1424 +    //template<typename I> I getNext(const I& i) const { 
 10.1425 +    //  return gw.getNext(i); 
 10.1426 +    //}
 10.1427 +    template<typename I> I& next(I &i) const { 
 10.1428 +      g->next(i); 
 10.1429 +      //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); }
 10.1430 +      return i;
 10.1431 +    }
 10.1432 +    
 10.1433 +    template< typename It > It first() const { 
 10.1434 +      It e; this->first(e); return e; }
 10.1435 +    
 10.1436 +    template< typename It > It first(const Node& v) const { 
 10.1437 +      It e; this->first(e, v); return e; }
 10.1438 +
 10.1439 +    void erase(const OutEdgeIt& e) const {
 10.1440 +      OutEdgeIt f=e;
 10.1441 +      this->next(f);
 10.1442 +      first_out_edges->set(this->tail(e), f);
 10.1443 +    }
 10.1444 +  };
 10.1445 +
 10.1446 +//   template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
 10.1447 +//   class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
 10.1448 +//   protected:
 10.1449 +//     ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
 10.1450 +//     //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
 10.1451 +//   public:
 10.1452 +//     ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow, 
 10.1453 +// 			   const CapacityMap& _capacity) : 
 10.1454 +//       ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), 
 10.1455 +//       first_out_edges(*this) /*, dist(*this)*/ { 
 10.1456 +//       for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) {
 10.1457 +// 	OutEdgeIt e;
 10.1458 +// 	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
 10.1459 +// 	first_out_edges.set(n, e);
 10.1460 +//       }
 10.1461 +//     }
 10.1462 +
 10.1463 +//     //void setGraph(Graph& _graph) { graph = &_graph; }
 10.1464 +//     //Graph& getGraph() const { return (*graph); }
 10.1465 +  
 10.1466 +//     //TrivGraphWrapper() : graph(0) { }
 10.1467 +//     //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { }
 10.1468 +
 10.1469 +//     //typedef Graph BaseGraph;
 10.1470 +
 10.1471 +//     //typedef typename Graph::Node Node;
 10.1472 +//     //typedef typename Graph::NodeIt NodeIt;
 10.1473 +
 10.1474 +//     //typedef typename Graph::Edge Edge;
 10.1475 +//     //typedef typename Graph::OutEdgeIt OutEdgeIt;
 10.1476 +//     //typedef typename Graph::InEdgeIt InEdgeIt;
 10.1477 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
 10.1478 +//     //typedef typename Graph::EdgeIt EdgeIt;
 10.1479 +
 10.1480 +//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
 10.1481 +//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
 10.1482 +
 10.1483 +//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
 10.1484 +//     typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
 10.1485 +//     //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
 10.1486 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
 10.1487 +//     //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
 10.1488 +
 10.1489 +//     NodeIt& first(NodeIt& n) const { 
 10.1490 +//       return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
 10.1491 +//     }
 10.1492 +
 10.1493 +//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { 
 10.1494 +//       e=first_out_edges.get(n);
 10.1495 +//       return e;
 10.1496 +//     }
 10.1497 +    
 10.1498 +//     //ROSSZ template<typename I> I& first(I& i) const { return first(i); }
 10.1499 +//     //ROSSZ template<typename I, typename P> I& first(I& i, const P& p) const { 
 10.1500 +//     //  return first(i, p); }
 10.1501 +    
 10.1502 +//     //template<typename I> I getNext(const I& i) const { 
 10.1503 +//     //  return gw.getNext(i); }
 10.1504 +//     //template<typename I> I& next(I &i) const { return gw.next(i); }    
 10.1505 +
 10.1506 +//     template< typename It > It first() const { 
 10.1507 +//       It e; first(e); return e; }
 10.1508 +
 10.1509 +//     template< typename It > It first(const Node& v) const { 
 10.1510 +//       It e; first(e, v); return e; }
 10.1511 +
 10.1512 +//     //Node head(const Edge& e) const { return gw.head(e); }
 10.1513 +//     //Node tail(const Edge& e) const { return gw.tail(e); }
 10.1514 +
 10.1515 +//     //template<typename I> bool valid(const I& i) const 
 10.1516 +//     //  { return gw.valid(i); }
 10.1517 +  
 10.1518 +//     //int nodeNum() const { return gw.nodeNum(); }
 10.1519 +//     //int edgeNum() const { return gw.edgeNum(); }
 10.1520 +  
 10.1521 +//     //template<typename I> Node aNode(const I& e) const { 
 10.1522 +//     //  return gw.aNode(e); }
 10.1523 +//     //template<typename I> Node bNode(const I& e) const { 
 10.1524 +//     //  return gw.bNode(e); }
 10.1525 +  
 10.1526 +//     //Node addNode() const { return gw.addNode(); }
 10.1527 +//     //Edge addEdge(const Node& tail, const Node& head) const { 
 10.1528 +//     //  return gw.addEdge(tail, head); }
 10.1529 +  
 10.1530 +//     //void erase(const OutEdgeIt& e) {
 10.1531 +//     //  first_out_edge(this->tail(e))=e;
 10.1532 +//     //}
 10.1533 +//     void erase(const Edge& e) {
 10.1534 +//       OutEdgeIt f(e);
 10.1535 +//       next(f);
 10.1536 +//       first_out_edges.set(this->tail(e), f);
 10.1537 +//     }
 10.1538 +//     //template<typename I> void erase(const I& i) const { gw.erase(i); }
 10.1539 +  
 10.1540 +//     //void clear() const { gw.clear(); }
 10.1541 +    
 10.1542 +//     template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { 
 10.1543 +//     public:
 10.1544 +//       NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : 
 10.1545 +// 	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
 10.1546 +//       NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : 
 10.1547 +// 	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
 10.1548 +//     };
 10.1549 +
 10.1550 +//     template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { 
 10.1551 +//     public:
 10.1552 +//       EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : 
 10.1553 +// 	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
 10.1554 +//       EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : 
 10.1555 +// 	ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
 10.1556 +//     };
 10.1557 +//   };
 10.1558 +
 10.1559 +//   template<typename GraphWrapper> 
 10.1560 +//   class FilterGraphWrapper {
 10.1561 +//   };
 10.1562 +
 10.1563 +//   template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
 10.1564 +//   class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
 10.1565 +
 10.1566 +//     //Graph* graph;
 10.1567 +  
 10.1568 +//   public:
 10.1569 +//     //typedef Graph BaseGraph;
 10.1570 +
 10.1571 +//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
 10.1572 +//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
 10.1573 +
 10.1574 +//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
 10.1575 +//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
 10.1576 +//     //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
 10.1577 +//     //typedef typename Graph::SymEdgeIt SymEdgeIt;
 10.1578 +//     typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
 10.1579 +
 10.1580 +//     //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
 10.1581 +    
 10.1582 +//   public:
 10.1583 +//     FilterGraphWrapper(const Graph& _G, FlowMap& _flow, 
 10.1584 +// 			   const CapacityMap& _capacity) : 
 10.1585 +//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, gw.nodeNum()) { 
 10.1586 +//     }
 10.1587 +
 10.1588 +//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {
 10.1589 +//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);
 10.1590 +//       while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e)))) 
 10.1591 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
 10.1592 +//       return e;
 10.1593 +//     }
 10.1594 +
 10.1595 +//     NodeIt& next(NodeIt& e) const {
 10.1596 +//       return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
 10.1597 +//     }
 10.1598 +
 10.1599 +//     OutEdgeIt& next(OutEdgeIt& e) const {
 10.1600 +//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
 10.1601 +//       while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e)))) 
 10.1602 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
 10.1603 +//       return e;
 10.1604 +//     }
 10.1605 +
 10.1606 +//     NodeIt& first(NodeIt& n) const {
 10.1607 +//       return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);
 10.1608 +//     }
 10.1609 +
 10.1610 +//     void erase(const Edge& e) {
 10.1611 +//       OutEdgeIt f(e);
 10.1612 +//       ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
 10.1613 +//       while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f)))) 
 10.1614 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
 10.1615 +//       first_out_edges.set(this->tail(e), f);
 10.1616 +//     }
 10.1617 +
 10.1618 +//     //TrivGraphWrapper() : graph(0) { }
 10.1619 +//     //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
 10.1620 +
 10.1621 +//     //void setGraph(Graph& _graph) { graph = &_graph; }
 10.1622 +//     //Graph& getGraph() const { return (*graph); }
 10.1623 +    
 10.1624 +//     //template<typename I> I& first(I& i) const { return gw.first(i); }
 10.1625 +//     //template<typename I, typename P> I& first(I& i, const P& p) const { 
 10.1626 +//     //  return gw.first(i, p); }
 10.1627 +    
 10.1628 +//     //template<typename I> I getNext(const I& i) const { 
 10.1629 +//     //  return gw.getNext(i); }
 10.1630 +//     //template<typename I> I& next(I &i) const { return gw.next(i); }    
 10.1631 +
 10.1632 +//     template< typename It > It first() const { 
 10.1633 +//       It e; first(e); return e; }
 10.1634 +
 10.1635 +//     template< typename It > It first(const Node& v) const { 
 10.1636 +//       It e; first(e, v); return e; }
 10.1637 +
 10.1638 +//     //Node head(const Edge& e) const { return gw.head(e); }
 10.1639 +//     //Node tail(const Edge& e) const { return gw.tail(e); }
 10.1640 +
 10.1641 +//     //template<typename I> bool valid(const I& i) const 
 10.1642 +//     //  { return gw.valid(i); }
 10.1643 +  
 10.1644 +//     //template<typename I> void setInvalid(const I &i);
 10.1645 +//     //{ return gw.setInvalid(i); }
 10.1646 +
 10.1647 +//     //int nodeNum() const { return gw.nodeNum(); }
 10.1648 +//     //int edgeNum() const { return gw.edgeNum(); }
 10.1649 +  
 10.1650 +//     //template<typename I> Node aNode(const I& e) const { 
 10.1651 +//     //  return gw.aNode(e); }
 10.1652 +//     //template<typename I> Node bNode(const I& e) const { 
 10.1653 +//     //  return gw.bNode(e); }
 10.1654 +  
 10.1655 +//     //Node addNode() const { return gw.addNode(); }
 10.1656 +//     //Edge addEdge(const Node& tail, const Node& head) const { 
 10.1657 +//     //  return gw.addEdge(tail, head); }
 10.1658 +  
 10.1659 +//     //template<typename I> void erase(const I& i) const { gw.erase(i); }
 10.1660 +  
 10.1661 +//     //void clear() const { gw.clear(); }
 10.1662 +    
 10.1663 +//     template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { 
 10.1664 +//     public:
 10.1665 +//       NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : 
 10.1666 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
 10.1667 +//       NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : 
 10.1668 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
 10.1669 +//     };
 10.1670 +
 10.1671 +//     template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { 
 10.1672 +//     public:
 10.1673 +//       EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : 
 10.1674 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
 10.1675 +//       EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : 
 10.1676 +// 	ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
 10.1677 +//     };
 10.1678 +
 10.1679 +//   public:
 10.1680 +//     ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
 10.1681 +
 10.1682 +//   };
 10.1683 +
 10.1684 +
 10.1685 +
 10.1686 +// // FIXME: comparison should be made better!!!
 10.1687 +//   template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
 10.1688 +//   class ResGraphWrapper
 10.1689 +//   {
 10.1690 +//     Graph* graph;
 10.1691 +  
 10.1692 +//   public:
 10.1693 +//     typedef Graph BaseGraph;
 10.1694 +
 10.1695 +//     typedef typename Graph::Node Node;
 10.1696 +//     typedef typename Graph::Edge Edge;
 10.1697 +  
 10.1698 +//     typedef typename Graph::NodeIt NodeIt;
 10.1699 +   
 10.1700 +//     class OutEdgeIt {
 10.1701 +//     public:
 10.1702 +//       //Graph::Node n;
 10.1703 +//       bool out_or_in;
 10.1704 +//       typename Graph::OutEdgeIt o;
 10.1705 +//       typename Graph::InEdgeIt i;   
 10.1706 +//     };
 10.1707 +//     class InEdgeIt {
 10.1708 +//     public:
 10.1709 +//       //Graph::Node n;
 10.1710 +//       bool out_or_in;
 10.1711 +//       typename Graph::OutEdgeIt o;
 10.1712 +//       typename Graph::InEdgeIt i;   
 10.1713 +//     };
 10.1714 +//     typedef typename Graph::SymEdgeIt SymEdgeIt;
 10.1715 +//     typedef typename Graph::EdgeIt EdgeIt;
 10.1716 +
 10.1717 +//     int nodeNum() const { return gw.nodeNum(); }
 10.1718 +//     int edgeNum() const { return gw.edgeNum(); }
 10.1719 +
 10.1720 +//     Node& first(Node& n) const { return gw.first(n); }
 10.1721 +
 10.1722 +//     // Edge and SymEdge  is missing!!!!
 10.1723 +//     // Edge <-> In/OutEdgeIt conversion is missing!!!!
 10.1724 +
 10.1725 +//     //FIXME
 10.1726 +//     OutEdgeIt& first(OutEdgeIt& e, const Node& n) const 
 10.1727 +//       {
 10.1728 +// 	e.n=n;
 10.1729 +// 	gw.first(e.o,n);
 10.1730 +// 	while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
 10.1731 +// 	  gw.goNext(e.o);
 10.1732 +// 	if(!gw.valid(e.o)) {
 10.1733 +// 	  gw.first(e.i,n);
 10.1734 +// 	  while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
 10.1735 +// 	    gw.goNext(e.i);
 10.1736 +// 	}
 10.1737 +// 	return e;
 10.1738 +//       }
 10.1739 +// /*
 10.1740 +//   OutEdgeIt &goNext(OutEdgeIt &e)
 10.1741 +//   {
 10.1742 +//   if(gw.valid(e.o)) {
 10.1743 +//   while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
 10.1744 +//   gw.goNext(e.o);
 10.1745 +//   if(gw.valid(e.o)) return e;
 10.1746 +//   else gw.first(e.i,e.n);
 10.1747 +//   }
 10.1748 +//   else {
 10.1749 +//   while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
 10.1750 +//   gw.goNext(e.i);
 10.1751 +//   return e;
 10.1752 +//   }
 10.1753 +//   }
 10.1754 +//   OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
 10.1755 +// */
 10.1756 +//     //bool valid(const OutEdgeIt e) { return gw.valid(e.o)||gw.valid(e.i);}
 10.1757 +
 10.1758 +//     //FIXME
 10.1759 +//     InEdgeIt& first(InEdgeIt& e, const Node& n) const 
 10.1760 +//       {
 10.1761 +// 	e.n=n;
 10.1762 +// 	gw.first(e.i,n);
 10.1763 +// 	while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
 10.1764 +// 	  gw.goNext(e.i);
 10.1765 +// 	if(!gw.valid(e.i)) {
 10.1766 +// 	  gw.first(e.o,n);
 10.1767 +// 	  while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
 10.1768 +// 	    gw.goNext(e.o);
 10.1769 +// 	}
 10.1770 +// 	return e;
 10.1771 +//       }
 10.1772 +// /*
 10.1773 +//   InEdgeIt &goNext(InEdgeIt &e)
 10.1774 +//   {
 10.1775 +//   if(gw.valid(e.i)) {
 10.1776 +//   while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
 10.1777 +//   gw.goNext(e.i);
 10.1778 +//   if(gw.valid(e.i)) return e;
 10.1779 +//   else gw.first(e.o,e.n);
 10.1780 +//   }
 10.1781 +//   else {
 10.1782 +//   while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
 10.1783 +//   gw.goNext(e.o);
 10.1784 +//   return e;
 10.1785 +//   }
 10.1786 +//   }
 10.1787 +//   InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
 10.1788 +// */
 10.1789 +//     //bool valid(const InEdgeIt e) { return gw.valid(e.i)||gw.valid(e.o);}
 10.1790 +
 10.1791 +//     //template<typename I> I &goNext(I &i); { return gw.goNext(i); }
 10.1792 +//     //template<typename I> I next(const I i); { return gw.goNext(i); }
 10.1793 +
 10.1794 +//     template< typename It > It first() const { 
 10.1795 +//       It e; first(e); return e; }
 10.1796 +
 10.1797 +//     template< typename It > It first(Node v) const { 
 10.1798 +//       It e; first(e, v); return e; }
 10.1799 +
 10.1800 +//     Node head(const Edge& e) const { return gw.head(e); }
 10.1801 +//     Node tail(const Edge& e) const { return gw.tail(e); }
 10.1802 +  
 10.1803 +//     template<typename I> Node aNode(const I& e) const { 
 10.1804 +//       return gw.aNode(e); }
 10.1805 +//     template<typename I> Node bNode(const I& e) const { 
 10.1806 +//       return gw.bNode(e); }
 10.1807 +  
 10.1808 +//     //template<typename I> bool valid(const I i);
 10.1809 +//     //{ return gw.valid(i); }
 10.1810 +  
 10.1811 +//     //template<typename I> void setInvalid(const I &i);
 10.1812 +//     //{ return gw.setInvalid(i); }
 10.1813 +  
 10.1814 +//     Node addNode() { return gw.addNode(); }
 10.1815 +//     Edge addEdge(const Node& tail, const Node& head) { 
 10.1816 +//       return gw.addEdge(tail, head); }
 10.1817 +  
 10.1818 +//     template<typename I> void erase(const I& i) { gw.erase(i); }
 10.1819 +  
 10.1820 +//     void clear() { gw.clear(); }
 10.1821 +  
 10.1822 +//     template<typename S> class NodeMap : public Graph::NodeMap<S> { };
 10.1823 +//     template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
 10.1824 +  
 10.1825 +//     void setGraph(Graph& _graph) { graph = &_graph; }
 10.1826 +//     Graph& getGraph() { return (*graph); }
 10.1827 +
 10.1828 +//     //ResGraphWrapper() : graph(0) { }
 10.1829 +//     ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
 10.1830 +//   };
 10.1831 +
 10.1832 +} //namespace hugo
 10.1833 +
 10.1834 +#endif //HUGO_GRAPH_WRAPPER_H
 10.1835 +
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/work/marci/experiment/iterator_bfs_demo.cc	Sat Apr 03 17:26:46 2004 +0000
    11.3 @@ -0,0 +1,322 @@
    11.4 +// -*- c++ -*-
    11.5 +#include <iostream>
    11.6 +#include <vector>
    11.7 +#include <string>
    11.8 +
    11.9 +#include <list_graph.h>
   11.10 +//#include <smart_graph.h>
   11.11 +#include <bfs_iterator_1.h>
   11.12 +#include <graph_wrapper_1.h>
   11.13 +
   11.14 +using namespace hugo;
   11.15 +using std::cout; 
   11.16 +using std::endl;
   11.17 +using std::string;
   11.18 +
   11.19 +template <typename Graph, typename NodeNameMap>
   11.20 +class EdgeNameMap {
   11.21 +  Graph& graph;
   11.22 +  NodeNameMap& node_name_map;
   11.23 +public:
   11.24 +  EdgeNameMap(Graph& _graph, NodeNameMap& _node_name_map) : 
   11.25 +    graph(_graph), node_name_map(_node_name_map) { }
   11.26 +  string get(typename Graph::Edge e) const { 
   11.27 +    return 
   11.28 +      (node_name_map.get(graph.tail(e))+"->"+node_name_map.get(graph.head(e)));
   11.29 +  }
   11.30 +};
   11.31 +
   11.32 +int main (int, char*[])
   11.33 +{
   11.34 +  //typedef SmartGraph Graph;
   11.35 +  typedef ListGraph Graph;
   11.36 +
   11.37 +  typedef Graph::Node Node;
   11.38 +  typedef Graph::Edge Edge;
   11.39 + 
   11.40 +  Graph G;
   11.41 +
   11.42 +  Node s=G.addNode();
   11.43 +  Node v1=G.addNode();
   11.44 +  Node v2=G.addNode();
   11.45 +  Node v3=G.addNode();
   11.46 +  Node v4=G.addNode();
   11.47 +  Node t=G.addNode();
   11.48 +  
   11.49 +  Graph::NodeMap<string> node_name(G);
   11.50 +  node_name.set(s, "s");
   11.51 +  node_name.set(v1, "v1");
   11.52 +  node_name.set(v2, "v2");
   11.53 +  node_name.set(v3, "v3");
   11.54 +  node_name.set(v4, "v4");
   11.55 +  node_name.set(t, "t");
   11.56 +
   11.57 +  G.addEdge(s, v1);
   11.58 +  G.addEdge(s, v2);
   11.59 +  G.addEdge(v1, v2);
   11.60 +  G.addEdge(v2, v1);
   11.61 +  G.addEdge(v1, v3);
   11.62 +  G.addEdge(v3, v2);
   11.63 +  G.addEdge(v2, v4);
   11.64 +  G.addEdge(v4, v3);
   11.65 +  G.addEdge(v3, t);
   11.66 +  G.addEdge(v4, t);
   11.67 +
   11.68 +  cout << "    /-->    ------------->            "<< endl;
   11.69 +  cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
   11.70 +  cout << "  / |          |    /  /->     \\     "<< endl;
   11.71 +  cout << " /  |          |   /  |    ^    \\  "<< endl;
   11.72 +  cout << "s   |          |  /   |    |     \\->  t "<< endl;
   11.73 +  cout << " \\  |          | /    |    |     /->  "<< endl;
   11.74 +  cout << "  \\ |       --/ /     |    |    /     "<< endl;
   11.75 +  cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
   11.76 +  cout << "    \\-->    ------------->         "<< endl;
   11.77 +  
   11.78 +//   typedef TrivGraphWrapper<const Graph> CGW;
   11.79 +//   CGW gw(G);
   11.80 +
   11.81 +//   cout << "bfs and dfs demo on the directed graph" << endl;
   11.82 +//   for(CGW::NodeIt n=gw.first<CGW::NodeIt>(); n.valid(); ++n) { 
   11.83 +//     cout << n << ": ";
   11.84 +//     cout << "out edges: ";
   11.85 +//     for(CGW::OutEdgeIt e=gw.first<CGW::OutEdgeIt>(n); e.valid(); ++e) 
   11.86 +//       cout << e << " ";
   11.87 +//     cout << "in edges: ";
   11.88 +//     for(CGW::InEdgeIt e=gw.first<CGW::InEdgeIt>(n); e.valid(); ++e) 
   11.89 +//       cout << e << " ";
   11.90 +//     cout << endl;
   11.91 +//   }
   11.92 +
   11.93 +  {
   11.94 +    typedef TrivGraphWrapper<const Graph> GW;
   11.95 +    GW gw(G);
   11.96 +
   11.97 +    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
   11.98 +    
   11.99 +    cout << "bfs and dfs iterator demo on the directed graph" << endl;
  11.100 +    for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
  11.101 +      cout << node_name.get(n) << ": ";
  11.102 +      cout << "out edges: ";
  11.103 +      for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  11.104 +	cout << edge_name.get(e) << " ";
  11.105 +      cout << "in edges: ";
  11.106 +      for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  11.107 +	cout << edge_name.get(e) << " ";
  11.108 +      cout << endl;
  11.109 +    }
  11.110 +
  11.111 +    cout << "bfs from s ..." << endl;
  11.112 +    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
  11.113 +    bfs.pushAndSetReached(s);
  11.114 +    while (!bfs.finished()) {
  11.115 +      //cout << "edge: ";
  11.116 +      if (gw.valid(bfs)) {
  11.117 +	cout << edge_name.get(bfs) << /*endl*/", " << 
  11.118 +	  node_name.get(gw.aNode(bfs)) << 
  11.119 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.120 +	  node_name.get(gw.bNode(bfs)) << 
  11.121 +	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
  11.122 +	   ": is not newly reached.");
  11.123 +      } else { 
  11.124 +	cout << "invalid" << /*endl*/", " << 
  11.125 +	  node_name.get(bfs.aNode()) << 
  11.126 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.127 +	  
  11.128 +	  "invalid.";
  11.129 +      }
  11.130 +      cout << endl;
  11.131 +      ++bfs;
  11.132 +    }
  11.133 +
  11.134 +    cout << "    /-->    ------------->            "<< endl;
  11.135 +    cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
  11.136 +    cout << "  / |          |    /  /->     \\     "<< endl;
  11.137 +    cout << " /  |          |   /  |    ^    \\  "<< endl;
  11.138 +    cout << "s   |          |  /   |    |     \\->  t "<< endl;
  11.139 +    cout << " \\  |          | /    |    |     /->  "<< endl;
  11.140 +    cout << "  \\ |       --/ /     |    |    /     "<< endl;
  11.141 +    cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
  11.142 +    cout << "    \\-->    ------------->         "<< endl;
  11.143 +
  11.144 +    cout << "dfs from s ..." << endl;
  11.145 +    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
  11.146 +    dfs.pushAndSetReached(s);
  11.147 +    while (!dfs.finished()) {
  11.148 +      ++dfs;
  11.149 +      //cout << "edge: ";
  11.150 +      if (gw.valid(dfs)) {
  11.151 +	cout << edge_name.get(dfs) << /*endl*/", " << 
  11.152 +	  node_name.get(gw.aNode(dfs)) << 
  11.153 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.154 +	  node_name.get(gw.bNode(dfs)) << 
  11.155 +	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
  11.156 +	   ": is not newly reached.");
  11.157 +      } else { 
  11.158 +	cout << "invalid" << /*endl*/", " << 
  11.159 +	  node_name.get(dfs.aNode()) << 
  11.160 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.161 +	  
  11.162 +	  "invalid.";
  11.163 +      }
  11.164 +      cout << endl;
  11.165 +    }
  11.166 +  }
  11.167 +
  11.168 +
  11.169 +  {
  11.170 +    typedef RevGraphWrapper<const TrivGraphWrapper<const Graph> > GW;
  11.171 +    GW gw(G);
  11.172 +    
  11.173 +    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
  11.174 +    
  11.175 +    cout << "bfs and dfs iterator demo on the reversed directed graph" << endl;
  11.176 +    for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
  11.177 +      cout << node_name.get(n) << ": ";
  11.178 +      cout << "out edges: ";
  11.179 +      for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  11.180 +	cout << edge_name.get(e) << " ";
  11.181 +      cout << "in edges: ";
  11.182 +      for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  11.183 +	cout << edge_name.get(e) << " ";
  11.184 +      cout << endl;
  11.185 +    }
  11.186 +
  11.187 +    cout << "bfs from t ..." << endl;
  11.188 +    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
  11.189 +    bfs.pushAndSetReached(t);
  11.190 +    while (!bfs.finished()) {
  11.191 +      //cout << "edge: ";
  11.192 +      if (gw.valid(bfs)) {
  11.193 +	cout << edge_name.get(bfs) << /*endl*/", " << 
  11.194 +	  node_name.get(gw.aNode(bfs)) << 
  11.195 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.196 +	  node_name.get(gw.bNode(bfs)) << 
  11.197 +	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
  11.198 +	   ": is not newly reached.");
  11.199 +      } else { 
  11.200 +	cout << "invalid" << /*endl*/", " << 
  11.201 +	  node_name.get(bfs.aNode()) << 
  11.202 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.203 +	  
  11.204 +	  "invalid.";
  11.205 +      }
  11.206 +      cout << endl;
  11.207 +      ++bfs;
  11.208 +    }
  11.209 +
  11.210 +    cout << "    /-->    ------------->            "<< endl;
  11.211 +    cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
  11.212 +    cout << "  / |          |    /  /->     \\     "<< endl;
  11.213 +    cout << " /  |          |   /  |    ^    \\  "<< endl;
  11.214 +    cout << "s   |          |  /   |    |     \\->  t "<< endl;
  11.215 +    cout << " \\  |          | /    |    |     /->  "<< endl;
  11.216 +    cout << "  \\ |       --/ /     |    |    /     "<< endl;
  11.217 +    cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
  11.218 +    cout << "    \\-->    ------------->         "<< endl;
  11.219 +    
  11.220 +    cout << "dfs from t ..." << endl;
  11.221 +    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
  11.222 +    dfs.pushAndSetReached(t);
  11.223 +    while (!dfs.finished()) {
  11.224 +      ++dfs;
  11.225 +      //cout << "edge: ";
  11.226 +      if (gw.valid(dfs)) {
  11.227 +	cout << edge_name.get(dfs) << /*endl*/", " << 
  11.228 +	  node_name.get(gw.aNode(dfs)) << 
  11.229 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.230 +	  node_name.get(gw.bNode(dfs)) << 
  11.231 +	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
  11.232 +	   ": is not newly reached.");
  11.233 +      } else { 
  11.234 +	cout << "invalid" << /*endl*/", " << 
  11.235 +	  node_name.get(dfs.aNode()) << 
  11.236 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.237 +	  
  11.238 +	  "invalid.";
  11.239 +      }
  11.240 +      cout << endl;
  11.241 +    }
  11.242 +  }
  11.243 +
  11.244 +  {
  11.245 +    //typedef UndirGraphWrapper<const Graph> GW;
  11.246 +    typedef UndirGraphWrapper<const TrivGraphWrapper<const Graph> > GW;
  11.247 +    GW gw(G);
  11.248 +    
  11.249 +    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
  11.250 +    
  11.251 +    cout << "bfs and dfs iterator demo on the undirected graph" << endl;
  11.252 +    for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
  11.253 +      cout << node_name.get(n) << ": ";
  11.254 +      cout << "out edges: ";
  11.255 +      for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  11.256 +	cout << edge_name.get(e) << " ";
  11.257 +      cout << "in edges: ";
  11.258 +      for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  11.259 +	cout << edge_name.get(e) << " ";
  11.260 +      cout << endl;
  11.261 +    }
  11.262 +//     for(GW::EdgeIt e=gw.first<GW::EdgeIt>(); gw.valid(e); gw.next(e)) { 
  11.263 +//       cout << edge_name.get(e) << " ";
  11.264 +//     }
  11.265 +//     cout << endl;
  11.266 +
  11.267 +    cout << "bfs from t ..." << endl;
  11.268 +    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
  11.269 +    bfs.pushAndSetReached(t);
  11.270 +    while (!bfs.finished()) {
  11.271 +      //cout << "edge: ";
  11.272 +      if (gw.valid(GW::OutEdgeIt(bfs))) {
  11.273 +	cout << edge_name.get(GW::OutEdgeIt(bfs)) << /*endl*/", " << 
  11.274 +	  node_name.get(gw.aNode(bfs)) << 
  11.275 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.276 +	  node_name.get(gw.bNode(bfs)) << 
  11.277 +	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
  11.278 +	   ": is not newly reached.");
  11.279 +      } else { 
  11.280 +	cout << "invalid" << /*endl*/", " << 
  11.281 +	  node_name.get(bfs.aNode()) << 
  11.282 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.283 +	  
  11.284 +	  "invalid.";
  11.285 +      }
  11.286 +      cout << endl;
  11.287 +      ++bfs;
  11.288 +    }
  11.289 +
  11.290 +    cout << "    /-->    ------------->            "<< endl;
  11.291 +    cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
  11.292 +    cout << "  / |          |    /  /->     \\     "<< endl;
  11.293 +    cout << " /  |          |   /  |    ^    \\  "<< endl;
  11.294 +    cout << "s   |          |  /   |    |     \\->  t "<< endl;
  11.295 +    cout << " \\  |          | /    |    |     /->  "<< endl;
  11.296 +    cout << "  \\ |       --/ /     |    |    /     "<< endl;
  11.297 +    cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
  11.298 +    cout << "    \\-->    ------------->         "<< endl;
  11.299 +    
  11.300 +    cout << "dfs from t ..." << endl;
  11.301 +    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
  11.302 +    dfs.pushAndSetReached(t);
  11.303 +    while (!dfs.finished()) {
  11.304 +      ++dfs;
  11.305 +      //cout << "edge: ";
  11.306 +      if (gw.valid(GW::OutEdgeIt(dfs))) {
  11.307 +	cout << edge_name.get(GW::OutEdgeIt(dfs)) << /*endl*/", " << 
  11.308 +	  node_name.get(gw.aNode(dfs)) << 
  11.309 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.310 +	  node_name.get(gw.bNode(dfs)) << 
  11.311 +	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
  11.312 +	   ": is not newly reached.");
  11.313 +      } else { 
  11.314 +	cout << "invalid" << /*endl*/", " << 
  11.315 +	  node_name.get(dfs.aNode()) << 
  11.316 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  11.317 +	  
  11.318 +	  "invalid.";
  11.319 +      }
  11.320 +      cout << endl;
  11.321 +    }
  11.322 +  }
  11.323 +
  11.324 +  return 0;
  11.325 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/work/marci/experiment/iterator_bfs_demo_1.cc	Sat Apr 03 17:26:46 2004 +0000
    12.3 @@ -0,0 +1,322 @@
    12.4 +// -*- c++ -*-
    12.5 +#include <iostream>
    12.6 +#include <vector>
    12.7 +#include <string>
    12.8 +
    12.9 +#include <list_graph.h>
   12.10 +#include <smart_graph.h>
   12.11 +#include <bfs_iterator.h>
   12.12 +#include <graph_wrapper.h>
   12.13 +
   12.14 +using namespace hugo;
   12.15 +using std::cout; 
   12.16 +using std::endl;
   12.17 +using std::string;
   12.18 +
   12.19 +template <typename Graph, typename NodeNameMap>
   12.20 +class EdgeNameMap {
   12.21 +  Graph& graph;
   12.22 +  NodeNameMap& node_name_map;
   12.23 +public:
   12.24 +  EdgeNameMap(Graph& _graph, NodeNameMap& _node_name_map) : 
   12.25 +    graph(_graph), node_name_map(_node_name_map) { }
   12.26 +  string get(typename Graph::Edge e) const { 
   12.27 +    return 
   12.28 +      (node_name_map.get(graph.tail(e))+"->"+node_name_map.get(graph.head(e)));
   12.29 +  }
   12.30 +};
   12.31 +
   12.32 +int main (int, char*[])
   12.33 +{
   12.34 +  //typedef SmartGraph Graph;
   12.35 +  typedef ListGraph Graph;
   12.36 +
   12.37 +  typedef Graph::Node Node;
   12.38 +  typedef Graph::Edge Edge;
   12.39 + 
   12.40 +  Graph G;
   12.41 +
   12.42 +  Node s=G.addNode();
   12.43 +  Node v1=G.addNode();
   12.44 +  Node v2=G.addNode();
   12.45 +  Node v3=G.addNode();
   12.46 +  Node v4=G.addNode();
   12.47 +  Node t=G.addNode();
   12.48 +  
   12.49 +  Graph::NodeMap<string> node_name(G);
   12.50 +  node_name.set(s, "s");
   12.51 +  node_name.set(v1, "v1");
   12.52 +  node_name.set(v2, "v2");
   12.53 +  node_name.set(v3, "v3");
   12.54 +  node_name.set(v4, "v4");
   12.55 +  node_name.set(t, "t");
   12.56 +
   12.57 +  G.addEdge(s, v1);
   12.58 +  G.addEdge(s, v2);
   12.59 +  G.addEdge(v1, v2);
   12.60 +  G.addEdge(v2, v1);
   12.61 +  G.addEdge(v1, v3);
   12.62 +  G.addEdge(v3, v2);
   12.63 +  G.addEdge(v2, v4);
   12.64 +  G.addEdge(v4, v3);
   12.65 +  G.addEdge(v3, t);
   12.66 +  G.addEdge(v4, t);
   12.67 +
   12.68 +  cout << "    /-->    ------------->            "<< endl;
   12.69 +  cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
   12.70 +  cout << "  / |          |    /  /->     \\     "<< endl;
   12.71 +  cout << " /  |          |   /  |    ^    \\  "<< endl;
   12.72 +  cout << "s   |          |  /   |    |     \\->  t "<< endl;
   12.73 +  cout << " \\  |          | /    |    |     /->  "<< endl;
   12.74 +  cout << "  \\ |       --/ /     |    |    /     "<< endl;
   12.75 +  cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
   12.76 +  cout << "    \\-->    ------------->         "<< endl;
   12.77 +  
   12.78 +//   typedef TrivGraphWrapper<const Graph> CGW;
   12.79 +//   CGW gw(G);
   12.80 +
   12.81 +//   cout << "bfs and dfs demo on the directed graph" << endl;
   12.82 +//   for(CGW::NodeIt n=gw.first<CGW::NodeIt>(); n.valid(); ++n) { 
   12.83 +//     cout << n << ": ";
   12.84 +//     cout << "out edges: ";
   12.85 +//     for(CGW::OutEdgeIt e=gw.first<CGW::OutEdgeIt>(n); e.valid(); ++e) 
   12.86 +//       cout << e << " ";
   12.87 +//     cout << "in edges: ";
   12.88 +//     for(CGW::InEdgeIt e=gw.first<CGW::InEdgeIt>(n); e.valid(); ++e) 
   12.89 +//       cout << e << " ";
   12.90 +//     cout << endl;
   12.91 +//   }
   12.92 +
   12.93 +  {
   12.94 +    typedef TrivGraphWrapper<const Graph> GW;
   12.95 +    GW gw(G);
   12.96 +
   12.97 +    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
   12.98 +    
   12.99 +    cout << "bfs and dfs iterator demo on the directed graph" << endl;
  12.100 +    for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
  12.101 +      cout << node_name.get(n) << ": ";
  12.102 +      cout << "out edges: ";
  12.103 +      for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  12.104 +	cout << edge_name.get(e) << " ";
  12.105 +      cout << "in edges: ";
  12.106 +      for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  12.107 +	cout << edge_name.get(e) << " ";
  12.108 +      cout << endl;
  12.109 +    }
  12.110 +
  12.111 +    cout << "bfs from s ..." << endl;
  12.112 +    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
  12.113 +    bfs.pushAndSetReached(s);
  12.114 +    while (!bfs.finished()) {
  12.115 +      //cout << "edge: ";
  12.116 +      if (gw.valid(bfs)) {
  12.117 +	cout << edge_name.get(bfs) << /*endl*/", " << 
  12.118 +	  node_name.get(gw.aNode(bfs)) << 
  12.119 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.120 +	  node_name.get(gw.bNode(bfs)) << 
  12.121 +	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
  12.122 +	   ": is not newly reached.");
  12.123 +      } else { 
  12.124 +	cout << "invalid" << /*endl*/", " << 
  12.125 +	  node_name.get(bfs.aNode()) << 
  12.126 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.127 +	  
  12.128 +	  "invalid.";
  12.129 +      }
  12.130 +      cout << endl;
  12.131 +      ++bfs;
  12.132 +    }
  12.133 +
  12.134 +    cout << "    /-->    ------------->            "<< endl;
  12.135 +    cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
  12.136 +    cout << "  / |          |    /  /->     \\     "<< endl;
  12.137 +    cout << " /  |          |   /  |    ^    \\  "<< endl;
  12.138 +    cout << "s   |          |  /   |    |     \\->  t "<< endl;
  12.139 +    cout << " \\  |          | /    |    |     /->  "<< endl;
  12.140 +    cout << "  \\ |       --/ /     |    |    /     "<< endl;
  12.141 +    cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
  12.142 +    cout << "    \\-->    ------------->         "<< endl;
  12.143 +
  12.144 +    cout << "dfs from s ..." << endl;
  12.145 +    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
  12.146 +    dfs.pushAndSetReached(s);
  12.147 +    while (!dfs.finished()) {
  12.148 +      ++dfs;
  12.149 +      //cout << "edge: ";
  12.150 +      if (gw.valid(dfs)) {
  12.151 +	cout << edge_name.get(dfs) << /*endl*/", " << 
  12.152 +	  node_name.get(gw.aNode(dfs)) << 
  12.153 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.154 +	  node_name.get(gw.bNode(dfs)) << 
  12.155 +	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
  12.156 +	   ": is not newly reached.");
  12.157 +      } else { 
  12.158 +	cout << "invalid" << /*endl*/", " << 
  12.159 +	  node_name.get(dfs.aNode()) << 
  12.160 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.161 +	  
  12.162 +	  "invalid.";
  12.163 +      }
  12.164 +      cout << endl;
  12.165 +    }
  12.166 +  }
  12.167 +
  12.168 +
  12.169 +  {
  12.170 +    typedef RevGraphWrapper<const TrivGraphWrapper<const Graph> > GW;
  12.171 +    GW gw(G);
  12.172 +    
  12.173 +    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
  12.174 +    
  12.175 +    cout << "bfs and dfs iterator demo on the reversed directed graph" << endl;
  12.176 +    for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
  12.177 +      cout << node_name.get(n) << ": ";
  12.178 +      cout << "out edges: ";
  12.179 +      for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  12.180 +	cout << edge_name.get(e) << " ";
  12.181 +      cout << "in edges: ";
  12.182 +      for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  12.183 +	cout << edge_name.get(e) << " ";
  12.184 +      cout << endl;
  12.185 +    }
  12.186 +
  12.187 +    cout << "bfs from t ..." << endl;
  12.188 +    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
  12.189 +    bfs.pushAndSetReached(t);
  12.190 +    while (!bfs.finished()) {
  12.191 +      //cout << "edge: ";
  12.192 +      if (gw.valid(bfs)) {
  12.193 +	cout << edge_name.get(bfs) << /*endl*/", " << 
  12.194 +	  node_name.get(gw.aNode(bfs)) << 
  12.195 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.196 +	  node_name.get(gw.bNode(bfs)) << 
  12.197 +	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
  12.198 +	   ": is not newly reached.");
  12.199 +      } else { 
  12.200 +	cout << "invalid" << /*endl*/", " << 
  12.201 +	  node_name.get(bfs.aNode()) << 
  12.202 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.203 +	  
  12.204 +	  "invalid.";
  12.205 +      }
  12.206 +      cout << endl;
  12.207 +      ++bfs;
  12.208 +    }
  12.209 +
  12.210 +    cout << "    /-->    ------------->            "<< endl;
  12.211 +    cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
  12.212 +    cout << "  / |          |    /  /->     \\     "<< endl;
  12.213 +    cout << " /  |          |   /  |    ^    \\  "<< endl;
  12.214 +    cout << "s   |          |  /   |    |     \\->  t "<< endl;
  12.215 +    cout << " \\  |          | /    |    |     /->  "<< endl;
  12.216 +    cout << "  \\ |       --/ /     |    |    /     "<< endl;
  12.217 +    cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
  12.218 +    cout << "    \\-->    ------------->         "<< endl;
  12.219 +    
  12.220 +    cout << "dfs from t ..." << endl;
  12.221 +    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
  12.222 +    dfs.pushAndSetReached(t);
  12.223 +    while (!dfs.finished()) {
  12.224 +      ++dfs;
  12.225 +      //cout << "edge: ";
  12.226 +      if (gw.valid(dfs)) {
  12.227 +	cout << edge_name.get(dfs) << /*endl*/", " << 
  12.228 +	  node_name.get(gw.aNode(dfs)) << 
  12.229 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.230 +	  node_name.get(gw.bNode(dfs)) << 
  12.231 +	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
  12.232 +	   ": is not newly reached.");
  12.233 +      } else { 
  12.234 +	cout << "invalid" << /*endl*/", " << 
  12.235 +	  node_name.get(dfs.aNode()) << 
  12.236 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.237 +	  
  12.238 +	  "invalid.";
  12.239 +      }
  12.240 +      cout << endl;
  12.241 +    }
  12.242 +  }
  12.243 +
  12.244 +  {
  12.245 +    //typedef UndirGraphWrapper<const Graph> GW;
  12.246 +    typedef UndirGraphWrapper<const TrivGraphWrapper<const Graph> > GW;
  12.247 +    GW gw(G);
  12.248 +    
  12.249 +    EdgeNameMap< GW, Graph::NodeMap<string> > edge_name(gw, node_name);
  12.250 +    
  12.251 +    cout << "bfs and dfs iterator demo on the undirected graph" << endl;
  12.252 +    for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { 
  12.253 +      cout << node_name.get(n) << ": ";
  12.254 +      cout << "out edges: ";
  12.255 +      for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  12.256 +	cout << edge_name.get(e) << " ";
  12.257 +      cout << "in edges: ";
  12.258 +      for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) 
  12.259 +	cout << edge_name.get(e) << " ";
  12.260 +      cout << endl;
  12.261 +    }
  12.262 +//     for(GW::EdgeIt e=gw.first<GW::EdgeIt>(); gw.valid(e); gw.next(e)) { 
  12.263 +//       cout << edge_name.get(e) << " ";
  12.264 +//     }
  12.265 +//     cout << endl;
  12.266 +
  12.267 +    cout << "bfs from t ..." << endl;
  12.268 +    BfsIterator5< GW, GW::NodeMap<bool> > bfs(gw);
  12.269 +    bfs.pushAndSetReached(t);
  12.270 +    while (!bfs.finished()) {
  12.271 +      //cout << "edge: ";
  12.272 +      if (gw.valid(GW::OutEdgeIt(bfs))) {
  12.273 +	cout << edge_name.get(GW::OutEdgeIt(bfs)) << /*endl*/", " << 
  12.274 +	  node_name.get(gw.aNode(bfs)) << 
  12.275 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.276 +	  node_name.get(gw.bNode(bfs)) << 
  12.277 +	  (bfs.isBNodeNewlyReached() ? ": is newly reached." : 
  12.278 +	   ": is not newly reached.");
  12.279 +      } else { 
  12.280 +	cout << "invalid" << /*endl*/", " << 
  12.281 +	  node_name.get(bfs.aNode()) << 
  12.282 +	  (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.283 +	  
  12.284 +	  "invalid.";
  12.285 +      }
  12.286 +      cout << endl;
  12.287 +      ++bfs;
  12.288 +    }
  12.289 +
  12.290 +    cout << "    /-->    ------------->            "<< endl;
  12.291 +    cout << "   / /-- v1 <-\\      /---- v3-\\      "<< endl;
  12.292 +    cout << "  / |          |    /  /->     \\     "<< endl;
  12.293 +    cout << " /  |          |   /  |    ^    \\  "<< endl;
  12.294 +    cout << "s   |          |  /   |    |     \\->  t "<< endl;
  12.295 +    cout << " \\  |          | /    |    |     /->  "<< endl;
  12.296 +    cout << "  \\ |       --/ /     |    |    /     "<< endl;
  12.297 +    cout << "   \\ \\-> v2 <--/       \\-- v4 -/      "<< endl;
  12.298 +    cout << "    \\-->    ------------->         "<< endl;
  12.299 +    
  12.300 +    cout << "dfs from t ..." << endl;
  12.301 +    DfsIterator5< GW, GW::NodeMap<bool> > dfs(gw);
  12.302 +    dfs.pushAndSetReached(t);
  12.303 +    while (!dfs.finished()) {
  12.304 +      ++dfs;
  12.305 +      //cout << "edge: ";
  12.306 +      if (gw.valid(GW::OutEdgeIt(dfs))) {
  12.307 +	cout << edge_name.get(GW::OutEdgeIt(dfs)) << /*endl*/", " << 
  12.308 +	  node_name.get(gw.aNode(dfs)) << 
  12.309 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.310 +	  node_name.get(gw.bNode(dfs)) << 
  12.311 +	  (dfs.isBNodeNewlyReached() ? ": is newly reached." : 
  12.312 +	   ": is not newly reached.");
  12.313 +      } else { 
  12.314 +	cout << "invalid" << /*endl*/", " << 
  12.315 +	  node_name.get(dfs.aNode()) << 
  12.316 +	  (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << 
  12.317 +	  
  12.318 +	  "invalid.";
  12.319 +      }
  12.320 +      cout << endl;
  12.321 +    }
  12.322 +  }
  12.323 +
  12.324 +  return 0;
  12.325 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/work/marci/experiment/list_graph.h	Sat Apr 03 17:26:46 2004 +0000
    13.3 @@ -0,0 +1,570 @@
    13.4 +// -*- c++ -*-
    13.5 +#ifndef HUGO_LIST_GRAPH_H
    13.6 +#define HUGO_LIST_GRAPH_H
    13.7 +
    13.8 +#include <iostream>
    13.9 +#include <vector>
   13.10 +
   13.11 +#include <invalid.h>
   13.12 +
   13.13 +namespace hugo {
   13.14 +
   13.15 +  template <typename It>
   13.16 +  int count(It it) { 
   13.17 +    int i=0;
   13.18 +    for( ; it.valid(); ++it) { ++i; } 
   13.19 +    return i;
   13.20 +  }
   13.21 +
   13.22 +  class ListGraph {
   13.23 +    class node_item;
   13.24 +    class edge_item;
   13.25 +  public:
   13.26 +    class Node;
   13.27 +    class NodeIt;
   13.28 +    class Edge;
   13.29 +    class EdgeIt;
   13.30 +    class OutEdgeIt;
   13.31 +    class InEdgeIt;
   13.32 +    class SymEdgeIt;
   13.33 +    template <typename T> class NodeMap;
   13.34 +    template <typename T> class EdgeMap;
   13.35 +  private:
   13.36 +    template <typename T> friend class NodeMap;
   13.37 +    template <typename T> friend class EdgeMap;
   13.38 + 
   13.39 +    template <typename T>
   13.40 +    class NodeMap {
   13.41 +      const ListGraph& G; 
   13.42 +      std::vector<T> container;
   13.43 +    public:
   13.44 +      typedef T ValueType;
   13.45 +      typedef Node KeyType;
   13.46 +      NodeMap(const ListGraph& _G) : G(_G), container(G.node_id) { }
   13.47 +      NodeMap(const ListGraph& _G, T a) : 
   13.48 +	G(_G), container(G.node_id, a) { }
   13.49 +      void set(Node n, T a) { container[/*G.id(n)*/n.node->id]=a; }
   13.50 +      T get(Node n) const { return container[/*G.id(n)*/n.node->id]; }
   13.51 +      typename std::vector<T>::reference operator[](Node n) { 
   13.52 +	return container[/*G.id(n)*/n.node->id]; }
   13.53 +      typename std::vector<T>::const_reference operator[](Node n) const { 
   13.54 +	return container[/*G.id(n)*/n.node->id]; 
   13.55 +      }
   13.56 +      void update() { container.resize(G.node_id); }
   13.57 +      void update(T a) { container.resize(G.node_id, a); }
   13.58 +    };
   13.59 +
   13.60 +    template <typename T>
   13.61 +    class EdgeMap {
   13.62 +      const ListGraph& G; 
   13.63 +      std::vector<T> container;
   13.64 +    public:
   13.65 +      typedef T ValueType;
   13.66 +      typedef Edge KeyType;
   13.67 +      EdgeMap(const ListGraph& _G) : G(_G), container(G.edge_id) { }
   13.68 +      EdgeMap(const ListGraph& _G, T a) : 
   13.69 +	G(_G), container(G.edge_id, a) { }
   13.70 +      void set(Edge e, T a) { container[/*G.id(e)*/e.edge->id]=a; }
   13.71 +      T get(Edge e) const { return container[/*G.id(e)*/e.edge->id]; }
   13.72 +      typename std::vector<T>::reference operator[](Edge e) { 
   13.73 +	return container[/*G.id(e)*/e.edge->id]; } 
   13.74 +      typename std::vector<T>::const_reference operator[](Edge e) const { 
   13.75 +	return container[/*G.id(e)*/e.edge->id]; 
   13.76 +      } 
   13.77 +      void update() { container.resize(G.edge_id); }
   13.78 +      void update(T a) { container.resize(G.edge_id, a); }
   13.79 +    };
   13.80 +
   13.81 +    int node_id;
   13.82 +    int edge_id;
   13.83 +    int _node_num;
   13.84 +    int _edge_num;
   13.85 +
   13.86 +    node_item* _first_node;
   13.87 +    node_item* _last_node;
   13.88 +
   13.89 +    class node_item {
   13.90 +      friend class ListGraph;
   13.91 +      template <typename T> friend class NodeMap;
   13.92 +      
   13.93 +      friend class Node;
   13.94 +      friend class NodeIt;
   13.95 +      friend class Edge;
   13.96 +      friend class EdgeIt;
   13.97 +      friend class OutEdgeIt;
   13.98 +      friend class InEdgeIt;
   13.99 +      friend class SymEdgeIt;
  13.100 +      friend std::ostream& operator<<(std::ostream& os, const Node& i);
  13.101 +      friend std::ostream& operator<<(std::ostream& os, const Edge& i);
  13.102 +      //ListGraph* G;
  13.103 +      int id;
  13.104 +      edge_item* _first_out_edge;
  13.105 +      edge_item* _last_out_edge;
  13.106 +      edge_item* _first_in_edge;
  13.107 +      edge_item* _last_in_edge;
  13.108 +      node_item* _next_node;
  13.109 +      node_item* _prev_node;
  13.110 +    public:
  13.111 +      node_item() { }
  13.112 +    };
  13.113 +
  13.114 +    class edge_item {
  13.115 +      friend class ListGraph;
  13.116 +      template <typename T> friend class EdgeMap;
  13.117 +
  13.118 +      friend class Node;
  13.119 +      friend class NodeIt;
  13.120 +      friend class Edge;
  13.121 +      friend class EdgeIt;
  13.122 +      friend class OutEdgeIt;
  13.123 +      friend class InEdgeIt;
  13.124 +      friend class SymEdgeIt;
  13.125 +      friend std::ostream& operator<<(std::ostream& os, const Edge& i);
  13.126 +      //ListGraph* G;
  13.127 +      int id;
  13.128 +      node_item* _tail;
  13.129 +      node_item* _head;
  13.130 +      edge_item* _next_out;
  13.131 +      edge_item* _prev_out;
  13.132 +      edge_item* _next_in;
  13.133 +      edge_item* _prev_in;
  13.134 +    public:
  13.135 +      edge_item() { }
  13.136 +    };
  13.137 +
  13.138 +    node_item* _add_node() { 
  13.139 +      node_item* p=new node_item;
  13.140 +      p->id=node_id++;
  13.141 +      p->_first_out_edge=0;
  13.142 +      p->_last_out_edge=0;
  13.143 +      p->_first_in_edge=0;
  13.144 +      p->_last_in_edge=0;
  13.145 +      p->_prev_node=_last_node;
  13.146 +      p->_next_node=0;
  13.147 +      if (_last_node) _last_node->_next_node=p;
  13.148 +      _last_node=p;
  13.149 +      if (!_first_node) _first_node=p;
  13.150 +
  13.151 +      ++_node_num;
  13.152 +      return p;
  13.153 +    }
  13.154 +
  13.155 +    edge_item* _add_edge(node_item* _tail, node_item* _head) {
  13.156 +      edge_item* e=new edge_item;
  13.157 +      e->id=edge_id++;
  13.158 +      e->_tail=_tail;
  13.159 +      e->_head=_head;
  13.160 +      
  13.161 +      e->_prev_out=_tail->_last_out_edge;
  13.162 +      if (_tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;
  13.163 +      _tail->_last_out_edge=e;
  13.164 +      if (!_tail->_first_out_edge) _tail->_first_out_edge=e; 
  13.165 +      e->_next_out=0;
  13.166 + 
  13.167 +      e->_prev_in=_head->_last_in_edge;
  13.168 +      if (_head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;
  13.169 +      _head->_last_in_edge=e;
  13.170 +      if (!_head->_first_in_edge) { _head->_first_in_edge=e; } 
  13.171 +      e->_next_in=0;
  13.172 +
  13.173 +      ++_edge_num;
  13.174 +      return e;
  13.175 +    }
  13.176 +
  13.177 +    //deletes a node which has no out edge and no in edge
  13.178 +    void _delete_node(node_item* v) {
  13.179 +      if (v->_next_node) (v->_next_node)->_prev_node=v->_prev_node; else 
  13.180 +	_last_node=v->_prev_node;
  13.181 +      if (v->_prev_node) (v->_prev_node)->_next_node=v->_next_node; else 
  13.182 +	_first_node=v->_next_node;
  13.183 +
  13.184 +      delete v;
  13.185 +      --_node_num;
  13.186 +    }
  13.187 +
  13.188 +    void _delete_edge(edge_item* e) {
  13.189 +      if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else 
  13.190 +	(e->_tail)->_last_out_edge=e->_prev_out;
  13.191 +      if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else 
  13.192 +	(e->_tail)->_first_out_edge=e->_next_out;
  13.193 +      if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else 
  13.194 +	(e->_head)->_last_in_edge=e->_prev_in;
  13.195 +      if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else 
  13.196 +	(e->_head)->_first_in_edge=e->_next_in;
  13.197 +
  13.198 +      delete e;
  13.199 +      --_edge_num;
  13.200 +    }
  13.201 +
  13.202 +    void _set_tail(edge_item* e, node_item* _tail) {
  13.203 +      if (e->_next_out) (e->_next_out)->_prev_out=e->_prev_out; else 
  13.204 +	(e->_tail)->_last_out_edge=e->_prev_out;
  13.205 +      if (e->_prev_out) (e->_prev_out)->_next_out=e->_next_out; else 
  13.206 +	(e->_tail)->_first_out_edge=e->_next_out;
  13.207 +      
  13.208 +      e->_tail=_tail;
  13.209 +      
  13.210 +      e->_prev_out=_tail->_last_out_edge;
  13.211 +      if (_tail->_last_out_edge) (_tail->_last_out_edge)->_next_out=e;
  13.212 +      _tail->_last_out_edge=e;
  13.213 +      if (!_tail->_first_out_edge) _tail->_first_out_edge=e; 
  13.214 +      e->_next_out=0;
  13.215 +    }
  13.216 +
  13.217 +    void _set_head(edge_item* e, node_item* _head) {
  13.218 +      if (e->_next_in) (e->_next_in)->_prev_in=e->_prev_in; else 
  13.219 +	(e->_head)->_last_in_edge=e->_prev_in;
  13.220 +      if (e->_prev_in) (e->_prev_in)->_next_in=e->_next_in; else 
  13.221 +	(e->_head)->_first_in_edge=e->_next_in;
  13.222 +      
  13.223 +      e->_head=_head;
  13.224 +      
  13.225 +      e->_prev_in=_head->_last_in_edge;
  13.226 +      if (_head->_last_in_edge) (_head->_last_in_edge)->_next_in=e;
  13.227 +      _head->_last_in_edge=e;
  13.228 +      if (!_head->_first_in_edge) { _head->_first_in_edge=e; } 
  13.229 +      e->_next_in=0;
  13.230 +    }
  13.231 +
  13.232 +  public:
  13.233 +
  13.234 +    /* default constructor */
  13.235 +
  13.236 +    ListGraph() : node_id(0), edge_id(0), _node_num(0), _edge_num(0), _first_node(0), _last_node(0) { }
  13.237 +    
  13.238 +    ~ListGraph() { 
  13.239 +      while (first<NodeIt>().valid()) erase(first<NodeIt>());
  13.240 +    }
  13.241 +
  13.242 +    int nodeNum() const { return _node_num; }
  13.243 +    int edgeNum() const { return _edge_num; }
  13.244 +
  13.245 +    /* functions to construct iterators from the graph, or from each other */
  13.246 +
  13.247 +    //NodeIt firstNode() const { return NodeIt(*this); }
  13.248 +    //EdgeIt firstEdge() const { return EdgeIt(*this); }
  13.249 +    
  13.250 +    //OutEdgeIt firstOutEdge(const Node v) const { return OutEdgeIt(v); }
  13.251 +    //InEdgeIt firstInEdge(const Node v) const { return InEdgeIt(v); }
  13.252 +    //SymEdgeIt firstSymEdge(const Node v) const { return SymEdgeIt(v); }
  13.253 +    Node tail(Edge e) const { return e.tailNode(); }
  13.254 +    Node head(Edge e) const { return e.headNode(); }
  13.255 +
  13.256 +    Node aNode(const OutEdgeIt& e) const { return e.aNode(); }
  13.257 +    Node aNode(const InEdgeIt& e) const { return e.aNode(); }
  13.258 +    Node aNode(const SymEdgeIt& e) const { return e.aNode(); }
  13.259 +
  13.260 +    Node bNode(const OutEdgeIt& e) const { return e.bNode(); }
  13.261 +    Node bNode(const InEdgeIt& e) const { return e.bNode(); }
  13.262 +    Node bNode(const SymEdgeIt& e) const { return e.bNode(); }
  13.263 +
  13.264 +    //Node invalid_node() { return Node(); }
  13.265 +    //Edge invalid_edge() { return Edge(); }
  13.266 +    //OutEdgeIt invalid_out_edge() { return OutEdgeIt(); }
  13.267 +    //InEdgeIt invalid_in_edge() { return InEdgeIt(); }
  13.268 +    //SymEdgeIt invalid_sym_edge() { return SymEdgeIt(); }
  13.269 +
  13.270 +    /* same methods in other style */
  13.271 +    /* for experimental purpose */
  13.272 +
  13.273 +    NodeIt& /*getF*/first(NodeIt& v) const { 
  13.274 +      v=NodeIt(*this); return v; }
  13.275 +    EdgeIt& /*getF*/first(EdgeIt& e) const { 
  13.276 +      e=EdgeIt(*this); return e; }
  13.277 +    OutEdgeIt& /*getF*/first(OutEdgeIt& e, Node v) const { 
  13.278 +      e=OutEdgeIt(*this, v); return e; }
  13.279 +    InEdgeIt& /*getF*/first(InEdgeIt& e, Node v) const { 
  13.280 +      e=InEdgeIt(*this, v); return e; }
  13.281 +    SymEdgeIt& /*getF*/first(SymEdgeIt& e, Node v) const { 
  13.282 +      e=SymEdgeIt(*this, v); return e; }
  13.283 +    //void getTail(Node& n, const Edge& e) const { n=tail(e); }
  13.284 +    //void getHead(Node& n, const Edge& e) const { n=head(e); }
  13.285 +
  13.286 +    //void getANode(Node& n, const OutEdgeIt& e) const { n=e.aNode(); }
  13.287 +    //void getANode(Node& n, const InEdgeIt& e) const { n=e.aNode(); }
  13.288 +    //void getANode(Node& n, const SymEdgeIt& e) const { n=e.aNode(); }
  13.289 +    //void getBNode(Node& n, const OutEdgeIt& e) const { n=e.bNode(); }
  13.290 +    //void getBNode(Node& n, const InEdgeIt& e) const { n=e.bNode(); }
  13.291 +    //void getBNode(Node& n, const SymEdgeIt& e) const { n=e.bNode(); }
  13.292 +    //void get_invalid(Node& n) { n=Node(); }
  13.293 +    //void get_invalid(Edge& e) { e=Edge(); }
  13.294 +    //void get_invalid(OutEdgeIt& e) { e=OutEdgeIt(); }
  13.295 +    //void get_invalid(InEdgeIt& e) { e=InEdgeIt(); }
  13.296 +    //void get_invalid(SymEdgeIt& e) { e=SymEdgeIt(); }
  13.297 +
  13.298 +    template< typename It >
  13.299 +    It first() const { 
  13.300 +      It e;
  13.301 +      /*getF*/first(e);
  13.302 +      return e; 
  13.303 +    }
  13.304 +
  13.305 +    template< typename It >
  13.306 +    It first(Node v) const { 
  13.307 +      It e;
  13.308 +      /*getF*/first(e, v);
  13.309 +      return e; 
  13.310 +    }
  13.311 +
  13.312 +    bool valid(Node n) const { return n.valid(); }
  13.313 +    bool valid(Edge e) const { return e.valid(); }
  13.314 +    
  13.315 +//    template <typename It> It getNext(It it) const { 
  13.316 +//      It tmp(it); next(tmp); return tmp; }
  13.317 +//     NodeIt& next(NodeIt& it) const { return ++it; }
  13.318 +//     EdgeIt& next(EdgeIt& it) const { return ++it; }
  13.319 +//     OutEdgeIt& next(OutEdgeIt& it) const { return ++it; }
  13.320 +//     InEdgeIt& next(InEdgeIt& it) const { return ++it; }
  13.321 +//     SymEdgeIt& next(SymEdgeIt& it) const { return ++it; }
  13.322 +//    template <typename It> It& next(It& it) const { return ++it; }
  13.323 +    template <typename It> It& next(It& it) const { ++it; return it; }
  13.324 +   
  13.325 +
  13.326 +    /* for getting id's of graph objects */
  13.327 +    /* these are important for the implementation of property vectors */
  13.328 +
  13.329 +    int id(Node v) const { return v.node->id; }
  13.330 +    int id(Edge e) const { return e.edge->id; }
  13.331 +
  13.332 +    /* adding nodes and edges */
  13.333 +
  13.334 +    Node addNode() { return Node(_add_node()); }
  13.335 +    Edge addEdge(Node u, Node v) {
  13.336 +      return Edge(_add_edge(u.node, v.node)); 
  13.337 +    }
  13.338 +
  13.339 +    void erase(Node i) { 
  13.340 +      while (first<OutEdgeIt>(i).valid()) erase(first<OutEdgeIt>(i));
  13.341 +      while (first<InEdgeIt>(i).valid()) erase(first<InEdgeIt>(i));
  13.342 +      _delete_node(i.node); 
  13.343 +    }
  13.344 +  
  13.345 +    void erase(Edge e) { _delete_edge(e.edge); }
  13.346 +
  13.347 +    void clear() { 
  13.348 +      while (first<NodeIt>().valid()) erase(first<NodeIt>());
  13.349 +    }
  13.350 +
  13.351 +    void setTail(Edge e, Node tail) {
  13.352 +      _set_tail(e.edge, tail.node); 
  13.353 +    }
  13.354 +
  13.355 +    void setHead(Edge e, Node head) {
  13.356 +      _set_head(e.edge, head.node); 
  13.357 +    }
  13.358 +
  13.359 +    /* stream operations, for testing purpose */
  13.360 +
  13.361 +    friend std::ostream& operator<<(std::ostream& os, const Node& i) { 
  13.362 +      os << i.node->id; return os; 
  13.363 +    }
  13.364 +    friend std::ostream& operator<<(std::ostream& os, const Edge& i) { 
  13.365 +      os << "(" << i.edge->_tail->id << "--" << i.edge->id << "->" << i.edge->_head->id << ")"; 
  13.366 +      return os; 
  13.367 +    }
  13.368 +
  13.369 +    class Node {
  13.370 +      friend class ListGraph;
  13.371 +      template <typename T> friend class NodeMap;
  13.372 +
  13.373 +      friend class Edge;
  13.374 +      friend class OutEdgeIt;
  13.375 +      friend class InEdgeIt;
  13.376 +      friend class SymEdgeIt;
  13.377 +      //public:  //FIXME: It is required by op= of NodeIt
  13.378 +    protected:
  13.379 +      node_item* node;
  13.380 +    protected:
  13.381 +      friend int ListGraph::id(Node v) const; 
  13.382 +    public:
  13.383 +      Node() /*: node(0)*/ { }
  13.384 +      Node(const Invalid&) : node(0) { }
  13.385 +    protected:
  13.386 +      Node(node_item* _node) : node(_node) { }
  13.387 +      bool valid() const { return (node); }
  13.388 +    public:
  13.389 +      //void makeInvalid() { node=0; }
  13.390 +      friend bool operator==(Node u, Node v) { return v.node==u.node; } 
  13.391 +      friend bool operator!=(Node u, Node v) { return v.node!=u.node; } 
  13.392 +      friend std::ostream& operator<<(std::ostream& os, const Node& i);
  13.393 +    };
  13.394 +    
  13.395 +    class NodeIt : public Node {
  13.396 +      friend class ListGraph;
  13.397 +      //protected:
  13.398 +    public: //for everybody but marci
  13.399 +      NodeIt(const ListGraph& G) : Node(G._first_node) { }
  13.400 +    public:
  13.401 +      NodeIt() : Node() { }
  13.402 +      NodeIt(const Invalid& i) : Node(i) { }
  13.403 +    protected:
  13.404 +      NodeIt(node_item* v) : Node(v) { }
  13.405 +      NodeIt& operator++() { node=node->_next_node; return *this; }
  13.406 +      //FIXME::
  13.407 +      //      NodeIt& operator=(const Node& e)
  13.408 +      //      { node=e.node; return *this; }
  13.409 +    };
  13.410 +
  13.411 +    class Edge {
  13.412 +      friend class ListGraph;
  13.413 +      template <typename T> friend class EdgeMap;
  13.414 +      
  13.415 +      friend class Node;
  13.416 +      friend class NodeIt;
  13.417 +    protected:
  13.418 +      edge_item* edge;
  13.419 +      friend int ListGraph::id(Edge e) const;
  13.420 +    public:
  13.421 +      Edge() /*: edge(0)*/ { }
  13.422 +      Edge(const Invalid&) : edge(0) { }
  13.423 +      //Edge() { }
  13.424 +    protected:
  13.425 +      Edge(edge_item* _edge) : edge(_edge) { }
  13.426 +      bool valid() const { return (edge); }
  13.427 +    public:
  13.428 +      //void makeInvalid() { edge=0; }
  13.429 +      friend bool operator==(Edge u, Edge v) { return v.edge==u.edge; } 
  13.430 +      friend bool operator!=(Edge u, Edge v) { return v.edge!=u.edge; } 
  13.431 +    protected:
  13.432 +      Node tailNode() const { return Node(edge->_tail); }
  13.433 +      Node headNode() const { return Node(edge->_head); }
  13.434 +    public:
  13.435 +      friend std::ostream& operator<<(std::ostream& os, const Edge& i);
  13.436 +    };
  13.437 +    
  13.438 +    class EdgeIt : public Edge {
  13.439 +      friend class ListGraph;
  13.440 +      //protected: 
  13.441 +    public: //for alpar
  13.442 +      EdgeIt(const ListGraph& G) {
  13.443 +	node_item* v=G._first_node;
  13.444 +	if (v) edge=v->_first_out_edge; else edge=0;
  13.445 +	while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
  13.446 +      }
  13.447 +    public:
  13.448 +      EdgeIt() : Edge() { }
  13.449 +      EdgeIt(const Invalid& i) : Edge(i) { }
  13.450 +    protected:
  13.451 +      EdgeIt(edge_item* _e) : Edge(_e) { }
  13.452 +      EdgeIt& operator++() { 
  13.453 +	node_item* v=edge->_tail;
  13.454 +	edge=edge->_next_out; 
  13.455 +	while (v && !edge) { v=v->_next_node; if (v) edge=v->_first_out_edge; }
  13.456 +	return *this;
  13.457 +      }
  13.458 +    };
  13.459 +    
  13.460 +    class OutEdgeIt : public Edge {
  13.461 +      friend class ListGraph;
  13.462 +      //node_item* v;
  13.463 +      //protected: 
  13.464 +    protected: //for alpar
  13.465 +      OutEdgeIt(const Node& _v) /*: v(_v.node)*/ { edge=_v.node->_first_out_edge; }
  13.466 +    public:
  13.467 +      OutEdgeIt() : Edge()/*, v(0)*/ { }
  13.468 +      OutEdgeIt(const Invalid& i) : Edge(i) { }
  13.469 +      OutEdgeIt(const ListGraph&, Node _v) /*: v(_v.node)*/ { edge=_v.node->_first_out_edge; }
  13.470 +    protected:
  13.471 +      OutEdgeIt& operator++() { edge=edge->_next_out; return *this; }
  13.472 +    protected:
  13.473 +      Node aNode() const { return Node(edge->_tail); }
  13.474 +      Node bNode() const { return Node(edge->_head); }
  13.475 +    };
  13.476 +    
  13.477 +    class InEdgeIt : public Edge {
  13.478 +      friend class ListGraph;
  13.479 +      //node_item* v;
  13.480 +      //protected:
  13.481 +    protected: //for alpar
  13.482 +      InEdgeIt(const Node& _v) /*: v(_v.node)*/ { edge=_v.node->_first_in_edge; }
  13.483 +    public:
  13.484 +      InEdgeIt() : Edge()/*, v(0)*/ { }
  13.485 +      InEdgeIt(const Invalid& i) : Edge(i) { }
  13.486 +      InEdgeIt(const ListGraph&, Node _v) /*: v(_v.node)*/ { edge=_v.node->_first_in_edge; }
  13.487 +    protected:
  13.488 +      InEdgeIt& operator++() { edge=edge->_next_in; return *this; }
  13.489 +    protected:
  13.490 +      Node aNode() const { return Node(edge->_head); }
  13.491 +      Node bNode() const { return Node(edge->_tail); }
  13.492 +    };
  13.493 +
  13.494 +    class SymEdgeIt : public Edge {
  13.495 +      friend class ListGraph;
  13.496 +      bool out_or_in; //1 iff out, 0 iff in
  13.497 +      //node_item* v;
  13.498 +      //protected:
  13.499 +    public: //for alpar
  13.500 +      SymEdgeIt(const Node& _v) /*: v(_v.node)*/ { 
  13.501 +	out_or_in=1;
  13.502 +	edge=_v.node->_first_out_edge; 
  13.503 +	if (!edge) { edge=_v.node->_first_in_edge; out_or_in=0; }
  13.504 +      }
  13.505 +    public:
  13.506 +      SymEdgeIt() : Edge() /*, v(0)*/ { }
  13.507 +      SymEdgeIt(const Invalid& i) : Edge(i) { }
  13.508 +      SymEdgeIt(const ListGraph&, Node _v) /*: v(_v.node)*/ { 
  13.509 +	out_or_in=1;
  13.510 +	edge=_v.node->_first_out_edge; 
  13.511 +	if (!edge) { edge=_v.node->_first_in_edge; out_or_in=0; }
  13.512 +      }
  13.513 +    protected:
  13.514 +      SymEdgeIt& operator++() { 
  13.515 +	if (out_or_in) { 
  13.516 +	  node_item* v=edge->_tail;
  13.517 +	  edge=edge->_next_out; 
  13.518 +	  if (!edge) { out_or_in=0; edge=v->_first_in_edge; }
  13.519 +	} else {
  13.520 +	  edge=edge->_next_in; 
  13.521 +	}
  13.522 +	return *this;
  13.523 +      }
  13.524 +    protected:
  13.525 +      Node aNode() const { 
  13.526 +	return (out_or_in) ? Node(edge->_tail) : Node(edge->_head); }
  13.527 +      Node bNode() const { 
  13.528 +	return (out_or_in) ? Node(edge->_head) : Node(edge->_tail); }
  13.529 +    };
  13.530 +
  13.531 +  };
  13.532 +
  13.533 +//   template< typename T >
  13.534 +//   T ListGraph::first() const { 
  13.535 +//     std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>();" << std::endl; 
  13.536 +//     return T(); 
  13.537 +//   }
  13.538 +
  13.539 +//   template<>
  13.540 +//   ListGraph::NodeIt ListGraph::first<ListGraph::NodeIt>() const { 
  13.541 +//     return firstNode(); 
  13.542 +//   }
  13.543 +
  13.544 +//   template<>
  13.545 +//   ListGraph::EdgeIt ListGraph::first<ListGraph::EdgeIt>() const { 
  13.546 +//     return firstEdge(); 
  13.547 +//   }
  13.548 +
  13.549 +//   template< typename T >
  13.550 +//   T ListGraph::first(ListGraph::Node v) const {
  13.551 +//     std::cerr << "Invalid use of template<typemane T> T ListGraph::first<T>(ListGRaph::Node);" << std::endl; 
  13.552 +//     return T(); 
  13.553 +//   } 
  13.554 +
  13.555 +//   template<>
  13.556 +//   ListGraph::OutEdgeIt ListGraph::first<ListGraph::OutEdgeIt>(const ListGraph::Node v) const { 
  13.557 +//     return firstOutEdge(v); 
  13.558 +//   }
  13.559 +
  13.560 +//   template<>
  13.561 +//   ListGraph::InEdgeIt ListGraph::first<ListGraph::InEdgeIt>(const ListGraph::Node v) const { 
  13.562 +//     return firstInEdge(v); 
  13.563 +//   }
  13.564 +
  13.565 +//   template<>
  13.566 +//   ListGraph::SymEdgeIt ListGraph::first<ListGraph::SymEdgeIt>(const ListGraph::Node v) const { 
  13.567 +//     return firstSymEdge(v); 
  13.568 +//   }
  13.569 +
  13.570 +
  13.571 +} //namespace hugo
  13.572 +
  13.573 +#endif //HUGO_LIST_GRAPH_H
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/work/marci/experiment/makefile	Sat Apr 03 17:26:46 2004 +0000
    14.3 @@ -0,0 +1,35 @@
    14.4 +INCLUDEDIRS ?= -I. -I../../../include -I..
    14.5 +CXXFLAGS = -g -O3 -W -Wall $(INCLUDEDIRS) -ansi -pedantic
    14.6 +
    14.7 +BINARIES ?= iterator_bfs_demo iterator_bfs_demo_1 edmonds_karp_demo edmonds_karp_demo_1
    14.8 +
    14.9 +# Hat, ez elismerem, hogy nagyon ronda, de mukodik minden altalam
   14.10 +# ismert rendszeren :-)  (Misi)
   14.11 +CXX := $(shell type -p g++-3.3 || type -p g++-3.2 || type -p g++-3.0 || type -p g++-3 || echo g++)
   14.12 +CC := $(CXX)
   14.13 +
   14.14 +
   14.15 +all: $(BINARIES)
   14.16 +
   14.17 +################
   14.18 +# Minden binarishoz egy sor, felsorolva, hogy mely object file-okbol
   14.19 +# all elo.
   14.20 +# Kiveve ha siman file.cc -> file  esetrol van szo, amikor is nem kell
   14.21 +# irni semmit.
   14.22 +
   14.23 +#proba: proba.o seged.o
   14.24 +
   14.25 +################
   14.26 +
   14.27 +
   14.28 +.depend dep depend:
   14.29 +	-$(CXX) $(INCLUDEDIRS) -M $(BINARIES:=.cc) > .depend #2>/dev/null
   14.30 +#	-$(CXX) $(CXXFLAGS) -M *.cc > .depend
   14.31 +
   14.32 +makefile: .depend
   14.33 +sinclude .depend
   14.34 +
   14.35 +clean:
   14.36 +	$(RM) *.o $(BINARIES) .depend
   14.37 +
   14.38 +.PHONY: all clean dep depend