src/hugo/graph_wrapper.h
changeset 891 74589d20dbc3
parent 888 cc3590763f7f
child 892 004636791dd7
equal deleted inserted replaced
40:f094479c406c 41:6666fe4c46f4
   284     Node tail(const Edge& e) const { 
   284     Node tail(const Edge& e) const { 
   285       return GraphWrapper<Graph>::head(e); }
   285       return GraphWrapper<Graph>::head(e); }
   286     Node head(const Edge& e) const { 
   286     Node head(const Edge& e) const { 
   287       return GraphWrapper<Graph>::tail(e); }
   287       return GraphWrapper<Graph>::tail(e); }
   288 
   288 
   289     KEEP_MAPS(Parent, RevGraphWrapper);
   289     //    KEEP_MAPS(Parent, RevGraphWrapper);
   290 
   290 
   291   };
   291   };
   292 
   292 
   293 
   293 
   294 
   294 
   491       int i=0;
   491       int i=0;
   492       for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
   492       for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
   493       return i; 
   493       return i; 
   494     }
   494     }
   495 
   495 
   496     KEEP_MAPS(Parent, SubGraphWrapper);
   496     //    KEEP_MAPS(Parent, SubGraphWrapper);
   497   };
   497   };
   498 
   498 
   499 
   499 
   500 
   500 
   501   template<typename Graph>
   501   template<typename Graph>
   556 	return this->graph->head(e); }
   556 	return this->graph->head(e); }
   557     Node bNode(const OutEdgeIt& e) const { 
   557     Node bNode(const OutEdgeIt& e) const { 
   558       if (e.out_or_in) return this->graph->head(e); else 
   558       if (e.out_or_in) return this->graph->head(e); else 
   559 	return this->graph->tail(e); }
   559 	return this->graph->tail(e); }
   560 
   560 
   561     KEEP_MAPS(Parent, UndirGraphWrapper);
   561     //    KEEP_MAPS(Parent, UndirGraphWrapper);
   562 
   562 
   563   };
   563   };
   564   
   564   
   565   /// \brief An undirected graph template.
   565   /// \brief An undirected graph template.
   566   ///
   566   ///
   567   ///\warning Graph wrappers are in even more experimental state than the other
   567   ///\warning Graph wrappers are in even more experimental state than the other
   568   ///parts of the lib. Use them at you own risk.
   568   ///parts of the lib. Use them at your own risk.
   569   ///
   569   ///
   570   /// An undirected graph template.
   570   /// An undirected graph template.
   571   /// This class works as an undirected graph and a directed graph of 
   571   /// This class works as an undirected graph and a directed graph of 
   572   /// class \c Graph is used for the physical storage.
   572   /// class \c Graph is used for the physical storage.
   573   /// \ingroup graphs
   573   /// \ingroup graphs
   579   public:
   579   public:
   580     UndirGraph() : UndirGraphWrapper<Graph>() { 
   580     UndirGraph() : UndirGraphWrapper<Graph>() { 
   581       Parent::setGraph(gr); 
   581       Parent::setGraph(gr); 
   582     }
   582     }
   583 
   583 
   584     KEEP_MAPS(Parent, UndirGraph);
   584     //    KEEP_MAPS(Parent, UndirGraph);
   585   };
   585   };
   586 
   586 
   587 
   587 
   588 
   588 
   589   ///\brief A wrapper for composing a subgraph of a 
   589   ///\brief A wrapper for composing a subgraph of a 
   892     template <typename T>
   892     template <typename T>
   893     /// \c SubBidirGraphWrapper<..., ..., ...>::EdgeMap contains two 
   893     /// \c SubBidirGraphWrapper<..., ..., ...>::EdgeMap contains two 
   894     /// Graph::EdgeMap one for the forward edges and 
   894     /// Graph::EdgeMap one for the forward edges and 
   895     /// one for the backward edges.
   895     /// one for the backward edges.
   896     class EdgeMap {
   896     class EdgeMap {
       
   897       template <typename TT> friend class EdgeMap;
   897       typename Graph::template EdgeMap<T> forward_map, backward_map; 
   898       typename Graph::template EdgeMap<T> forward_map, backward_map; 
   898     public:
   899     public:
   899       typedef T ValueType;
   900       typedef T ValueType;
   900       typedef Edge KeyType;
   901       typedef Edge KeyType;
       
   902 
   901       EdgeMap(const SubBidirGraphWrapper<Graph, 
   903       EdgeMap(const SubBidirGraphWrapper<Graph, 
   902 	      ForwardFilterMap, BackwardFilterMap>& g) : 
   904 	      ForwardFilterMap, BackwardFilterMap>& g) : 
   903 	forward_map(*(g.graph)), backward_map(*(g.graph)) { }
   905 	forward_map(*(g.graph)), backward_map(*(g.graph)) { }
       
   906 
   904       EdgeMap(const SubBidirGraphWrapper<Graph, 
   907       EdgeMap(const SubBidirGraphWrapper<Graph, 
   905 	      ForwardFilterMap, BackwardFilterMap>& g, T a) : 
   908 	      ForwardFilterMap, BackwardFilterMap>& g, T a) : 
   906 	forward_map(*(g.graph), a), backward_map(*(g.graph), a) { }
   909 	forward_map(*(g.graph), a), backward_map(*(g.graph), a) { }
       
   910 
       
   911       template <typename TT>
       
   912       EdgeMap(const EdgeMap<TT>& copy) 
       
   913 	: forward_map(copy.forward_map), backward_map(copy.backward_map) {}
       
   914 
       
   915       template <typename TT>
       
   916       EdgeMap& operator=(const EdgeMap<TT>& copy) {
       
   917 	forward_map = copy.forward_map;
       
   918 	backward_map = copy.backward_map;
       
   919 	return *this;
       
   920       }
       
   921       
   907       void set(Edge e, T a) { 
   922       void set(Edge e, T a) { 
   908 	if (!e.backward) 
   923 	if (!e.backward) 
   909 	  forward_map.set(e, a); 
   924 	  forward_map.set(e, a); 
   910 	else 
   925 	else 
   911 	  backward_map.set(e, a); 
   926 	  backward_map.set(e, a); 
   912       }
   927       }
   913       T operator[](Edge e) const { 
   928 
       
   929       typename Graph::template EdgeMap<T>::ConstReferenceType 
       
   930       operator[](Edge e) const { 
   914 	if (!e.backward) 
   931 	if (!e.backward) 
   915 	  return forward_map[e]; 
   932 	  return forward_map[e]; 
   916 	else 
   933 	else 
   917 	  return backward_map[e]; 
   934 	  return backward_map[e]; 
   918       }
   935       }
       
   936 
       
   937       typename Graph::template EdgeMap<T>::ReferenceType 
       
   938       operator[](Edge e) { 
       
   939 	if (!e.backward) 
       
   940 	  return forward_map[e]; 
       
   941 	else 
       
   942 	  return backward_map[e]; 
       
   943       }
       
   944 
   919       void update() { 
   945       void update() { 
   920 	forward_map.update(); 
   946 	forward_map.update(); 
   921 	backward_map.update();
   947 	backward_map.update();
   922       }
   948       }
   923     };
   949     };
   924 
   950 
   925 
   951 
   926     KEEP_NODE_MAP(Parent, SubBidirGraphWrapper);
   952     //    KEEP_NODE_MAP(Parent, SubBidirGraphWrapper);
   927 
   953 
   928   };
   954   };
   929 
   955 
   930 
   956 
   931   ///\brief A wrapper for composing bidirected graph from a directed one. 
   957   ///\brief A wrapper for composing bidirected graph from a directed one. 
   963     }
   989     }
   964 
   990 
   965     int edgeNum() const { 
   991     int edgeNum() const { 
   966       return 2*this->graph->edgeNum();
   992       return 2*this->graph->edgeNum();
   967     }
   993     }
   968     KEEP_MAPS(Parent, BidirGraphWrapper);
   994     //    KEEP_MAPS(Parent, BidirGraphWrapper);
   969   };
   995   };
   970 
   996 
   971 
   997 
   972   /// \brief A bidirected graph template.
   998   /// \brief A bidirected graph template.
   973   ///
   999   ///
   989     Graph gr;
  1015     Graph gr;
   990   public:
  1016   public:
   991     BidirGraph() : BidirGraphWrapper<Graph>() { 
  1017     BidirGraph() : BidirGraphWrapper<Graph>() { 
   992       Parent::setGraph(gr); 
  1018       Parent::setGraph(gr); 
   993     }
  1019     }
   994     KEEP_MAPS(Parent, BidirGraph);
  1020     //    KEEP_MAPS(Parent, BidirGraph);
   995   };
  1021   };
   996 
  1022 
   997 
  1023 
   998 
  1024 
   999   template<typename Graph, typename Number,
  1025   template<typename Graph, typename Number,
  1104 	else 
  1130 	else 
  1105 	  return (*(res_graph->flow))[e]; 
  1131 	  return (*(res_graph->flow))[e]; 
  1106       }
  1132       }
  1107     };
  1133     };
  1108 
  1134 
  1109     KEEP_MAPS(Parent, ResGraphWrapper);
  1135     //    KEEP_MAPS(Parent, ResGraphWrapper);
  1110   };
  1136   };
  1111 
  1137 
  1112 
  1138 
  1113   /// For blocking flows.
  1139   /// For blocking flows.
  1114 
  1140 
  1166       typename Graph::OutEdgeIt f(*Parent::graph, n);
  1192       typename Graph::OutEdgeIt f(*Parent::graph, n);
  1167       ++f;
  1193       ++f;
  1168       first_out_edges->set(n, f);
  1194       first_out_edges->set(n, f);
  1169     }
  1195     }
  1170 
  1196 
  1171     KEEP_MAPS(Parent, ErasingFirstGraphWrapper);
  1197     //    KEEP_MAPS(Parent, ErasingFirstGraphWrapper);
  1172   };
  1198   };
  1173 
  1199 
  1174   ///@}
  1200   ///@}
  1175 
  1201 
  1176 } //namespace hugo
  1202 } //namespace hugo