src/hugo/graph_wrapper.h
changeset 792 147eb3a58706
parent 777 a82713ed19f3
child 838 51dcd224455c
equal deleted inserted replaced
28:5f5edb1e7ae5 29:6a891870210a
    98     GraphWrapper(Graph& _graph) : graph(&_graph) { }
    98     GraphWrapper(Graph& _graph) : graph(&_graph) { }
    99     GraphWrapper(const GraphWrapper<Graph>& gw) : graph(gw.graph) { }
    99     GraphWrapper(const GraphWrapper<Graph>& gw) : graph(gw.graph) { }
   100 //     Graph& getGraph() const { return *graph; }
   100 //     Graph& getGraph() const { return *graph; }
   101  
   101  
   102     typedef typename Graph::Node Node;
   102     typedef typename Graph::Node Node;
   103 //     class Node : public Graph::Node {
       
   104 //       friend class GraphWrapper<Graph>;
       
   105 //     public:
       
   106 //       Node() { }
       
   107 //       Node(const typename Graph::Node& _n) : Graph::Node(_n) { }
       
   108 //       // /// \bug construction throughrthr multiple levels should be 
       
   109 //       // /// handled better
       
   110 //       // Node(const typename ParentGraph::ParentGraph::Node& _n) : 
       
   111 //       // Graph::Node(_n) { }
       
   112 //       Node(const Invalid& i) : Graph::Node(i) { }
       
   113 //     };
       
   114     class NodeIt : public Node { 
   103     class NodeIt : public Node { 
   115       const GraphWrapper<Graph>* gw;
   104       const GraphWrapper<Graph>* gw;
   116       friend class GraphWrapper<Graph>;
   105       friend class GraphWrapper<Graph>;
   117      public:
   106      public:
   118       NodeIt() { }
   107       NodeIt() { }
   127 	  ++(typename Graph::NodeIt(*(gw->graph), *this));
   116 	  ++(typename Graph::NodeIt(*(gw->graph), *this));
   128 	return *this; 
   117 	return *this; 
   129       }
   118       }
   130     };
   119     };
   131     typedef typename Graph::Edge Edge;
   120     typedef typename Graph::Edge Edge;
   132 //     class Edge : public Graph::Edge {
       
   133 //       friend class GraphWrapper<Graph>;
       
   134 //     public:
       
   135 //       Edge() { }
       
   136 //       Edge(const typename Graph::Edge& _e) : Graph::Edge(_e) { }
       
   137 //       Edge(const Invalid& i) : Graph::Edge(i) { }
       
   138 //     };
       
   139     class OutEdgeIt : public Edge { 
   121     class OutEdgeIt : public Edge { 
   140       const GraphWrapper<Graph>* gw;
   122       const GraphWrapper<Graph>* gw;
   141       friend class GraphWrapper<Graph>;
   123       friend class GraphWrapper<Graph>;
   142      public:
   124      public:
   143       OutEdgeIt() { }
   125       OutEdgeIt() { }
   275     RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
   257     RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { }  
   276     RevGraphWrapper(const RevGraphWrapper<Graph>& gw) : Parent(gw) { }
   258     RevGraphWrapper(const RevGraphWrapper<Graph>& gw) : Parent(gw) { }
   277 
   259 
   278     typedef typename GraphWrapper<Graph>::Node Node;
   260     typedef typename GraphWrapper<Graph>::Node Node;
   279     typedef typename GraphWrapper<Graph>::Edge Edge;
   261     typedef typename GraphWrapper<Graph>::Edge Edge;
   280     //If Graph::OutEdgeIt is not defined
   262     //remark: OutEdgeIt and InEdgeIt cannot be typedef-ed to each other
   281     //and we do not want to use RevGraphWrapper::InEdgeIt,
   263     //because this does not work is some of them are not defined in the 
   282     //the typdef techinque does not work.
   264     //original graph. The problem with this is that typedef-ed stuff 
   283     //Unfortunately all the typedefs are instantiated in templates.
   265     //are instantiated in c++.
   284     //typedef typename GraphWrapper<Graph>::OutEdgeIt InEdgeIt;
       
   285     //typedef typename GraphWrapper<Graph>::InEdgeIt OutEdgeIt;
       
   286 
       
   287     class OutEdgeIt : public Edge { 
   266     class OutEdgeIt : public Edge { 
   288       const RevGraphWrapper<Graph>* gw;
   267       const RevGraphWrapper<Graph>* gw;
   289       friend class GraphWrapper<Graph>;
   268       friend class GraphWrapper<Graph>;
   290      public:
   269      public:
   291       OutEdgeIt() { }
   270       OutEdgeIt() { }
   380 		    EdgeFilterMap& _edge_filter_map) : 
   359 		    EdgeFilterMap& _edge_filter_map) : 
   381       GraphWrapper<Graph>(_graph), node_filter_map(&_node_filter_map), 
   360       GraphWrapper<Graph>(_graph), node_filter_map(&_node_filter_map), 
   382       edge_filter_map(&_edge_filter_map) { }  
   361       edge_filter_map(&_edge_filter_map) { }  
   383 
   362 
   384     typedef typename GraphWrapper<Graph>::Node Node;
   363     typedef typename GraphWrapper<Graph>::Node Node;
   385 //     class NodeIt { 
       
   386 //       friend class GraphWrapper<Graph>;
       
   387 //       friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
       
   388 //       typename Graph::NodeIt n;
       
   389 //      public:
       
   390 //       NodeIt() { }
       
   391 //       NodeIt(const typename Graph::NodeIt& _n) : n(_n) { }
       
   392 //       NodeIt(const Invalid& i) : n(i) { }
       
   393 //       NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _G) : 
       
   394 // 	n(*(_G.graph)) { 
       
   395 // 	while (_G.graph->valid(n) && !(*(_G.node_filter_map))[n]) 
       
   396 // 	  _G.graph->next(n);
       
   397 //       }
       
   398 //       operator Node() const { return Node(typename Graph::Node(n)); }
       
   399 //     };
       
   400     class NodeIt : public Node { 
   364     class NodeIt : public Node { 
   401       const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
   365       const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
   402       friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
   366       friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
   403     public:
   367     public:
   404       NodeIt() { }
   368       NodeIt() { }
   558     bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
   522     bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
   559 
   523 
   560     /// Returns true if \c n is hidden.
   524     /// Returns true if \c n is hidden.
   561     bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
   525     bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
   562 
   526 
   563     /// This is a linear time operation and works only if 
   527     /// \warning This is a linear time operation and works only if 
   564     /// NodeIt is defined.
   528     /// \c Graph::NodeIt is defined.
   565     int nodeNum() const { 
   529     int nodeNum() const { 
   566       int i=0;
   530       int i=0;
   567       NodeIt n;
   531       for (NodeIt n(*this); n!=INVALID; ++n) ++i;
   568       for (this->first(n); this->valid(n); this->next(n)) ++i;
       
   569       return i; 
   532       return i; 
   570     }
   533     }
   571 
   534 
   572     /// This is a linear time operation and works only if 
   535     /// \warning This is a linear time operation and works only if 
   573     /// EdgeIt is defined.
   536     /// \c Graph::EdgeIt is defined.
   574     int edgeNum() const { 
   537     int edgeNum() const { 
   575       int i=0;
   538       int i=0;
   576       EdgeIt e;
   539       for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
   577       for (this->first(e); this->valid(e); this->next(e)) ++i;
       
   578       return i; 
   540       return i; 
   579     }
   541     }
   580 
   542 
   581   };
   543   };
   582 
   544 
   687   };
   649   };
   688 
   650 
   689 
   651 
   690 
   652 
   691   ///\brief A wrapper for composing a subgraph of a 
   653   ///\brief A wrapper for composing a subgraph of a 
   692   /// bidirected graph composed from a directed one. 
   654   /// bidirected graph made from a directed one. 
   693   /// experimental, for fezso's sake.
       
   694   ///
   655   ///
   695   /// A wrapper for composing a subgraps of a 
   656   /// Suppose that for a directed graph $G=(V, A)$, 
   696   /// bidirected graph composed from a directed one. 
   657   /// two predicates on the edge-set, $forward_filter$, and $backward_filter$ 
   697   /// experimental, for fezso's sake.
   658   /// is given, and we are dealing with the directed graph
   698   /// A bidirected graph is composed over the directed one without physical 
   659   /// a $G'=(V, \{uv : uv\in A \mbox{ and } forward_filter(uv) \mbox{ is true}\}+\{vu : uv\in A \mbox{ and } backward_filter(uv) \mbox{ is true}\})$. 
   699   /// storage. As the oppositely directed edges are logically different ones 
   660   /// The purpose of writing + instead of union is because parallel 
   700   /// the maps are able to attach different values for them.
   661   /// edges can arose. 
       
   662   /// In other words, a subgraph of the bidirected graph obtained, which 
       
   663   /// is given by orienting the edges of the original graph in both directions.
       
   664   /// An example for such a construction is the \c RevGraphWrapper where the 
       
   665   /// forward_filter is everywhere false and the backward_filter is 
       
   666   /// everywhere true. We note that for sake of efficiency, 
       
   667   /// \c RevGraphWrapper is implemented in a different way. 
       
   668   /// But BidirGraphWrapper is obtained from 
       
   669   /// SubBidirGraphWrapper by considering everywhere true 
       
   670   /// predicates both forward_filter and backward_filter. 
       
   671   /// Finally, one of the most important applications of SubBidirGraphWrapper 
       
   672   /// is ResGraphWrapper, which stands for the residual graph in directed 
       
   673   /// flow and circulation problems. 
       
   674   /// As wrappers usually, the SubBidirGraphWrapper implements the 
       
   675   /// above mentioned graph structure without its physical storage, 
       
   676   /// that is the whole stuff eats constant memory. 
       
   677   /// As the oppositely directed edges are logical different, 
       
   678   /// the maps are able to attach different values for them. 
   701   template<typename Graph, 
   679   template<typename Graph, 
   702 	   typename ForwardFilterMap, typename BackwardFilterMap>
   680 	   typename ForwardFilterMap, typename BackwardFilterMap>
   703   class SubBidirGraphWrapper : public GraphWrapper<Graph> {
   681   class SubBidirGraphWrapper : public GraphWrapper<Graph> {
   704   public:
   682   public:
   705     typedef GraphWrapper<Graph> Parent; 
   683     typedef GraphWrapper<Graph> Parent; 
   706   protected:
   684   protected:
   707     ForwardFilterMap* forward_filter;
   685     ForwardFilterMap* forward_filter;
   708     BackwardFilterMap* backward_filter;
   686     BackwardFilterMap* backward_filter;
   709 
   687 
   710     SubBidirGraphWrapper() : GraphWrapper<Graph>()/*, 
   688     SubBidirGraphWrapper() : GraphWrapper<Graph>() { }
   711 						 capacity(0), flow(0)*/ { }
       
   712     void setForwardFilterMap(ForwardFilterMap& _forward_filter) {
   689     void setForwardFilterMap(ForwardFilterMap& _forward_filter) {
   713       forward_filter=&_forward_filter;
   690       forward_filter=&_forward_filter;
   714     }
   691     }
   715     void setBackwardFilterMap(BackwardFilterMap& _backward_filter) {
   692     void setBackwardFilterMap(BackwardFilterMap& _backward_filter) {
   716       backward_filter=&_backward_filter;
   693       backward_filter=&_backward_filter;
   731     class Edge; 
   708     class Edge; 
   732     class OutEdgeIt; 
   709     class OutEdgeIt; 
   733     friend class Edge; 
   710     friend class Edge; 
   734     friend class OutEdgeIt; 
   711     friend class OutEdgeIt; 
   735 
   712 
   736     //template<typename T> class NodeMap;    
       
   737     template<typename T> class EdgeMap;
   713     template<typename T> class EdgeMap;
   738 
   714 
   739     typedef typename GraphWrapper<Graph>::Node Node;
   715     typedef typename GraphWrapper<Graph>::Node Node;
   740     //typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
       
   741 
   716 
   742     typedef typename Graph::Edge GraphEdge;
   717     typedef typename Graph::Edge GraphEdge;
       
   718     /// SubBidirGraphWrapper<..., ..., ...>::Edge is inherited from 
       
   719     /// Graph::Edge. It contains an extra bool flag which shows if the 
       
   720     /// edge is the backward version of the original edge.
   743     class Edge : public Graph::Edge {
   721     class Edge : public Graph::Edge {
   744       friend class SubBidirGraphWrapper<Graph, 
   722       friend class SubBidirGraphWrapper<Graph, 
   745 					ForwardFilterMap, BackwardFilterMap>;
   723 					ForwardFilterMap, BackwardFilterMap>;
   746       ///\bug ez nem is kell
       
   747       //template<typename T> friend class NodeMap;
       
   748       template<typename T> friend class EdgeMap;
   724       template<typename T> friend class EdgeMap;
   749     protected:
   725     protected:
   750       bool backward; //true, iff backward
   726       bool backward; //true, iff backward
   751 //      typename Graph::Edge e;
       
   752     public:
   727     public:
   753       Edge() { }
   728       Edge() { }
   754       ///\bug =false kell-e? zsoltnak kell az addEdge miatt
   729       /// \todo =false is needed, or causes problems?
       
   730       /// If \c _backward is false, then we get an edge corresponding to the 
       
   731       /// original one, otherwise its oppositely directed pair is obtained.
   755       Edge(const typename Graph::Edge& e, bool _backward/*=false*/) : 
   732       Edge(const typename Graph::Edge& e, bool _backward/*=false*/) : 
   756 	Graph::Edge(e), backward(_backward) { }
   733 	Graph::Edge(e), backward(_backward) { }
   757       Edge(Invalid i) : Graph::Edge(i), backward(true) { }
   734       Edge(Invalid i) : Graph::Edge(i), backward(true) { }
   758 //the unique invalid iterator
   735 //the unique invalid iterator
   759 //       friend bool operator==(const Edge& u, const Edge& v) { 
   736 //       friend bool operator==(const Edge& u, const Edge& v) { 
   956 //       i=NodeIt(*this); return i;
   933 //       i=NodeIt(*this); return i;
   957 //     }
   934 //     }
   958     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
   935     OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
   959       i=OutEdgeIt(*this, p); return i;
   936       i=OutEdgeIt(*this, p); return i;
   960     }
   937     }
   961 //    FIXME not tested
       
   962     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
   938     InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
   963       i=InEdgeIt(*this, p); return i;
   939       i=InEdgeIt(*this, p); return i;
   964     }
   940     }
   965     EdgeIt& first(EdgeIt& i) const { 
   941     EdgeIt& first(EdgeIt& i) const { 
   966       i=EdgeIt(*this); return i;
   942       i=EdgeIt(*this); return i;
  1050       Edge f=e;
  1026       Edge f=e;
  1051       f.backward=!f.backward;
  1027       f.backward=!f.backward;
  1052       return f;
  1028       return f;
  1053     }
  1029     }
  1054 
  1030 
  1055 //    int nodeNum() const { return graph->nodeNum(); }
  1031     /// \warning This is a linear time operation and works only if 
  1056     //FIXME
  1032     /// \c Graph::EdgeIt is defined.
  1057     void edgeNum() const { }
  1033     int edgeNum() const { 
  1058     //int edgeNum() const { return graph->edgeNum(); }
  1034       int i=0;
  1059 
  1035       for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
  1060 
  1036       return i; 
  1061 //    int id(Node v) const { return graph->id(v); }
  1037     }
  1062 
       
  1063 //     bool valid(Node n) const { return GraphWrapper<Graph>::valid(n); }
       
  1064 //     bool valid(Edge e) const { 
       
  1065 //       return this->graph->valid(e);
       
  1066 // 	//return e.forward ? graph->valid(e.out) : graph->valid(e.in); 
       
  1067 //     }
       
  1068 
  1038 
  1069     bool forward(const Edge& e) const { return !e.backward; }
  1039     bool forward(const Edge& e) const { return !e.backward; }
  1070     bool backward(const Edge& e) const { return e.backward; }
  1040     bool backward(const Edge& e) const { return e.backward; }
  1071 
  1041 
  1072 //     void augment(const Edge& e, Number a) const {
       
  1073 //       if (!e.backward)  
       
  1074 // // 	flow->set(e.out, flow->get(e.out)+a);
       
  1075 // 	flow->set(e, (*flow)[e]+a);
       
  1076 //       else  
       
  1077 // // 	flow->set(e.in, flow->get(e.in)-a);
       
  1078 // 	flow->set(e, (*flow)[e]-a);
       
  1079 //     }
       
  1080 
       
  1081 //     bool enabled(const Edge& e) const { 
       
  1082 //       if (!e.backward) 
       
  1083 // //	return (capacity->get(e.out)-flow->get(e.out)); 
       
  1084 // 	//return ((*capacity)[e]-(*flow)[e]);
       
  1085 // 	return true;
       
  1086 //       else 
       
  1087 // //	return (flow->get(e.in)); 
       
  1088 // 	//return ((*flow)[e]); 
       
  1089 // 	return true;
       
  1090 //     }
       
  1091 
       
  1092 //     Number enabled(typename Graph::OutEdgeIt out) const { 
       
  1093 // //      return (capacity->get(out)-flow->get(out)); 
       
  1094 //       return ((*capacity)[out]-(*flow)[out]); 
       
  1095 //     }
       
  1096     
       
  1097 //     Number enabled(typename Graph::InEdgeIt in) const { 
       
  1098 // //      return (flow->get(in)); 
       
  1099 //       return ((*flow)[in]); 
       
  1100 //     }
       
  1101 
  1042 
  1102     template <typename T>
  1043     template <typename T>
       
  1044     /// \c SubBidirGraphWrapper<..., ..., ...>::EdgeMap contains two 
       
  1045     /// Graph::EdgeMap one for the forward edges and 
       
  1046     /// one for the backward edges.
  1103     class EdgeMap {
  1047     class EdgeMap {
  1104       typename Graph::template EdgeMap<T> forward_map, backward_map; 
  1048       typename Graph::template EdgeMap<T> forward_map, backward_map; 
  1105     public:
  1049     public:
  1106       typedef T ValueType;
  1050       typedef T ValueType;
  1107       typedef Edge KeyType;
  1051       typedef Edge KeyType;
  1111       EdgeMap(const SubBidirGraphWrapper<Graph, 
  1055       EdgeMap(const SubBidirGraphWrapper<Graph, 
  1112 	      ForwardFilterMap, BackwardFilterMap>& g, T a) : 
  1056 	      ForwardFilterMap, BackwardFilterMap>& g, T a) : 
  1113 	forward_map(*(g.graph), a), backward_map(*(g.graph), a) { }
  1057 	forward_map(*(g.graph), a), backward_map(*(g.graph), a) { }
  1114       void set(Edge e, T a) { 
  1058       void set(Edge e, T a) { 
  1115 	if (!e.backward) 
  1059 	if (!e.backward) 
  1116 	  forward_map.set(e/*.out*/, a); 
  1060 	  forward_map.set(e, a); 
  1117 	else 
  1061 	else 
  1118 	  backward_map.set(e/*.in*/, a); 
  1062 	  backward_map.set(e, a); 
  1119       }
  1063       }
  1120       T operator[](Edge e) const { 
  1064       T operator[](Edge e) const { 
  1121 	if (!e.backward) 
  1065 	if (!e.backward) 
  1122 	  return forward_map[e/*.out*/]; 
  1066 	  return forward_map[e]; 
  1123 	else 
  1067 	else 
  1124 	  return backward_map[e/*.in*/]; 
  1068 	  return backward_map[e]; 
  1125       }
  1069       }
  1126       void update() { 
  1070       void update() { 
  1127 	forward_map.update(); 
  1071 	forward_map.update(); 
  1128 	backward_map.update();
  1072 	backward_map.update();
  1129       }
  1073       }
  1135 //       }
  1079 //       }
  1136     };
  1080     };
  1137   };
  1081   };
  1138 
  1082 
  1139 
  1083 
  1140 
       
  1141   ///\brief A wrapper for composing bidirected graph from a directed one. 
  1084   ///\brief A wrapper for composing bidirected graph from a directed one. 
  1142   /// experimental, for fezso's sake.
       
  1143   ///
  1085   ///
  1144   /// A wrapper for composing bidirected graph from a directed one. 
  1086   /// A wrapper for composing bidirected graph from a directed one. 
  1145   /// experimental, for fezso's sake.
       
  1146   /// A bidirected graph is composed over the directed one without physical 
  1087   /// A bidirected graph is composed over the directed one without physical 
  1147   /// storage. As the oppositely directed edges are logically different ones 
  1088   /// storage. As the oppositely directed edges are logically different ones 
  1148   /// the maps are able to attach different values for them.
  1089   /// the maps are able to attach different values for them.
  1149   template<typename Graph>
  1090   template<typename Graph>
  1150   class BidirGraphWrapper : 
  1091   class BidirGraphWrapper : 
  1157       Graph, 
  1098       Graph, 
  1158       ConstMap<typename Graph::Edge, bool>, 
  1099       ConstMap<typename Graph::Edge, bool>, 
  1159       ConstMap<typename Graph::Edge, bool> > Parent; 
  1100       ConstMap<typename Graph::Edge, bool> > Parent; 
  1160   protected:
  1101   protected:
  1161     ConstMap<typename Graph::Edge, bool> cm;
  1102     ConstMap<typename Graph::Edge, bool> cm;
  1162     //const CapacityMap* capacity;
       
  1163     //FlowMap* flow;
       
  1164 
  1103 
  1165     BidirGraphWrapper() : Parent(), cm(true) { 
  1104     BidirGraphWrapper() : Parent(), cm(true) { 
  1166       Parent::setForwardFilterMap(cm);
  1105       Parent::setForwardFilterMap(cm);
  1167       Parent::setBackwardFilterMap(cm);
  1106       Parent::setBackwardFilterMap(cm);
  1168     }
  1107     }
  1169 //     void setCapacityMap(const CapacityMap& _capacity) {
  1108   public:
  1170 //       capacity=&_capacity;
       
  1171 //     }
       
  1172 //     void setFlowMap(FlowMap& _flow) {
       
  1173 //       flow=&_flow;
       
  1174 //     }
       
  1175 
       
  1176   public:
       
  1177 
       
  1178     BidirGraphWrapper(Graph& _graph) : Parent() { 
  1109     BidirGraphWrapper(Graph& _graph) : Parent() { 
  1179       Parent::setGraph(_graph);
  1110       Parent::setGraph(_graph);
  1180       Parent::setForwardFilterMap(cm);
  1111       Parent::setForwardFilterMap(cm);
  1181       Parent::setBackwardFilterMap(cm);
  1112       Parent::setBackwardFilterMap(cm);
  1182     }
  1113     }
  1186     }
  1117     }
  1187   };
  1118   };
  1188 
  1119 
  1189 
  1120 
  1190 
  1121 
  1191 
  1122   // this is a direct implementation of the bidirected-graph wrapper. 
       
  1123   // in early hugo, it was implemented that way.
  1192   template<typename Graph>
  1124   template<typename Graph>
  1193   class OldBidirGraphWrapper : public GraphWrapper<Graph> {
  1125   class OldBidirGraphWrapper : public GraphWrapper<Graph> {
  1194   public:
  1126   public:
  1195     typedef GraphWrapper<Graph> Parent; 
  1127     typedef GraphWrapper<Graph> Parent; 
  1196   protected:
  1128   protected:
  1197     //const CapacityMap* capacity;
  1129     OldBidirGraphWrapper() : GraphWrapper<Graph>() { }
  1198     //FlowMap* flow;
  1130 
  1199 
  1131   public:
  1200     OldBidirGraphWrapper() : GraphWrapper<Graph>()/*, 
  1132 
  1201 						 capacity(0), flow(0)*/ { }
  1133     OldBidirGraphWrapper(Graph& _graph) : 
  1202 //     void setCapacityMap(const CapacityMap& _capacity) {
  1134       GraphWrapper<Graph>(_graph) { }
  1203 //       capacity=&_capacity;
       
  1204 //     }
       
  1205 //     void setFlowMap(FlowMap& _flow) {
       
  1206 //       flow=&_flow;
       
  1207 //     }
       
  1208 
       
  1209   public:
       
  1210 
       
  1211     OldBidirGraphWrapper(Graph& _graph/*, const CapacityMap& _capacity, 
       
  1212 				     FlowMap& _flow*/) : 
       
  1213       GraphWrapper<Graph>(_graph)/*, capacity(&_capacity), flow(&_flow)*/ { }
       
  1214 
  1135 
  1215     class Edge; 
  1136     class Edge; 
  1216     class OutEdgeIt; 
  1137     class OutEdgeIt; 
  1217     friend class Edge; 
  1138     friend class Edge; 
  1218     friend class OutEdgeIt; 
  1139     friend class OutEdgeIt; 
  1457     }
  1378     }
  1458 
  1379 
  1459     bool forward(const Edge& e) const { return !e.backward; }
  1380     bool forward(const Edge& e) const { return !e.backward; }
  1460     bool backward(const Edge& e) const { return e.backward; }
  1381     bool backward(const Edge& e) const { return e.backward; }
  1461 
  1382 
  1462 //     void augment(const Edge& e, Number a) const {
       
  1463 //       if (!e.backward)  
       
  1464 // // 	flow->set(e.out, flow->get(e.out)+a);
       
  1465 // 	flow->set(e, (*flow)[e]+a);
       
  1466 //       else  
       
  1467 // // 	flow->set(e.in, flow->get(e.in)-a);
       
  1468 // 	flow->set(e, (*flow)[e]-a);
       
  1469 //     }
       
  1470 
       
  1471     bool enabled(const Edge& e) const { 
  1383     bool enabled(const Edge& e) const { 
  1472       if (!e.backward) 
  1384       if (!e.backward) 
  1473 //	return (capacity->get(e.out)-flow->get(e.out)); 
  1385 //	return (capacity->get(e.out)-flow->get(e.out)); 
  1474 	//return ((*capacity)[e]-(*flow)[e]);
  1386 	//return ((*capacity)[e]-(*flow)[e]);
  1475 	return true;
  1387 	return true;
  1660 	return ((*flow)[e]); 
  1572 	return ((*flow)[e]); 
  1661     }
  1573     }
  1662 
  1574 
  1663     /// \brief Residual capacity map.
  1575     /// \brief Residual capacity map.
  1664     ///
  1576     ///
  1665     /// In generic residual graphs the residual capacity can be obtained as a map.
  1577     /// In generic residual graphs the residual capacity can be obtained as a map. Not tested.
  1666     class ResCap {
  1578     class ResCap {
  1667     protected:
  1579     protected:
  1668       const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>* res_graph;
  1580       const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>* res_graph;
  1669     public:
  1581     public:
  1670       typedef Number ValueType;
  1582       typedef Number ValueType;
  2005 
  1917 
  2006 
  1918 
  2007 
  1919 
  2008   /// For blocking flows.
  1920   /// For blocking flows.
  2009 
  1921 
  2010   /// This graph wrapper is used for Dinits blocking flow computations.
  1922   /// This graph wrapper is used for on-the-fly 
       
  1923   /// Dinits blocking flow computations.
  2011   /// For each node, an out-edge is stored which is used when the 
  1924   /// For each node, an out-edge is stored which is used when the 
  2012   /// \code 
  1925   /// \code 
  2013   /// OutEdgeIt& first(OutEdgeIt&, const Node&)
  1926   /// OutEdgeIt& first(OutEdgeIt&, const Node&)
  2014   /// \endcode
  1927   /// \endcode
  2015   /// is called. 
  1928   /// is called. 
  2016   ///
  1929   ///
  2017   ///\author Marton Makai
  1930   /// \author Marton Makai
  2018   template<typename Graph, typename FirstOutEdgesMap>
  1931   template<typename Graph, typename FirstOutEdgesMap>
  2019   class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
  1932   class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
  2020   public:
  1933   public:
  2021     typedef GraphWrapper<Graph> Parent; 
  1934     typedef GraphWrapper<Graph> Parent; 
  2022   protected:
  1935   protected:
  2025     ErasingFirstGraphWrapper(Graph& _graph, 
  1938     ErasingFirstGraphWrapper(Graph& _graph, 
  2026 			     FirstOutEdgesMap& _first_out_edges) : 
  1939 			     FirstOutEdgesMap& _first_out_edges) : 
  2027       GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { }  
  1940       GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { }  
  2028 
  1941 
  2029     typedef typename GraphWrapper<Graph>::Node Node;
  1942     typedef typename GraphWrapper<Graph>::Node Node;
  2030 //     class NodeIt { 
       
  2031 //       friend class GraphWrapper<Graph>;
       
  2032 //       friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
       
  2033 //       typename Graph::NodeIt n;
       
  2034 //      public:
       
  2035 //       NodeIt() { }
       
  2036 //       NodeIt(const typename Graph::NodeIt& _n) : n(_n) { }
       
  2037 //       NodeIt(const Invalid& i) : n(i) { }
       
  2038 //       NodeIt(const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>& _G) : 
       
  2039 // 	n(*(_G.graph)) { }
       
  2040 //       operator Node() const { return Node(typename Graph::Node(n)); }
       
  2041 //     };
       
  2042     typedef typename GraphWrapper<Graph>::Edge Edge;
  1943     typedef typename GraphWrapper<Graph>::Edge Edge;
  2043     class OutEdgeIt : public Edge { 
  1944     class OutEdgeIt : public Edge { 
  2044       friend class GraphWrapper<Graph>;
  1945       friend class GraphWrapper<Graph>;
  2045       friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
  1946       friend class ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>;
  2046       const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>* gw;
  1947       const ErasingFirstGraphWrapper<Graph, FirstOutEdgesMap>* gw;