src/work/marci/bipartite_graph_wrapper.h
changeset 551 d167149bde95
parent 502 1b41ebb5fee5
child 555 995bc1f1a3ce
equal deleted inserted replaced
7:160841b07998 8:224bccbacaab
   308 //(first, 0, invalid) ...
   308 //(first, 0, invalid) ...
   309 //(invalid, 1, vmi)
   309 //(invalid, 1, vmi)
   310 //(invalid, 2, vmi)
   310 //(invalid, 2, vmi)
   311 //invalid, 3, invalid)
   311 //invalid, 3, invalid)
   312     template <typename T> class NodeMap;
   312     template <typename T> class NodeMap;
   313     template <typename T, typename Parent> class EdgeMap;
   313     template <typename T> class EdgeMap;
   314 
   314 
   315 //    template <typename T> friend class NodeMap;
   315 //    template <typename T> friend class NodeMap;
   316 //    template <typename T> friend class EdgeMap;
   316 //    template <typename T> friend class EdgeMap;
   317 
   317 
   318     ///\todo FIXME ezt majd static-ra kell javitani
   318     ///\todo FIXME ezt majd static-ra kell javitani
   383     };
   383     };
   384 
   384 
   385     class Edge : public Graph::Edge {
   385     class Edge : public Graph::Edge {
   386       friend class GraphWrapper<Graph>;
   386       friend class GraphWrapper<Graph>;
   387       friend class stGraphWrapper<Graph>;
   387       friend class stGraphWrapper<Graph>;
   388       template <typename T, typename Parent> friend class EdgeMap;
   388       template <typename T> friend class EdgeMap;
   389       int spec;
   389       int spec;
   390       typename Graph::Node n;
   390       typename Graph::Node n;
   391     public:
   391     public:
   392       Edge() { }
   392       Edge() { }
   393       Edge(const typename Graph::Edge& _e, int _spec, 
   393       Edge(const typename Graph::Edge& _e, int _spec, 
   410 //      template<typename G> 
   410 //      template<typename G> 
   411 //      friend std::ostream& 
   411 //      friend std::ostream& 
   412 //      operator<<(std::ostream& os, const typename stGraphWrapper<G>::Edge& i); 
   412 //      operator<<(std::ostream& os, const typename stGraphWrapper<G>::Edge& i); 
   413       friend std::ostream& operator<< (std::ostream& os, const Edge& i);
   413       friend std::ostream& operator<< (std::ostream& os, const Edge& i);
   414       int getSpec() const { return spec; }
   414       int getSpec() const { return spec; }
       
   415       typename Graph::Node getNode() const { return n; }
   415     };
   416     };
   416 
   417 
   417     class OutEdgeIt { 
   418     class OutEdgeIt { 
   418       friend class GraphWrapper<Graph>;
   419       friend class GraphWrapper<Graph>;
   419       friend class stGraphWrapper<Graph>;
   420       friend class stGraphWrapper<Graph>;
   700   
   701   
   701 //    void clear() const { this->graph->clear(); }
   702 //    void clear() const { this->graph->clear(); }
   702     
   703     
   703     template<typename T> class NodeMap : public GraphWrapper<Graph>::template NodeMap<T> { 
   704     template<typename T> class NodeMap : public GraphWrapper<Graph>::template NodeMap<T> { 
   704       typedef typename GraphWrapper<Graph>::template NodeMap<T> Parent;
   705       typedef typename GraphWrapper<Graph>::template NodeMap<T> Parent;
       
   706     protected:
   705       T s_value, t_value;
   707       T s_value, t_value;
   706     public:
   708     public:
   707       NodeMap(const stGraphWrapper<Graph>& _G) :  Parent(_G), 
   709       NodeMap(const stGraphWrapper<Graph>& _G) :  Parent(_G), 
   708 						  s_value(), 
   710 						  s_value(), 
   709 						  t_value() { }
   711 						  t_value() { }
   712 						      t_value(a) { }
   714 						      t_value(a) { }
   713       T operator[](const Node& n) const { 
   715       T operator[](const Node& n) const { 
   714 	switch (n.spec) {
   716 	switch (n.spec) {
   715 	case 0: 
   717 	case 0: 
   716 	  return Parent::operator[](n);
   718 	  return Parent::operator[](n);
   717 	  break;
       
   718 	case 1:
   719 	case 1:
   719 	  return s_value;
   720 	  return s_value;
   720 	  break;
       
   721 	case 2: 
   721 	case 2: 
   722 	default:
   722 	default:
   723 	  return t_value;
   723 	  return t_value;
   724 	  break;
       
   725 	}
   724 	}
   726       }
   725       }
   727       void set(const Node& n, T t) { 
   726       void set(const Node& n, T t) { 
   728 	switch (n.spec) {
   727 	switch (n.spec) {
   729 	case 0: 
   728 	case 0: 
   738 	  break;
   737 	  break;
   739 	}
   738 	}
   740       }
   739       }
   741     };
   740     };
   742 
   741 
   743     template<typename T, 
   742     /// This class is to wrap a node-map of \c Graph and two variables 
   744 	     typename Parent=
   743     /// storing values for \c S_NODE and \c T_NODE to a node-map of 
   745 	     typename GraphWrapper<Graph>::template EdgeMap<T> > 
   744     /// stGraphWrapper<Graph>.
   746     class EdgeMap : public Parent { 
   745     template<typename NM> class NodeMapWrapper { 
   747       //typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
   746     public:
       
   747       typedef Node KeyType;
       
   748       typedef typename NM::ValueType ValueType;
       
   749     protected:
       
   750       NM* nm;
       
   751       ValueType* s_value, t_value;
       
   752     public:
       
   753       NodeMapWrapper(NM& _nm, ValueType& _s_value, ValueType& _t_value) : 
       
   754 	nm(&_nm), s_value(&_s_value), t_value(&_t_value) { }
       
   755       ValueType operator[](const Node& n) const { 
       
   756 	switch (n.getSpec()) {
       
   757 	case 0: 
       
   758 	  return (*nm)[n];
       
   759 	case 1:
       
   760 	  return *s_value;
       
   761 	case 2: 
       
   762 	default:
       
   763 	  return *t_value;
       
   764 	}
       
   765       }
       
   766       void set(const Node& n, ValueType t) { 
       
   767 	switch (n.getSpec()) {
       
   768 	case 0: 
       
   769 	  nm->set(n, t);
       
   770 	  break;
       
   771 	case 1:
       
   772 	  *s_value=t;
       
   773 	  break;
       
   774 	case 2:
       
   775 	default:
       
   776 	  *t_value=t;
       
   777 	  break;
       
   778 	}
       
   779       }
       
   780     };
       
   781 
       
   782     template<typename T> 
       
   783     class EdgeMap : public GraphWrapper<Graph>::template EdgeMap<T> { 
       
   784       typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
       
   785     protected:
   748       typename GraphWrapper<Graph>::template NodeMap<T> node_value;
   786       typename GraphWrapper<Graph>::template NodeMap<T> node_value;
   749     public:
   787     public:
   750       EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G), 
   788       EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G), 
   751 						 node_value(_G) { }
   789 						 node_value(_G) { }
   752       EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
   790       EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
   753 						      node_value(_G, a) { }
   791 						      node_value(_G, a) { }
   754       T operator[](const Edge& e) const { 
   792       T operator[](const Edge& e) const { 
   755 	switch (e.spec) {
   793 	switch (e.spec) {
   756 	case 0: 
   794 	case 0: 
   757 	  return Parent::operator[](e);
   795 	  return Parent::operator[](e);
   758 	  break;
       
   759 	case 1:
   796 	case 1:
   760 	  return node_value[e.n];
   797 	  return node_value[e.n];
   761 	  break;
       
   762 	case 2:
   798 	case 2:
   763 	default:
   799 	default:
   764 	  return node_value[e.n];
   800 	  return node_value[e.n];
   765 	  break;
       
   766 	}
   801 	}
   767       }
   802       }
   768       void set(const Edge& e, T t) { 
   803       void set(const Edge& e, T t) { 
   769 	switch (e.spec) {
   804 	switch (e.spec) {
   770 	case 0: 
   805 	case 0: 
   779 	  break;
   814 	  break;
   780 	}
   815 	}
   781       }
   816       }
   782     };
   817     };
   783 
   818 
   784 //     template<typename T> class EdgeMap : public GraphWrapper<Graph>::template EdgeMap<T> { 
   819     /// This class is to wrap an edge-map and a node-map of \c Graph 
   785 //       typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
   820     /// to an edge-map of stGraphWrapper<Graph>.
   786 //       typename GraphWrapper<Graph>::template NodeMap<T> node_value;
   821     template<typename EM, typename NM> 
   787 //     public:
   822     class EdgeMapWrapper {
   788 //       EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G), 
   823     public: 
   789 // 						 node_value(_G) { }
   824       typedef Edge KeyType;
   790 //       EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a), 
   825       typedef typename EM::ValueType ValueType;
   791 // 						      node_value(_G, a) { }
   826     protected:
   792 //       T operator[](const Edge& e) const { 
   827       EM* em;
   793 // 	switch (e.spec) {
   828       NM* nm;
   794 // 	case 0: 
   829     public:
   795 // 	  return Parent::operator[](e);
   830       EdgeMapWrapper(EM& _em, NM& _nm) : em(&_em), nm(&_nm) { }
   796 // 	  break;
   831       ValueType operator[](const Edge& e) const { 
   797 // 	case 1:
   832 	switch (e.getSpec()) {
   798 // 	  return node_value[e.n];
   833 	case 0: 
   799 // 	  break;
   834 	  return (*em)[e];
   800 // 	case 2:
   835 	case 1:
   801 // 	default:
   836 	  return (*nm)[e.getNode()];
   802 // 	  return node_value[e.n];
   837 	case 2:
   803 // 	  break;
   838 	default:
   804 // 	}
   839 	  return (*nm)[e.getNode()];
   805 //       }
   840 	}
   806 //       void set(const Edge& e, T t) { 
   841       }
   807 // 	switch (e.spec) {
   842       void set(const Edge& e, ValueType t) { 
   808 // 	case 0: 
   843 	switch (e.getSpec()) {
   809 // 	  GraphWrapper<Graph>::template EdgeMap<T>::set(e, t);
   844 	case 0: 
   810 // 	  break;
   845 	  em->set(e, t);
   811 // 	case 1:
   846 	  break;
   812 // 	  node_value.set(e.n, t);
   847 	case 1:
   813 // 	  break;
   848 	  nm->set(e.getNode(), t);
   814 // 	case 2:
   849 	  break;
   815 // 	default:
   850 	case 2:
   816 // 	  node_value.set(e.n, t);
   851 	default:
   817 // 	  break;
   852 	  nm->set(e.getNode(), t);
   818 // 	}
   853 	  break;
   819 //       }
   854 	}
   820 //     };
   855       }
       
   856     };
       
   857 
   821 
   858 
   822 //  template<typename G> 
   859 //  template<typename G> 
   823     friend std::ostream& 
   860     friend std::ostream& 
   824     operator<<(std::ostream& os, const /*typename stGraphWrapper<Graph>::*/Node& i) { 
   861     operator<<(std::ostream& os, const /*typename stGraphWrapper<Graph>::*/Node& i) { 
   825       os << "(node: " << typename Graph::Node(i) << " spec: " << i.spec <<")"; 
   862       os << "(node: " << typename Graph::Node(i) << " spec: " << i.spec <<")"; 
   838   ///@}
   875   ///@}
   839 
   876 
   840 } //namespace hugo
   877 } //namespace hugo
   841 
   878 
   842 
   879 
   843 #endif //HUGO_GRAPH_WRAPPER_H
   880 #endif //HUGO_BIPARTITE_GRAPH_WRAPPER_H
   844 
   881