src/lemon/graph_adaptor.h
changeset 1401 9588dcef6793
parent 1383 79b68a337f9f
child 1425 f3717c08e2be
equal deleted inserted replaced
25:7826d4e0f002 0:43cedfab4b92
     1 /* -*- C++ -*-
     1 /* -*- C++ -*-
     2  * src/lemon/graph_wrapper.h - Part of LEMON, a generic C++ optimization library
     2  * src/lemon/graph_adaptor.h - Part of LEMON, a generic C++ optimization library
     3  *
     3  *
     4  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     4  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     5  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     5  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     6  *
     6  *
     7  * Permission to use, modify and distribute this software is granted
     7  * Permission to use, modify and distribute this software is granted
    12  * express or implied, and with no claim as to its suitability for any
    12  * express or implied, and with no claim as to its suitability for any
    13  * purpose.
    13  * purpose.
    14  *
    14  *
    15  */
    15  */
    16 
    16 
    17 #ifndef LEMON_GRAPH_WRAPPER_H
    17 #ifndef LEMON_GRAPH_ADAPTOR_H
    18 #define LEMON_GRAPH_WRAPPER_H
    18 #define LEMON_GRAPH_ADAPTOR_H
    19 
    19 
    20 ///\ingroup gwrappers
    20 ///\ingroup graph_adaptors
    21 ///\file
    21 ///\file
    22 ///\brief Several graph wrappers.
    22 ///\brief Several graph adaptors.
    23 ///
    23 ///
    24 ///This file contains several useful graph wrapper functions.
    24 ///This file contains several useful graph adaptor functions.
    25 ///
    25 ///
    26 ///\author Marton Makai
    26 ///\author Marton Makai
    27 
    27 
    28 #include <lemon/invalid.h>
    28 #include <lemon/invalid.h>
    29 #include <lemon/maps.h>
    29 #include <lemon/maps.h>
    31 #include <lemon/bits/undir_graph_extender.h>
    31 #include <lemon/bits/undir_graph_extender.h>
    32 #include <iostream>
    32 #include <iostream>
    33 
    33 
    34 namespace lemon {
    34 namespace lemon {
    35 
    35 
    36   // Graph wrappers
    36   // Graph adaptors
    37 
    37 
    38   /*!
    38   /*!
    39     \addtogroup gwrappers
    39     \addtogroup graph_adaptors
    40     @{
    40     @{
    41    */
    41    */
    42 
    42 
    43   /*! 
    43   /*! 
    44     Base type for the Graph Wrappers
    44     Base type for the Graph Adaptors
    45     
    45     
    46     \warning Graph wrappers are in even more experimental state than the other
    46     \warning Graph adaptors are in even more experimental state than the other
    47     parts of the lib. Use them at you own risk.
    47     parts of the lib. Use them at you own risk.
    48     
    48     
    49     This is the base type for most of LEMON graph wrappers. 
    49     This is the base type for most of LEMON graph adaptors. 
    50     This class implements a trivial graph wrapper i.e. it only wraps the 
    50     This class implements a trivial graph adaptor i.e. it only wraps the 
    51     functions and types of the graph. The purpose of this class is to 
    51     functions and types of the graph. The purpose of this class is to 
    52     make easier implementing graph wrappers. E.g. if a wrapper is 
    52     make easier implementing graph adaptors. E.g. if an adaptor is 
    53     considered which differs from the wrapped graph only in some of its 
    53     considered which differs from the wrapped graph only in some of its 
    54     functions or types, then it can be derived from GraphWrapper, and only the 
    54     functions or types, then it can be derived from GraphAdaptor, and only the 
    55     differences should be implemented.
    55     differences should be implemented.
    56   
    56   
    57     \author Marton Makai 
    57     \author Marton Makai 
    58   */
    58   */
    59   template<typename _Graph>
    59   template<typename _Graph>
    60   class GraphWrapperBase {
    60   class GraphAdaptorBase {
    61   public:
    61   public:
    62     typedef _Graph Graph;
    62     typedef _Graph Graph;
    63     /// \todo Is it needed?
    63     /// \todo Is it needed?
    64     typedef Graph BaseGraph;
    64     typedef Graph BaseGraph;
    65     typedef Graph ParentGraph;
    65     typedef Graph ParentGraph;
    66 
    66 
    67   protected:
    67   protected:
    68     Graph* graph;
    68     Graph* graph;
    69     GraphWrapperBase() : graph(0) { }
    69     GraphAdaptorBase() : graph(0) { }
    70     void setGraph(Graph& _graph) { graph=&_graph; }
    70     void setGraph(Graph& _graph) { graph=&_graph; }
    71 
    71 
    72   public:
    72   public:
    73     GraphWrapperBase(Graph& _graph) : graph(&_graph) { }
    73     GraphAdaptorBase(Graph& _graph) : graph(&_graph) { }
    74  
    74  
    75     typedef typename Graph::Node Node;
    75     typedef typename Graph::Node Node;
    76     typedef typename Graph::Edge Edge;
    76     typedef typename Graph::Edge Edge;
    77    
    77    
    78     void first(Node& i) const { graph->first(i); }
    78     void first(Node& i) const { graph->first(i); }
   110 
   110 
   111     template <typename _Value>
   111     template <typename _Value>
   112     class NodeMap : public _Graph::template NodeMap<_Value> {
   112     class NodeMap : public _Graph::template NodeMap<_Value> {
   113     public:
   113     public:
   114       typedef typename _Graph::template NodeMap<_Value> Parent;
   114       typedef typename _Graph::template NodeMap<_Value> Parent;
   115       NodeMap(const GraphWrapperBase<_Graph>& gw) : Parent(*gw.graph) { }
   115       NodeMap(const GraphAdaptorBase<_Graph>& gw) : Parent(*gw.graph) { }
   116       NodeMap(const GraphWrapperBase<_Graph>& gw, const _Value& value)
   116       NodeMap(const GraphAdaptorBase<_Graph>& gw, const _Value& value)
   117       : Parent(*gw.graph, value) { }
   117       : Parent(*gw.graph, value) { }
   118     };
   118     };
   119 
   119 
   120     template <typename _Value>
   120     template <typename _Value>
   121     class EdgeMap : public _Graph::template EdgeMap<_Value> {
   121     class EdgeMap : public _Graph::template EdgeMap<_Value> {
   122     public:
   122     public:
   123       typedef typename _Graph::template EdgeMap<_Value> Parent;
   123       typedef typename _Graph::template EdgeMap<_Value> Parent;
   124       EdgeMap(const GraphWrapperBase<_Graph>& gw) : Parent(*gw.graph) { }
   124       EdgeMap(const GraphAdaptorBase<_Graph>& gw) : Parent(*gw.graph) { }
   125       EdgeMap(const GraphWrapperBase<_Graph>& gw, const _Value& value)
   125       EdgeMap(const GraphAdaptorBase<_Graph>& gw, const _Value& value)
   126       : Parent(*gw.graph, value) { }
   126       : Parent(*gw.graph, value) { }
   127     };
   127     };
   128 
   128 
   129   };
   129   };
   130 
   130 
   131   template <typename _Graph>
   131   template <typename _Graph>
   132   class GraphWrapper :
   132   class GraphAdaptor :
   133     public IterableGraphExtender<GraphWrapperBase<_Graph> > { 
   133     public IterableGraphExtender<GraphAdaptorBase<_Graph> > { 
   134   public:
   134   public:
   135     typedef _Graph Graph;
   135     typedef _Graph Graph;
   136     typedef IterableGraphExtender<GraphWrapperBase<_Graph> > Parent;
   136     typedef IterableGraphExtender<GraphAdaptorBase<_Graph> > Parent;
   137   protected:
   137   protected:
   138     GraphWrapper() : Parent() { }
   138     GraphAdaptor() : Parent() { }
   139 
   139 
   140   public:
   140   public:
   141     GraphWrapper(Graph& _graph) { setGraph(_graph); }
   141     GraphAdaptor(Graph& _graph) { setGraph(_graph); }
   142   };
   142   };
   143 
   143 
   144   template <typename _Graph>
   144   template <typename _Graph>
   145   class RevGraphWrapperBase : public GraphWrapperBase<_Graph> {
   145   class RevGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
   146   public:
   146   public:
   147     typedef _Graph Graph;
   147     typedef _Graph Graph;
   148     typedef GraphWrapperBase<_Graph> Parent;
   148     typedef GraphAdaptorBase<_Graph> Parent;
   149   protected:
   149   protected:
   150     RevGraphWrapperBase() : Parent() { }
   150     RevGraphAdaptorBase() : Parent() { }
   151   public:
   151   public:
   152     typedef typename Parent::Node Node;
   152     typedef typename Parent::Node Node;
   153     typedef typename Parent::Edge Edge;
   153     typedef typename Parent::Edge Edge;
   154 
   154 
   155     //    using Parent::first;
   155     //    using Parent::first;
   163     Node source(const Edge& e) const { return Parent::target(e); }
   163     Node source(const Edge& e) const { return Parent::target(e); }
   164     Node target(const Edge& e) const { return Parent::source(e); }
   164     Node target(const Edge& e) const { return Parent::source(e); }
   165   };
   165   };
   166     
   166     
   167 
   167 
   168   /// A graph wrapper which reverses the orientation of the edges.
   168   /// A graph adaptor which reverses the orientation of the edges.
   169 
   169 
   170   ///\warning Graph wrappers are in even more experimental state than the other
   170   ///\warning Graph adaptors are in even more experimental state than the other
   171   ///parts of the lib. Use them at you own risk.
   171   ///parts of the lib. Use them at you own risk.
   172   ///
   172   ///
   173   /// Let \f$G=(V, A)\f$ be a directed graph and 
   173   /// Let \f$G=(V, A)\f$ be a directed graph and 
   174   /// suppose that a graph instange \c g of type 
   174   /// suppose that a graph instange \c g of type 
   175   /// \c ListGraph implements \f$G\f$.
   175   /// \c ListGraph implements \f$G\f$.
   177   /// ListGraph g;
   177   /// ListGraph g;
   178   /// \endcode
   178   /// \endcode
   179   /// For each directed edge 
   179   /// For each directed edge 
   180   /// \f$e\in A\f$, let \f$\bar e\f$ denote the edge obtained by 
   180   /// \f$e\in A\f$, let \f$\bar e\f$ denote the edge obtained by 
   181   /// reversing its orientation. 
   181   /// reversing its orientation. 
   182   /// Then RevGraphWrapper implements the graph structure with node-set 
   182   /// Then RevGraphAdaptor implements the graph structure with node-set 
   183   /// \f$V\f$ and edge-set 
   183   /// \f$V\f$ and edge-set 
   184   /// \f$\{\bar e : e\in A \}\f$, i.e. the graph obtained from \f$G\f$ be 
   184   /// \f$\{\bar e : e\in A \}\f$, i.e. the graph obtained from \f$G\f$ be 
   185   /// reversing the orientation of its edges. The following code shows how 
   185   /// reversing the orientation of its edges. The following code shows how 
   186   /// such an instance can be constructed.
   186   /// such an instance can be constructed.
   187   /// \code
   187   /// \code
   188   /// RevGraphWrapper<ListGraph> gw(g);
   188   /// RevGraphAdaptor<ListGraph> gw(g);
   189   /// \endcode
   189   /// \endcode
   190   ///\author Marton Makai
   190   ///\author Marton Makai
   191   template<typename _Graph>
   191   template<typename _Graph>
   192   class RevGraphWrapper : 
   192   class RevGraphAdaptor : 
   193     public IterableGraphExtender<RevGraphWrapperBase<_Graph> > {
   193     public IterableGraphExtender<RevGraphAdaptorBase<_Graph> > {
   194   public:
   194   public:
   195     typedef _Graph Graph;
   195     typedef _Graph Graph;
   196     typedef IterableGraphExtender<
   196     typedef IterableGraphExtender<
   197       RevGraphWrapperBase<_Graph> > Parent;
   197       RevGraphAdaptorBase<_Graph> > Parent;
   198   protected:
   198   protected:
   199     RevGraphWrapper() { }
   199     RevGraphAdaptor() { }
   200   public:
   200   public:
   201     RevGraphWrapper(_Graph& _graph) { setGraph(_graph); }
   201     RevGraphAdaptor(_Graph& _graph) { setGraph(_graph); }
   202   };
   202   };
   203 
   203 
   204   
   204   
   205   template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
   205   template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
   206   class SubGraphWrapperBase : public GraphWrapperBase<_Graph> {
   206   class SubGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
   207   public:
   207   public:
   208     typedef _Graph Graph;
   208     typedef _Graph Graph;
   209     typedef GraphWrapperBase<_Graph> Parent;
   209     typedef GraphAdaptorBase<_Graph> Parent;
   210   protected:
   210   protected:
   211     NodeFilterMap* node_filter_map;
   211     NodeFilterMap* node_filter_map;
   212     EdgeFilterMap* edge_filter_map;
   212     EdgeFilterMap* edge_filter_map;
   213     SubGraphWrapperBase() : Parent(), 
   213     SubGraphAdaptorBase() : Parent(), 
   214 			    node_filter_map(0), edge_filter_map(0) { }
   214 			    node_filter_map(0), edge_filter_map(0) { }
   215 
   215 
   216     void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
   216     void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
   217       node_filter_map=&_node_filter_map;
   217       node_filter_map=&_node_filter_map;
   218     }
   218     }
   219     void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
   219     void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
   220       edge_filter_map=&_edge_filter_map;
   220       edge_filter_map=&_edge_filter_map;
   221     }
   221     }
   222 
   222 
   223   public:
   223   public:
   224 //     SubGraphWrapperBase(Graph& _graph, 
   224 //     SubGraphAdaptorBase(Graph& _graph, 
   225 // 			NodeFilterMap& _node_filter_map, 
   225 // 			NodeFilterMap& _node_filter_map, 
   226 // 			EdgeFilterMap& _edge_filter_map) : 
   226 // 			EdgeFilterMap& _edge_filter_map) : 
   227 //       Parent(&_graph), 
   227 //       Parent(&_graph), 
   228 //       node_filter_map(&node_filter_map), 
   228 //       node_filter_map(&node_filter_map), 
   229 //       edge_filter_map(&edge_filter_map) { }
   229 //       edge_filter_map(&edge_filter_map) { }
   312     }
   312     }
   313 
   313 
   314 
   314 
   315   };
   315   };
   316 
   316 
   317   /*! \brief A graph wrapper for hiding nodes and edges from a graph.
   317   /*! \brief A graph adaptor for hiding nodes and edges from a graph.
   318     
   318     
   319   \warning Graph wrappers are in even more experimental state than the other
   319   \warning Graph adaptors are in even more experimental state than the other
   320   parts of the lib. Use them at you own risk.
   320   parts of the lib. Use them at you own risk.
   321   
   321   
   322   SubGraphWrapper shows the graph with filtered node-set and 
   322   SubGraphAdaptor shows the graph with filtered node-set and 
   323   edge-set. 
   323   edge-set. 
   324   Let \f$G=(V, A)\f$ be a directed graph 
   324   Let \f$G=(V, A)\f$ be a directed graph 
   325   and suppose that the graph instance \c g of type ListGraph implements 
   325   and suppose that the graph instance \c g of type ListGraph implements 
   326   \f$G\f$. 
   326   \f$G\f$. 
   327   Let moreover \f$b_V\f$ and 
   327   Let moreover \f$b_V\f$ and 
   328   \f$b_A\f$ be bool-valued functions resp. on the node-set and edge-set. 
   328   \f$b_A\f$ be bool-valued functions resp. on the node-set and edge-set. 
   329   SubGraphWrapper<...>::NodeIt iterates 
   329   SubGraphAdaptor<...>::NodeIt iterates 
   330   on the node-set \f$\{v\in V : b_V(v)=true\}\f$ and 
   330   on the node-set \f$\{v\in V : b_V(v)=true\}\f$ and 
   331   SubGraphWrapper<...>::EdgeIt iterates 
   331   SubGraphAdaptor<...>::EdgeIt iterates 
   332   on the edge-set \f$\{e\in A : b_A(e)=true\}\f$. Similarly, 
   332   on the edge-set \f$\{e\in A : b_A(e)=true\}\f$. Similarly, 
   333   SubGraphWrapper<...>::OutEdgeIt and SubGraphWrapper<...>::InEdgeIt iterates 
   333   SubGraphAdaptor<...>::OutEdgeIt and SubGraphAdaptor<...>::InEdgeIt iterates 
   334   only on edges leaving and entering a specific node which have true value.
   334   only on edges leaving and entering a specific node which have true value.
   335 
   335 
   336   We have to note that this does not mean that an 
   336   We have to note that this does not mean that an 
   337   induced subgraph is obtained, the node-iterator cares only the filter 
   337   induced subgraph is obtained, the node-iterator cares only the filter 
   338   on the node-set, and the edge-iterators care only the filter on the 
   338   on the node-set, and the edge-iterators care only the filter on the 
   348   Node f=g.addEdge(v, u); //edge of id 1
   348   Node f=g.addEdge(v, u); //edge of id 1
   349   Graph::NodeMap<bool> nm(g, true);
   349   Graph::NodeMap<bool> nm(g, true);
   350   nm.set(u, false);
   350   nm.set(u, false);
   351   Graph::EdgeMap<bool> em(g, true);
   351   Graph::EdgeMap<bool> em(g, true);
   352   em.set(e, false);
   352   em.set(e, false);
   353   typedef SubGraphWrapper<Graph, Graph::NodeMap<bool>, Graph::EdgeMap<bool> > SubGW;
   353   typedef SubGraphAdaptor<Graph, Graph::NodeMap<bool>, Graph::EdgeMap<bool> > SubGW;
   354   SubGW gw(g, nm, em);
   354   SubGW gw(g, nm, em);
   355   for (SubGW::NodeIt n(gw); n!=INVALID; ++n) std::cout << g.id(n) << std::endl;
   355   for (SubGW::NodeIt n(gw); n!=INVALID; ++n) std::cout << g.id(n) << std::endl;
   356   std::cout << ":-)" << std::endl;
   356   std::cout << ":-)" << std::endl;
   357   for (SubGW::EdgeIt e(gw); e!=INVALID; ++e) std::cout << g.id(e) << std::endl;
   357   for (SubGW::EdgeIt e(gw); e!=INVALID; ++e) std::cout << g.id(e) << std::endl;
   358   \endcode
   358   \endcode
   363   1
   363   1
   364   \endcode
   364   \endcode
   365   Note that \c n is of type \c SubGW::NodeIt, but it can be converted to
   365   Note that \c n is of type \c SubGW::NodeIt, but it can be converted to
   366   \c Graph::Node that is why \c g.id(n) can be applied.
   366   \c Graph::Node that is why \c g.id(n) can be applied.
   367 
   367 
   368   For other examples see also the documentation of NodeSubGraphWrapper and 
   368   For other examples see also the documentation of NodeSubGraphAdaptor and 
   369   EdgeSubGraphWrapper.
   369   EdgeSubGraphAdaptor.
   370 
   370 
   371   \author Marton Makai
   371   \author Marton Makai
   372   */
   372   */
   373   template<typename _Graph, typename NodeFilterMap, 
   373   template<typename _Graph, typename NodeFilterMap, 
   374 	   typename EdgeFilterMap>
   374 	   typename EdgeFilterMap>
   375   class SubGraphWrapper : 
   375   class SubGraphAdaptor : 
   376     public IterableGraphExtender<
   376     public IterableGraphExtender<
   377     SubGraphWrapperBase<_Graph, NodeFilterMap, EdgeFilterMap> > {
   377     SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap> > {
   378   public:
   378   public:
   379     typedef _Graph Graph;
   379     typedef _Graph Graph;
   380     typedef IterableGraphExtender<
   380     typedef IterableGraphExtender<
   381       SubGraphWrapperBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
   381       SubGraphAdaptorBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
   382   protected:
   382   protected:
   383     SubGraphWrapper() { }
   383     SubGraphAdaptor() { }
   384   public:
   384   public:
   385     SubGraphWrapper(_Graph& _graph, NodeFilterMap& _node_filter_map, 
   385     SubGraphAdaptor(_Graph& _graph, NodeFilterMap& _node_filter_map, 
   386 		    EdgeFilterMap& _edge_filter_map) { 
   386 		    EdgeFilterMap& _edge_filter_map) { 
   387       setGraph(_graph);
   387       setGraph(_graph);
   388       setNodeFilterMap(_node_filter_map);
   388       setNodeFilterMap(_node_filter_map);
   389       setEdgeFilterMap(_edge_filter_map);
   389       setEdgeFilterMap(_edge_filter_map);
   390     }
   390     }
   391   };
   391   };
   392 
   392 
   393 
   393 
   394 
   394 
   395   /*! \brief A wrapper for hiding nodes from a graph.
   395   /*! \brief An adaptor for hiding nodes from a graph.
   396 
   396 
   397   \warning Graph wrappers are in even more experimental state than the other
   397   \warning Graph adaptors are in even more experimental state than the other
   398   parts of the lib. Use them at you own risk.
   398   parts of the lib. Use them at you own risk.
   399   
   399   
   400   A wrapper for hiding nodes from a graph.
   400   An adaptor for hiding nodes from a graph.
   401   This wrapper specializes SubGraphWrapper in the way that only the node-set 
   401   This adaptor specializes SubGraphAdaptor in the way that only the node-set 
   402   can be filtered. Note that this does not mean of considering induced 
   402   can be filtered. Note that this does not mean of considering induced 
   403   subgraph, the edge-iterators consider the original edge-set.
   403   subgraph, the edge-iterators consider the original edge-set.
   404   \author Marton Makai
   404   \author Marton Makai
   405   */
   405   */
   406   template<typename Graph, typename NodeFilterMap>
   406   template<typename Graph, typename NodeFilterMap>
   407   class NodeSubGraphWrapper : 
   407   class NodeSubGraphAdaptor : 
   408     public SubGraphWrapper<Graph, NodeFilterMap, 
   408     public SubGraphAdaptor<Graph, NodeFilterMap, 
   409 			   ConstMap<typename Graph::Edge,bool> > {
   409 			   ConstMap<typename Graph::Edge,bool> > {
   410   public:
   410   public:
   411     typedef SubGraphWrapper<Graph, NodeFilterMap, 
   411     typedef SubGraphAdaptor<Graph, NodeFilterMap, 
   412 			    ConstMap<typename Graph::Edge,bool> > Parent;
   412 			    ConstMap<typename Graph::Edge,bool> > Parent;
   413   protected:
   413   protected:
   414     ConstMap<typename Graph::Edge, bool> const_true_map;
   414     ConstMap<typename Graph::Edge, bool> const_true_map;
   415   public:
   415   public:
   416     NodeSubGraphWrapper(Graph& _graph, NodeFilterMap& _node_filter_map) : 
   416     NodeSubGraphAdaptor(Graph& _graph, NodeFilterMap& _node_filter_map) : 
   417       Parent(), const_true_map(true) { 
   417       Parent(), const_true_map(true) { 
   418       Parent::setGraph(_graph);
   418       Parent::setGraph(_graph);
   419       Parent::setNodeFilterMap(_node_filter_map);
   419       Parent::setNodeFilterMap(_node_filter_map);
   420       Parent::setEdgeFilterMap(const_true_map);
   420       Parent::setEdgeFilterMap(const_true_map);
   421     }
   421     }
   422   };
   422   };
   423 
   423 
   424 
   424 
   425   /*! \brief A wrapper for hiding edges from a graph.
   425   /*! \brief An adaptor for hiding edges from a graph.
   426 
   426 
   427   \warning Graph wrappers are in even more experimental state than the other
   427   \warning Graph adaptors are in even more experimental state than the other
   428   parts of the lib. Use them at you own risk.
   428   parts of the lib. Use them at you own risk.
   429   
   429   
   430   A wrapper for hiding edges from a graph.
   430   An adaptor for hiding edges from a graph.
   431   This wrapper specializes SubGraphWrapper in the way that only the edge-set 
   431   This adaptor specializes SubGraphAdaptor in the way that only the edge-set 
   432   can be filtered. The usefulness of this wrapper is demonstrated in the 
   432   can be filtered. The usefulness of this adaptor is demonstrated in the 
   433   problem of searching a maximum number of edge-disjoint shortest paths 
   433   problem of searching a maximum number of edge-disjoint shortest paths 
   434   between 
   434   between 
   435   two nodes \c s and \c t. Shortest here means being shortest w.r.t. 
   435   two nodes \c s and \c t. Shortest here means being shortest w.r.t. 
   436   non-negative edge-lengths. Note that 
   436   non-negative edge-lengths. Note that 
   437   the comprehension of the presented solution 
   437   the comprehension of the presented solution 
   496   \code
   496   \code
   497   typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap> 
   497   typedef TightEdgeFilterMap<Graph, const Dijkstra::DistMap, LengthMap> 
   498     TightEdgeFilter;
   498     TightEdgeFilter;
   499   TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
   499   TightEdgeFilter tight_edge_filter(g, dijkstra.distMap(), length);
   500   
   500   
   501   typedef EdgeSubGraphWrapper<Graph, TightEdgeFilter> SubGW;
   501   typedef EdgeSubGraphAdaptor<Graph, TightEdgeFilter> SubGW;
   502   SubGW gw(g, tight_edge_filter);
   502   SubGW gw(g, tight_edge_filter);
   503   \endcode
   503   \endcode
   504   Then, the maximum nimber of edge-disjoint \c s-\c t paths are computed 
   504   Then, the maximum nimber of edge-disjoint \c s-\c t paths are computed 
   505   with a max flow algorithm Preflow.
   505   with a max flow algorithm Preflow.
   506   \code
   506   \code
   547   \endcode
   547   \endcode
   548 
   548 
   549   \author Marton Makai
   549   \author Marton Makai
   550   */
   550   */
   551   template<typename Graph, typename EdgeFilterMap>
   551   template<typename Graph, typename EdgeFilterMap>
   552   class EdgeSubGraphWrapper : 
   552   class EdgeSubGraphAdaptor : 
   553     public SubGraphWrapper<Graph, ConstMap<typename Graph::Node,bool>, 
   553     public SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>, 
   554 			   EdgeFilterMap> {
   554 			   EdgeFilterMap> {
   555   public:
   555   public:
   556     typedef SubGraphWrapper<Graph, ConstMap<typename Graph::Node,bool>, 
   556     typedef SubGraphAdaptor<Graph, ConstMap<typename Graph::Node,bool>, 
   557 			    EdgeFilterMap> Parent;
   557 			    EdgeFilterMap> Parent;
   558   protected:
   558   protected:
   559     ConstMap<typename Graph::Node, bool> const_true_map;
   559     ConstMap<typename Graph::Node, bool> const_true_map;
   560   public:
   560   public:
   561     EdgeSubGraphWrapper(Graph& _graph, EdgeFilterMap& _edge_filter_map) : 
   561     EdgeSubGraphAdaptor(Graph& _graph, EdgeFilterMap& _edge_filter_map) : 
   562       Parent(), const_true_map(true) { 
   562       Parent(), const_true_map(true) { 
   563       Parent::setGraph(_graph);
   563       Parent::setGraph(_graph);
   564       Parent::setNodeFilterMap(const_true_map);
   564       Parent::setNodeFilterMap(const_true_map);
   565       Parent::setEdgeFilterMap(_edge_filter_map);
   565       Parent::setEdgeFilterMap(_edge_filter_map);
   566     }
   566     }
   567   };
   567   };
   568 
   568 
   569   template <typename _Graph>
   569   template <typename _Graph>
   570   class UndirGraphWrapperBase : 
   570   class UndirGraphAdaptorBase : 
   571     public UndirGraphExtender<GraphWrapperBase<_Graph> > {
   571     public UndirGraphExtender<GraphAdaptorBase<_Graph> > {
   572   public:
   572   public:
   573     typedef _Graph Graph;
   573     typedef _Graph Graph;
   574     typedef UndirGraphExtender<GraphWrapperBase<_Graph> > Parent;
   574     typedef UndirGraphExtender<GraphAdaptorBase<_Graph> > Parent;
   575   protected:
   575   protected:
   576     UndirGraphWrapperBase() : Parent() { }
   576     UndirGraphAdaptorBase() : Parent() { }
   577   public:
   577   public:
   578     typedef typename Parent::UndirEdge UndirEdge;
   578     typedef typename Parent::UndirEdge UndirEdge;
   579     typedef typename Parent::Edge Edge;
   579     typedef typename Parent::Edge Edge;
   580     
   580     
   581     /// \bug Why cant an edge say that it is forward or not??? 
   581     /// \bug Why cant an edge say that it is forward or not??? 
   582     /// By this, a pointer to the graph have to be stored
   582     /// By this, a pointer to the graph have to be stored
   583     /// The implementation
   583     /// The implementation
   584     template <typename T>
   584     template <typename T>
   585     class EdgeMap {
   585     class EdgeMap {
   586     protected:
   586     protected:
   587       const UndirGraphWrapperBase<_Graph>* g;
   587       const UndirGraphAdaptorBase<_Graph>* g;
   588       template <typename TT> friend class EdgeMap;
   588       template <typename TT> friend class EdgeMap;
   589       typename _Graph::template EdgeMap<T> forward_map, backward_map; 
   589       typename _Graph::template EdgeMap<T> forward_map, backward_map; 
   590     public:
   590     public:
   591       typedef T Value;
   591       typedef T Value;
   592       typedef Edge Key;
   592       typedef Edge Key;
   593       
   593       
   594       EdgeMap(const UndirGraphWrapperBase<_Graph>& _g) : g(&_g), 
   594       EdgeMap(const UndirGraphAdaptorBase<_Graph>& _g) : g(&_g), 
   595 	forward_map(*(g->graph)), backward_map(*(g->graph)) { }
   595 	forward_map(*(g->graph)), backward_map(*(g->graph)) { }
   596 
   596 
   597       EdgeMap(const UndirGraphWrapperBase<_Graph>& _g, T a) : g(&_g), 
   597       EdgeMap(const UndirGraphAdaptorBase<_Graph>& _g, T a) : g(&_g), 
   598 	forward_map(*(g->graph), a), backward_map(*(g->graph), a) { }
   598 	forward_map(*(g->graph), a), backward_map(*(g->graph), a) { }
   599       
   599       
   600       void set(Edge e, T a) { 
   600       void set(Edge e, T a) { 
   601 	if (g->forward(e)) 
   601 	if (g->forward(e)) 
   602 	  forward_map.set(e, a); 
   602 	  forward_map.set(e, a); 
   618       typename _Graph::template EdgeMap<T> map; 
   618       typename _Graph::template EdgeMap<T> map; 
   619     public:
   619     public:
   620       typedef T Value;
   620       typedef T Value;
   621       typedef UndirEdge Key;
   621       typedef UndirEdge Key;
   622       
   622       
   623       UndirEdgeMap(const UndirGraphWrapperBase<_Graph>& g) : 
   623       UndirEdgeMap(const UndirGraphAdaptorBase<_Graph>& g) : 
   624 	map(*(g.graph)) { }
   624 	map(*(g.graph)) { }
   625 
   625 
   626       UndirEdgeMap(const UndirGraphWrapperBase<_Graph>& g, T a) : 
   626       UndirEdgeMap(const UndirGraphAdaptorBase<_Graph>& g, T a) : 
   627 	map(*(g.graph), a) { }
   627 	map(*(g.graph), a) { }
   628       
   628       
   629       void set(UndirEdge e, T a) { 
   629       void set(UndirEdge e, T a) { 
   630 	map.set(e, a); 
   630 	map.set(e, a); 
   631       }
   631       }
   635       }
   635       }
   636     };
   636     };
   637       
   637       
   638   };
   638   };
   639 
   639 
   640   /// \brief An undirected graph is made from a directed graph by a wrapper
   640   /// \brief An undirected graph is made from a directed graph by an adaptor
   641   ///
   641   ///
   642   /// Undocumented, untested!!!
   642   /// Undocumented, untested!!!
   643   /// If somebody knows nice demo application, let's polulate it.
   643   /// If somebody knows nice demo application, let's polulate it.
   644   /// 
   644   /// 
   645   /// \author Marton Makai
   645   /// \author Marton Makai
   646   template<typename _Graph>
   646   template<typename _Graph>
   647   class UndirGraphWrapper : 
   647   class UndirGraphAdaptor : 
   648     public IterableUndirGraphExtender<
   648     public IterableUndirGraphExtender<
   649     UndirGraphWrapperBase<_Graph> > {
   649     UndirGraphAdaptorBase<_Graph> > {
   650   public:
   650   public:
   651     typedef _Graph Graph;
   651     typedef _Graph Graph;
   652     typedef IterableUndirGraphExtender<
   652     typedef IterableUndirGraphExtender<
   653       UndirGraphWrapperBase<_Graph> > Parent;
   653       UndirGraphAdaptorBase<_Graph> > Parent;
   654   protected:
   654   protected:
   655     UndirGraphWrapper() { }
   655     UndirGraphAdaptor() { }
   656   public:
   656   public:
   657     UndirGraphWrapper(_Graph& _graph) { 
   657     UndirGraphAdaptor(_Graph& _graph) { 
   658       setGraph(_graph);
   658       setGraph(_graph);
   659     }
   659     }
   660   };
   660   };
   661 
   661 
   662   
   662   
   663   template <typename _Graph, 
   663   template <typename _Graph, 
   664 	    typename ForwardFilterMap, typename BackwardFilterMap>
   664 	    typename ForwardFilterMap, typename BackwardFilterMap>
   665   class SubBidirGraphWrapperBase : public GraphWrapperBase<_Graph> {
   665   class SubBidirGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
   666   public:
   666   public:
   667     typedef _Graph Graph;
   667     typedef _Graph Graph;
   668     typedef GraphWrapperBase<_Graph> Parent;
   668     typedef GraphAdaptorBase<_Graph> Parent;
   669   protected:
   669   protected:
   670     ForwardFilterMap* forward_filter;
   670     ForwardFilterMap* forward_filter;
   671     BackwardFilterMap* backward_filter;
   671     BackwardFilterMap* backward_filter;
   672     SubBidirGraphWrapperBase() : Parent(), 
   672     SubBidirGraphAdaptorBase() : Parent(), 
   673 				 forward_filter(0), backward_filter(0) { }
   673 				 forward_filter(0), backward_filter(0) { }
   674 
   674 
   675     void setForwardFilterMap(ForwardFilterMap& _forward_filter) {
   675     void setForwardFilterMap(ForwardFilterMap& _forward_filter) {
   676       forward_filter=&_forward_filter;
   676       forward_filter=&_forward_filter;
   677     }
   677     }
   678     void setBackwardFilterMap(BackwardFilterMap& _backward_filter) {
   678     void setBackwardFilterMap(BackwardFilterMap& _backward_filter) {
   679       backward_filter=&_backward_filter;
   679       backward_filter=&_backward_filter;
   680     }
   680     }
   681 
   681 
   682   public:
   682   public:
   683 //     SubGraphWrapperBase(Graph& _graph, 
   683 //     SubGraphAdaptorBase(Graph& _graph, 
   684 // 			NodeFilterMap& _node_filter_map, 
   684 // 			NodeFilterMap& _node_filter_map, 
   685 // 			EdgeFilterMap& _edge_filter_map) : 
   685 // 			EdgeFilterMap& _edge_filter_map) : 
   686 //       Parent(&_graph), 
   686 //       Parent(&_graph), 
   687 //       node_filter_map(&node_filter_map), 
   687 //       node_filter_map(&node_filter_map), 
   688 //       edge_filter_map(&edge_filter_map) { }
   688 //       edge_filter_map(&edge_filter_map) { }
   689 
   689 
   690     typedef typename Parent::Node Node;
   690     typedef typename Parent::Node Node;
   691     typedef typename _Graph::Edge GraphEdge;
   691     typedef typename _Graph::Edge GraphEdge;
   692     template <typename T> class EdgeMap;
   692     template <typename T> class EdgeMap;
   693     /// SubBidirGraphWrapperBase<..., ..., ...>::Edge is inherited from 
   693     /// SubBidirGraphAdaptorBase<..., ..., ...>::Edge is inherited from 
   694     /// _Graph::Edge. It contains an extra bool flag which is true 
   694     /// _Graph::Edge. It contains an extra bool flag which is true 
   695     /// if and only if the 
   695     /// if and only if the 
   696     /// edge is the backward version of the original edge.
   696     /// edge is the backward version of the original edge.
   697     class Edge : public _Graph::Edge {
   697     class Edge : public _Graph::Edge {
   698       friend class SubBidirGraphWrapperBase<
   698       friend class SubBidirGraphAdaptorBase<
   699 	Graph, ForwardFilterMap, BackwardFilterMap>;
   699 	Graph, ForwardFilterMap, BackwardFilterMap>;
   700       template<typename T> friend class EdgeMap;
   700       template<typename T> friend class EdgeMap;
   701     protected:
   701     protected:
   702       bool backward; //true, iff backward
   702       bool backward; //true, iff backward
   703     public:
   703     public:
   847 
   847 
   848     bool forward(const Edge& e) const { return !e.backward; }
   848     bool forward(const Edge& e) const { return !e.backward; }
   849     bool backward(const Edge& e) const { return e.backward; }
   849     bool backward(const Edge& e) const { return e.backward; }
   850 
   850 
   851     template <typename T>
   851     template <typename T>
   852     /// \c SubBidirGraphWrapperBase<..., ..., ...>::EdgeMap contains two 
   852     /// \c SubBidirGraphAdaptorBase<..., ..., ...>::EdgeMap contains two 
   853     /// _Graph::EdgeMap one for the forward edges and 
   853     /// _Graph::EdgeMap one for the forward edges and 
   854     /// one for the backward edges.
   854     /// one for the backward edges.
   855     class EdgeMap {
   855     class EdgeMap {
   856       template <typename TT> friend class EdgeMap;
   856       template <typename TT> friend class EdgeMap;
   857       typename _Graph::template EdgeMap<T> forward_map, backward_map; 
   857       typename _Graph::template EdgeMap<T> forward_map, backward_map; 
   858     public:
   858     public:
   859       typedef T Value;
   859       typedef T Value;
   860       typedef Edge Key;
   860       typedef Edge Key;
   861 
   861 
   862       EdgeMap(const SubBidirGraphWrapperBase<_Graph, 
   862       EdgeMap(const SubBidirGraphAdaptorBase<_Graph, 
   863 	      ForwardFilterMap, BackwardFilterMap>& g) : 
   863 	      ForwardFilterMap, BackwardFilterMap>& g) : 
   864 	forward_map(*(g.graph)), backward_map(*(g.graph)) { }
   864 	forward_map(*(g.graph)), backward_map(*(g.graph)) { }
   865 
   865 
   866       EdgeMap(const SubBidirGraphWrapperBase<_Graph, 
   866       EdgeMap(const SubBidirGraphAdaptorBase<_Graph, 
   867 	      ForwardFilterMap, BackwardFilterMap>& g, T a) : 
   867 	      ForwardFilterMap, BackwardFilterMap>& g, T a) : 
   868 	forward_map(*(g.graph), a), backward_map(*(g.graph), a) { }
   868 	forward_map(*(g.graph), a), backward_map(*(g.graph), a) { }
   869       
   869       
   870       void set(Edge e, T a) { 
   870       void set(Edge e, T a) { 
   871 	if (!e.backward) 
   871 	if (!e.backward) 
   897     };
   897     };
   898 
   898 
   899   };
   899   };
   900 
   900 
   901 
   901 
   902   ///\brief A wrapper for composing a subgraph of a 
   902   ///\brief An adaptor for composing a subgraph of a 
   903   /// bidirected graph made from a directed one. 
   903   /// bidirected graph made from a directed one. 
   904   ///
   904   ///
   905   /// A wrapper for composing a subgraph of a 
   905   /// An adaptor for composing a subgraph of a 
   906   /// bidirected graph made from a directed one. 
   906   /// bidirected graph made from a directed one. 
   907   ///
   907   ///
   908   ///\warning Graph wrappers are in even more experimental state than the other
   908   ///\warning Graph adaptors are in even more experimental state than the other
   909   ///parts of the lib. Use them at you own risk.
   909   ///parts of the lib. Use them at you own risk.
   910   ///
   910   ///
   911   /// Let \f$G=(V, A)\f$ be a directed graph and for each directed edge 
   911   /// Let \f$G=(V, A)\f$ be a directed graph and for each directed edge 
   912   /// \f$e\in A\f$, let \f$\bar e\f$ denote the edge obtained by
   912   /// \f$e\in A\f$, let \f$\bar e\f$ denote the edge obtained by
   913   /// reversing its orientation. We are given moreover two bool valued 
   913   /// reversing its orientation. We are given moreover two bool valued 
   914   /// maps on the edge-set, 
   914   /// maps on the edge-set, 
   915   /// \f$forward\_filter\f$, and \f$backward\_filter\f$. 
   915   /// \f$forward\_filter\f$, and \f$backward\_filter\f$. 
   916   /// SubBidirGraphWrapper implements the graph structure with node-set 
   916   /// SubBidirGraphAdaptor implements the graph structure with node-set 
   917   /// \f$V\f$ and edge-set 
   917   /// \f$V\f$ and edge-set 
   918   /// \f$\{e : e\in A \mbox{ and } forward\_filter(e) \mbox{ is true}\}+\{\bar e : e\in A \mbox{ and } backward\_filter(e) \mbox{ is true}\}\f$. 
   918   /// \f$\{e : e\in A \mbox{ and } forward\_filter(e) \mbox{ is true}\}+\{\bar e : e\in A \mbox{ and } backward\_filter(e) \mbox{ is true}\}\f$. 
   919   /// The purpose of writing + instead of union is because parallel 
   919   /// The purpose of writing + instead of union is because parallel 
   920   /// edges can arise. (Similarly, antiparallel edges also can arise).
   920   /// edges can arise. (Similarly, antiparallel edges also can arise).
   921   /// In other words, a subgraph of the bidirected graph obtained, which 
   921   /// In other words, a subgraph of the bidirected graph obtained, which 
   922   /// is given by orienting the edges of the original graph in both directions.
   922   /// is given by orienting the edges of the original graph in both directions.
   923   /// As the oppositely directed edges are logically different, 
   923   /// As the oppositely directed edges are logically different, 
   924   /// the maps are able to attach different values for them. 
   924   /// the maps are able to attach different values for them. 
   925   ///
   925   ///
   926   /// An example for such a construction is \c RevGraphWrapper where the 
   926   /// An example for such a construction is \c RevGraphAdaptor where the 
   927   /// forward_filter is everywhere false and the backward_filter is 
   927   /// forward_filter is everywhere false and the backward_filter is 
   928   /// everywhere true. We note that for sake of efficiency, 
   928   /// everywhere true. We note that for sake of efficiency, 
   929   /// \c RevGraphWrapper is implemented in a different way. 
   929   /// \c RevGraphAdaptor is implemented in a different way. 
   930   /// But BidirGraphWrapper is obtained from 
   930   /// But BidirGraphAdaptor is obtained from 
   931   /// SubBidirGraphWrapper by considering everywhere true 
   931   /// SubBidirGraphAdaptor by considering everywhere true 
   932   /// valued maps both for forward_filter and backward_filter. 
   932   /// valued maps both for forward_filter and backward_filter. 
   933   ///
   933   ///
   934   /// The most important application of SubBidirGraphWrapper 
   934   /// The most important application of SubBidirGraphAdaptor 
   935   /// is ResGraphWrapper, which stands for the residual graph in directed 
   935   /// is ResGraphAdaptor, which stands for the residual graph in directed 
   936   /// flow and circulation problems. 
   936   /// flow and circulation problems. 
   937   /// As wrappers usually, the SubBidirGraphWrapper implements the 
   937   /// As adaptors usually, the SubBidirGraphAdaptor implements the 
   938   /// above mentioned graph structure without its physical storage, 
   938   /// above mentioned graph structure without its physical storage, 
   939   /// that is the whole stuff is stored in constant memory. 
   939   /// that is the whole stuff is stored in constant memory. 
   940   template<typename _Graph, 
   940   template<typename _Graph, 
   941 	   typename ForwardFilterMap, typename BackwardFilterMap>
   941 	   typename ForwardFilterMap, typename BackwardFilterMap>
   942   class SubBidirGraphWrapper : 
   942   class SubBidirGraphAdaptor : 
   943     public IterableGraphExtender<
   943     public IterableGraphExtender<
   944     SubBidirGraphWrapperBase<_Graph, ForwardFilterMap, BackwardFilterMap> > {
   944     SubBidirGraphAdaptorBase<_Graph, ForwardFilterMap, BackwardFilterMap> > {
   945   public:
   945   public:
   946     typedef _Graph Graph;
   946     typedef _Graph Graph;
   947     typedef IterableGraphExtender<
   947     typedef IterableGraphExtender<
   948       SubBidirGraphWrapperBase<
   948       SubBidirGraphAdaptorBase<
   949       _Graph, ForwardFilterMap, BackwardFilterMap> > Parent;
   949       _Graph, ForwardFilterMap, BackwardFilterMap> > Parent;
   950   protected:
   950   protected:
   951     SubBidirGraphWrapper() { }
   951     SubBidirGraphAdaptor() { }
   952   public:
   952   public:
   953     SubBidirGraphWrapper(_Graph& _graph, ForwardFilterMap& _forward_filter, 
   953     SubBidirGraphAdaptor(_Graph& _graph, ForwardFilterMap& _forward_filter, 
   954 			 BackwardFilterMap& _backward_filter) { 
   954 			 BackwardFilterMap& _backward_filter) { 
   955       setGraph(_graph);
   955       setGraph(_graph);
   956       setForwardFilterMap(_forward_filter);
   956       setForwardFilterMap(_forward_filter);
   957       setBackwardFilterMap(_backward_filter);
   957       setBackwardFilterMap(_backward_filter);
   958     }
   958     }
   959   };
   959   };
   960 
   960 
   961 
   961 
   962 
   962 
   963   ///\brief A wrapper for composing bidirected graph from a directed one. 
   963   ///\brief An adaptor for composing bidirected graph from a directed one. 
   964   ///
   964   ///
   965   ///\warning Graph wrappers are in even more experimental state than the other
   965   ///\warning Graph adaptors are in even more experimental state than the other
   966   ///parts of the lib. Use them at you own risk.
   966   ///parts of the lib. Use them at you own risk.
   967   ///
   967   ///
   968   /// A wrapper for composing bidirected graph from a directed one. 
   968   /// An adaptor for composing bidirected graph from a directed one. 
   969   /// A bidirected graph is composed over the directed one without physical 
   969   /// A bidirected graph is composed over the directed one without physical 
   970   /// storage. As the oppositely directed edges are logically different ones 
   970   /// storage. As the oppositely directed edges are logically different ones 
   971   /// the maps are able to attach different values for them.
   971   /// the maps are able to attach different values for them.
   972   template<typename Graph>
   972   template<typename Graph>
   973   class BidirGraphWrapper : 
   973   class BidirGraphAdaptor : 
   974     public SubBidirGraphWrapper<
   974     public SubBidirGraphAdaptor<
   975     Graph, 
   975     Graph, 
   976     ConstMap<typename Graph::Edge, bool>, 
   976     ConstMap<typename Graph::Edge, bool>, 
   977     ConstMap<typename Graph::Edge, bool> > {
   977     ConstMap<typename Graph::Edge, bool> > {
   978   public:
   978   public:
   979     typedef  SubBidirGraphWrapper<
   979     typedef  SubBidirGraphAdaptor<
   980       Graph, 
   980       Graph, 
   981       ConstMap<typename Graph::Edge, bool>, 
   981       ConstMap<typename Graph::Edge, bool>, 
   982       ConstMap<typename Graph::Edge, bool> > Parent; 
   982       ConstMap<typename Graph::Edge, bool> > Parent; 
   983   protected:
   983   protected:
   984     ConstMap<typename Graph::Edge, bool> cm;
   984     ConstMap<typename Graph::Edge, bool> cm;
   985 
   985 
   986     BidirGraphWrapper() : Parent(), cm(true) { 
   986     BidirGraphAdaptor() : Parent(), cm(true) { 
   987       Parent::setForwardFilterMap(cm);
   987       Parent::setForwardFilterMap(cm);
   988       Parent::setBackwardFilterMap(cm);
   988       Parent::setBackwardFilterMap(cm);
   989     }
   989     }
   990   public:
   990   public:
   991     BidirGraphWrapper(Graph& _graph) : Parent(), cm(true) { 
   991     BidirGraphAdaptor(Graph& _graph) : Parent(), cm(true) { 
   992       Parent::setGraph(_graph);
   992       Parent::setGraph(_graph);
   993       Parent::setForwardFilterMap(cm);
   993       Parent::setForwardFilterMap(cm);
   994       Parent::setBackwardFilterMap(cm);
   994       Parent::setBackwardFilterMap(cm);
   995     }
   995     }
   996 
   996 
   997     int edgeNum() const { 
   997     int edgeNum() const { 
   998       return 2*this->graph->edgeNum();
   998       return 2*this->graph->edgeNum();
   999     }
   999     }
  1000     //    KEEP_MAPS(Parent, BidirGraphWrapper);
  1000     //    KEEP_MAPS(Parent, BidirGraphAdaptor);
  1001   };
  1001   };
  1002 
  1002 
  1003 
  1003 
  1004   template<typename Graph, typename Number,
  1004   template<typename Graph, typename Number,
  1005 	   typename CapacityMap, typename FlowMap>
  1005 	   typename CapacityMap, typename FlowMap>
  1035       return (Number(0) < Number((*flow)[e]));
  1035       return (Number(0) < Number((*flow)[e]));
  1036     }
  1036     }
  1037   };
  1037   };
  1038 
  1038 
  1039   
  1039   
  1040   /*! \brief A wrapper for composing the residual graph for directed flow and circulation problems.
  1040   /*! \brief An adaptor for composing the residual graph for directed flow and circulation problems.
  1041 
  1041 
  1042   A wrapper for composing the residual graph for directed flow and circulation problems. 
  1042   An adaptor for composing the residual graph for directed flow and circulation problems. 
  1043   Let \f$G=(V, A)\f$ be a directed graph and let \f$F\f$ be a 
  1043   Let \f$G=(V, A)\f$ be a directed graph and let \f$F\f$ be a 
  1044   number type. Let moreover 
  1044   number type. Let moreover 
  1045   \f$f,c:A\to F\f$, be functions on the edge-set. 
  1045   \f$f,c:A\to F\f$, be functions on the edge-set. 
  1046   In the appications of ResGraphWrapper, \f$f\f$ usually stands for a flow 
  1046   In the appications of ResGraphAdaptor, \f$f\f$ usually stands for a flow 
  1047   and \f$c\f$ for a capacity function.   
  1047   and \f$c\f$ for a capacity function.   
  1048   Suppose that a graph instange \c g of type 
  1048   Suppose that a graph instange \c g of type 
  1049   \c ListGraph implements \f$G\f$.
  1049   \c ListGraph implements \f$G\f$.
  1050   \code
  1050   \code
  1051   ListGraph g;
  1051   ListGraph g;
  1052   \endcode
  1052   \endcode
  1053   Then RevGraphWrapper implements the graph structure with node-set 
  1053   Then RevGraphAdaptor implements the graph structure with node-set 
  1054   \f$V\f$ and edge-set \f$A_{forward}\cup A_{backward}\f$, where 
  1054   \f$V\f$ and edge-set \f$A_{forward}\cup A_{backward}\f$, where 
  1055   \f$A_{forward}=\{uv : uv\in A, f(uv)<c(uv)\}\f$ and 
  1055   \f$A_{forward}=\{uv : uv\in A, f(uv)<c(uv)\}\f$ and 
  1056   \f$A_{backward}=\{vu : uv\in A, f(uv)>0\}\f$, 
  1056   \f$A_{backward}=\{vu : uv\in A, f(uv)>0\}\f$, 
  1057   i.e. the so called residual graph. 
  1057   i.e. the so called residual graph. 
  1058   When we take the union \f$A_{forward}\cup A_{backward}\f$, 
  1058   When we take the union \f$A_{forward}\cup A_{backward}\f$, 
  1059   multilicities are counted, i.e. if an edge is in both 
  1059   multilicities are counted, i.e. if an edge is in both 
  1060   \f$A_{forward}\f$ and \f$A_{backward}\f$, then in the wrapper it 
  1060   \f$A_{forward}\f$ and \f$A_{backward}\f$, then in the adaptor it 
  1061   appears twice. 
  1061   appears twice. 
  1062   The following code shows how 
  1062   The following code shows how 
  1063   such an instance can be constructed.
  1063   such an instance can be constructed.
  1064   \code
  1064   \code
  1065   typedef ListGraph Graph;
  1065   typedef ListGraph Graph;
  1066   Graph::EdgeMap<int> f(g);
  1066   Graph::EdgeMap<int> f(g);
  1067   Graph::EdgeMap<int> c(g);
  1067   Graph::EdgeMap<int> c(g);
  1068   ResGraphWrapper<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > gw(g);
  1068   ResGraphAdaptor<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > gw(g);
  1069   \endcode
  1069   \endcode
  1070   \author Marton Makai
  1070   \author Marton Makai
  1071   */
  1071   */
  1072   template<typename Graph, typename Number, 
  1072   template<typename Graph, typename Number, 
  1073 	   typename CapacityMap, typename FlowMap>
  1073 	   typename CapacityMap, typename FlowMap>
  1074   class ResGraphWrapper : 
  1074   class ResGraphAdaptor : 
  1075     public SubBidirGraphWrapper< 
  1075     public SubBidirGraphAdaptor< 
  1076     Graph, 
  1076     Graph, 
  1077     ResForwardFilter<Graph, Number, CapacityMap, FlowMap>,  
  1077     ResForwardFilter<Graph, Number, CapacityMap, FlowMap>,  
  1078     ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> > {
  1078     ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> > {
  1079   public:
  1079   public:
  1080     typedef SubBidirGraphWrapper< 
  1080     typedef SubBidirGraphAdaptor< 
  1081       Graph, 
  1081       Graph, 
  1082       ResForwardFilter<Graph, Number, CapacityMap, FlowMap>,  
  1082       ResForwardFilter<Graph, Number, CapacityMap, FlowMap>,  
  1083       ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> > Parent;
  1083       ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> > Parent;
  1084   protected:
  1084   protected:
  1085     const CapacityMap* capacity;
  1085     const CapacityMap* capacity;
  1086     FlowMap* flow;
  1086     FlowMap* flow;
  1087     ResForwardFilter<Graph, Number, CapacityMap, FlowMap> forward_filter;
  1087     ResForwardFilter<Graph, Number, CapacityMap, FlowMap> forward_filter;
  1088     ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> backward_filter;
  1088     ResBackwardFilter<Graph, Number, CapacityMap, FlowMap> backward_filter;
  1089     ResGraphWrapper() : Parent(), 
  1089     ResGraphAdaptor() : Parent(), 
  1090  			capacity(0), flow(0) { }
  1090  			capacity(0), flow(0) { }
  1091     void setCapacityMap(const CapacityMap& _capacity) {
  1091     void setCapacityMap(const CapacityMap& _capacity) {
  1092       capacity=&_capacity;
  1092       capacity=&_capacity;
  1093       forward_filter.setCapacity(_capacity);
  1093       forward_filter.setCapacity(_capacity);
  1094       backward_filter.setCapacity(_capacity);
  1094       backward_filter.setCapacity(_capacity);
  1097       flow=&_flow;
  1097       flow=&_flow;
  1098       forward_filter.setFlow(_flow);
  1098       forward_filter.setFlow(_flow);
  1099       backward_filter.setFlow(_flow);
  1099       backward_filter.setFlow(_flow);
  1100     }
  1100     }
  1101   public:
  1101   public:
  1102     ResGraphWrapper(Graph& _graph, const CapacityMap& _capacity, 
  1102     ResGraphAdaptor(Graph& _graph, const CapacityMap& _capacity, 
  1103 		       FlowMap& _flow) : 
  1103 		       FlowMap& _flow) : 
  1104       Parent(), capacity(&_capacity), flow(&_flow), 
  1104       Parent(), capacity(&_capacity), flow(&_flow), 
  1105       forward_filter(/*_graph,*/ _capacity, _flow), 
  1105       forward_filter(/*_graph,*/ _capacity, _flow), 
  1106       backward_filter(/*_graph,*/ _capacity, _flow) {
  1106       backward_filter(/*_graph,*/ _capacity, _flow) {
  1107       Parent::setGraph(_graph);
  1107       Parent::setGraph(_graph);
  1122     ///
  1122     ///
  1123     /// In generic residual graphs the residual capacity can be obtained 
  1123     /// In generic residual graphs the residual capacity can be obtained 
  1124     /// as a map. 
  1124     /// as a map. 
  1125     class ResCap {
  1125     class ResCap {
  1126     protected:
  1126     protected:
  1127       const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>* res_graph;
  1127       const ResGraphAdaptor<Graph, Number, CapacityMap, FlowMap>* res_graph;
  1128     public:
  1128     public:
  1129       typedef Number Value;
  1129       typedef Number Value;
  1130       typedef Edge Key;
  1130       typedef Edge Key;
  1131       ResCap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& 
  1131       ResCap(const ResGraphAdaptor<Graph, Number, CapacityMap, FlowMap>& 
  1132 	     _res_graph) : res_graph(&_res_graph) { }
  1132 	     _res_graph) : res_graph(&_res_graph) { }
  1133       Number operator[](const Edge& e) const { 
  1133       Number operator[](const Edge& e) const { 
  1134 	if (res_graph->forward(e)) 
  1134 	if (res_graph->forward(e)) 
  1135 	  return (*(res_graph->capacity))[e]-(*(res_graph->flow))[e]; 
  1135 	  return (*(res_graph->capacity))[e]-(*(res_graph->flow))[e]; 
  1136 	else 
  1136 	else 
  1137 	  return (*(res_graph->flow))[e]; 
  1137 	  return (*(res_graph->flow))[e]; 
  1138       }
  1138       }
  1139     };
  1139     };
  1140 
  1140 
  1141     //    KEEP_MAPS(Parent, ResGraphWrapper);
  1141     //    KEEP_MAPS(Parent, ResGraphAdaptor);
  1142   };
  1142   };
  1143 
  1143 
  1144 
  1144 
  1145 
  1145 
  1146   template <typename _Graph, typename FirstOutEdgesMap>
  1146   template <typename _Graph, typename FirstOutEdgesMap>
  1147   class ErasingFirstGraphWrapperBase : public GraphWrapperBase<_Graph> {
  1147   class ErasingFirstGraphAdaptorBase : public GraphAdaptorBase<_Graph> {
  1148   public:
  1148   public:
  1149     typedef _Graph Graph;
  1149     typedef _Graph Graph;
  1150     typedef GraphWrapperBase<_Graph> Parent;
  1150     typedef GraphAdaptorBase<_Graph> Parent;
  1151   protected:
  1151   protected:
  1152     FirstOutEdgesMap* first_out_edges;
  1152     FirstOutEdgesMap* first_out_edges;
  1153     ErasingFirstGraphWrapperBase() : Parent(), 
  1153     ErasingFirstGraphAdaptorBase() : Parent(), 
  1154 				     first_out_edges(0) { }
  1154 				     first_out_edges(0) { }
  1155 
  1155 
  1156     void setFirstOutEdgesMap(FirstOutEdgesMap& _first_out_edges) {
  1156     void setFirstOutEdgesMap(FirstOutEdgesMap& _first_out_edges) {
  1157       first_out_edges=&_first_out_edges;
  1157       first_out_edges=&_first_out_edges;
  1158     }
  1158     }
  1175   };
  1175   };
  1176 
  1176 
  1177 
  1177 
  1178   /// For blocking flows.
  1178   /// For blocking flows.
  1179 
  1179 
  1180   ///\warning Graph wrappers are in even more experimental state than the other
  1180   ///\warning Graph adaptors are in even more experimental state than the other
  1181   ///parts of the lib. Use them at you own risk.
  1181   ///parts of the lib. Use them at you own risk.
  1182   ///
  1182   ///
  1183   /// This graph wrapper is used for on-the-fly 
  1183   /// This graph adaptor is used for on-the-fly 
  1184   /// Dinits blocking flow computations.
  1184   /// Dinits blocking flow computations.
  1185   /// For each node, an out-edge is stored which is used when the 
  1185   /// For each node, an out-edge is stored which is used when the 
  1186   /// \code 
  1186   /// \code 
  1187   /// OutEdgeIt& first(OutEdgeIt&, const Node&)
  1187   /// OutEdgeIt& first(OutEdgeIt&, const Node&)
  1188   /// \endcode
  1188   /// \endcode
  1189   /// is called. 
  1189   /// is called. 
  1190   ///
  1190   ///
  1191   /// \author Marton Makai
  1191   /// \author Marton Makai
  1192   template <typename _Graph, typename FirstOutEdgesMap>
  1192   template <typename _Graph, typename FirstOutEdgesMap>
  1193   class ErasingFirstGraphWrapper : 
  1193   class ErasingFirstGraphAdaptor : 
  1194     public IterableGraphExtender<
  1194     public IterableGraphExtender<
  1195     ErasingFirstGraphWrapperBase<_Graph, FirstOutEdgesMap> > {
  1195     ErasingFirstGraphAdaptorBase<_Graph, FirstOutEdgesMap> > {
  1196   public:
  1196   public:
  1197     typedef _Graph Graph;
  1197     typedef _Graph Graph;
  1198     typedef IterableGraphExtender<
  1198     typedef IterableGraphExtender<
  1199       ErasingFirstGraphWrapperBase<_Graph, FirstOutEdgesMap> > Parent;
  1199       ErasingFirstGraphAdaptorBase<_Graph, FirstOutEdgesMap> > Parent;
  1200     ErasingFirstGraphWrapper(Graph& _graph, 
  1200     ErasingFirstGraphAdaptor(Graph& _graph, 
  1201 			     FirstOutEdgesMap& _first_out_edges) { 
  1201 			     FirstOutEdgesMap& _first_out_edges) { 
  1202       setGraph(_graph);
  1202       setGraph(_graph);
  1203       setFirstOutEdgesMap(_first_out_edges);
  1203       setFirstOutEdgesMap(_first_out_edges);
  1204     } 
  1204     } 
  1205 
  1205 
  1207 
  1207 
  1208   ///@}
  1208   ///@}
  1209 
  1209 
  1210 } //namespace lemon
  1210 } //namespace lemon
  1211 
  1211 
  1212 #endif //LEMON_GRAPH_WRAPPER_H
  1212 #endif //LEMON_GRAPH_ADAPTOR_H
  1213 
  1213