COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
05/03/04 12:04:27 (20 years ago)
Author:
marci
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@670
Message:

matching, flows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/work/marci/bipartite_graph_wrapper.h

    r502 r510  
    311311//invalid, 3, invalid)
    312312    template <typename T> class NodeMap;
    313     template <typename T, typename Parent> class EdgeMap;
     313    template <typename T> class EdgeMap;
    314314
    315315//    template <typename T> friend class NodeMap;
     
    386386      friend class GraphWrapper<Graph>;
    387387      friend class stGraphWrapper<Graph>;
    388       template <typename T, typename Parent> friend class EdgeMap;
     388      template <typename T> friend class EdgeMap;
    389389      int spec;
    390390      typename Graph::Node n;
     
    413413      friend std::ostream& operator<< (std::ostream& os, const Edge& i);
    414414      int getSpec() const { return spec; }
     415      typename Graph::Node getNode() const { return n; }
    415416    };
    416417
     
    703704    template<typename T> class NodeMap : public GraphWrapper<Graph>::template NodeMap<T> {
    704705      typedef typename GraphWrapper<Graph>::template NodeMap<T> Parent;
     706    protected:
    705707      T s_value, t_value;
    706708    public:
     
    715717        case 0:
    716718          return Parent::operator[](n);
    717           break;
    718719        case 1:
    719720          return s_value;
    720           break;
    721721        case 2:
    722722        default:
    723723          return t_value;
    724           break;
    725724        }
    726725      }
     
    741740    };
    742741
    743     template<typename T,
    744              typename Parent=
    745              typename GraphWrapper<Graph>::template EdgeMap<T> >
    746     class EdgeMap : public Parent {
    747       //typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
     742    /// This class is to wrap a node-map of \c Graph and two variables
     743    /// storing values for \c S_NODE and \c T_NODE to a node-map of
     744    /// stGraphWrapper<Graph>.
     745    template<typename NM> class NodeMapWrapper {
     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:
    748786      typename GraphWrapper<Graph>::template NodeMap<T> node_value;
    749787    public:
     
    756794        case 0:
    757795          return Parent::operator[](e);
    758           break;
    759796        case 1:
    760797          return node_value[e.n];
    761           break;
    762798        case 2:
    763799        default:
    764800          return node_value[e.n];
    765           break;
    766801        }
    767802      }
     
    782817    };
    783818
    784 //     template<typename T> class EdgeMap : public GraphWrapper<Graph>::template EdgeMap<T> {
    785 //       typedef typename GraphWrapper<Graph>::template EdgeMap<T> Parent;
    786 //       typename GraphWrapper<Graph>::template NodeMap<T> node_value;
    787 //     public:
    788 //       EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G),
    789 //                                               node_value(_G) { }
    790 //       EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a),
    791 //                                                    node_value(_G, a) { }
    792 //       T operator[](const Edge& e) const {
    793 //      switch (e.spec) {
    794 //      case 0:
    795 //        return Parent::operator[](e);
    796 //        break;
    797 //      case 1:
    798 //        return node_value[e.n];
    799 //        break;
    800 //      case 2:
    801 //      default:
    802 //        return node_value[e.n];
    803 //        break;
    804 //      }
    805 //       }
    806 //       void set(const Edge& e, T t) {
    807 //      switch (e.spec) {
    808 //      case 0:
    809 //        GraphWrapper<Graph>::template EdgeMap<T>::set(e, t);
    810 //        break;
    811 //      case 1:
    812 //        node_value.set(e.n, t);
    813 //        break;
    814 //      case 2:
    815 //      default:
    816 //        node_value.set(e.n, t);
    817 //        break;
    818 //      }
    819 //       }
    820 //     };
     819    /// This class is to wrap an edge-map and a node-map of \c Graph
     820    /// to an edge-map of stGraphWrapper<Graph>.
     821    template<typename EM, typename NM>
     822    class EdgeMapWrapper {
     823    public:
     824      typedef Edge KeyType;
     825      typedef typename EM::ValueType ValueType;
     826    protected:
     827      EM* em;
     828      NM* nm;
     829    public:
     830      EdgeMapWrapper(EM& _em, NM& _nm) : em(&_em), nm(&_nm) { }
     831      ValueType operator[](const Edge& e) const {
     832        switch (e.getSpec()) {
     833        case 0:
     834          return (*em)[e];
     835        case 1:
     836          return (*nm)[e.getNode()];
     837        case 2:
     838        default:
     839          return (*nm)[e.getNode()];
     840        }
     841      }
     842      void set(const Edge& e, ValueType t) {
     843        switch (e.getSpec()) {
     844        case 0:
     845          em->set(e, t);
     846          break;
     847        case 1:
     848          nm->set(e.getNode(), t);
     849          break;
     850        case 2:
     851        default:
     852          nm->set(e.getNode(), t);
     853          break;
     854        }
     855      }
     856    };
     857
    821858
    822859//  template<typename G>
     
    841878
    842879
    843 #endif //HUGO_GRAPH_WRAPPER_H
    844 
     880#endif //HUGO_BIPARTITE_GRAPH_WRAPPER_H
     881
Note: See TracChangeset for help on using the changeset viewer.