COIN-OR::LEMON - Graph Library

Changeset 917:ffb8f0cbcb57 in lemon-0.x


Ignore:
Timestamp:
09/28/04 19:00:18 (19 years ago)
Author:
marci
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1228
Message:

merge_node_graph_wrapper::nodemap

Location:
src/work/marci
Files:
2 edited

Legend:

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

    r915 r917  
    11/* -*- C++ -*-
    2  * src/hugo/graph_wrapper.h - Part of HUGOlib, a generic C++ optimization library
     2 * src/hugo/merge_node_graph_wrapper.h - Part of HUGOlib, a generic C++ optimization library
    33 *
    44 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     
    1515 */
    1616
     17#ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H
     18#define HUGO_MERGE_NODE_GRAPH_WRAPPER_H
     19
    1720#include <hugo/invalid.h>
    1821#include <hugo/maps.h>
     
    2124#include <iostream>
    2225
    23 #ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H
    24 #define HUGO_MERGE_NODE_GRAPH_WRAPPER_H
    25 
    2626namespace hugo {
    2727
    28   template <typename Graph1, typename Graph2>
     28  template <typename Graph1, typename Graph2, typename Enable=void>
    2929  class MergeNodeGraphWrapper :
    3030    public GraphWrapper<Graph1>, public GraphWrapper<Graph2> {
     
    3838    friend class Node;
    3939    friend class NodeIt;
     40    template<typename Value> class NodeMap;
    4041
    4142    MergeNodeGraphWrapper(Graph1& _graph1, Graph2& _graph2) :
     
    4445    class Node : public Graph1Node, public Graph2Node {
    4546      friend class MergeNodeGraphWrapper<Graph1, Graph2>;
    46       //template<typename T> friend class NodeMap;
     47      template<typename Value> friend class NodeMap;
    4748    protected:
    4849      bool backward; //true, iff backward
     
    8182      NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw) :
    8283        Node(typename Graph1::NodeIt(*_gw.Parent1::graph),
    83              typename Graph2::NodeIt(),
     84             typename Graph2::Node(),
    8485             false), gw(&_gw) {
    8586        if (*static_cast<Graph1Node*>(this)==INVALID) {
    86           *static_cast<Node*>(this)=
    87             Node(Graph1Node(INVALID),
    88                  typename Graph2::NodeIt(*_gw.Parent2::graph),
    89                  true);
     87//        *static_cast<Node*>(this)=
     88//          Node(Graph1Node(INVALID),
     89//               typename Graph2::NodeIt(*_gw.Parent2::graph),
     90//               true);
     91          *static_cast<Graph2Node*>(this)=
     92            typename Graph2::NodeIt(*_gw.Parent2::graph);
     93          backward=true;
    9094        }
    9195      }
     
    98102            ++(typename Graph1::NodeIt(*gw->Parent1::graph, *this));
    99103          if (*static_cast<Graph1Node*>(this)==INVALID) {
    100             *static_cast<Node*>(this)=
    101               Node(typename Graph1::Node(INVALID),
    102                    typename Graph2::NodeIt(*gw->Parent2::graph), true);
     104//          *static_cast<Node*>(this)=
     105//            Node(typename Graph1::Node(INVALID),
     106//                 typename Graph2::NodeIt(*gw->Parent2::graph), true);
     107            *static_cast<Graph2Node*>(this)=
     108              typename Graph2::NodeIt(*gw->Parent2::graph);
     109            backward=true;
    103110          }
    104111        } else {
     
    117124    }
    118125
     126    template <typename Value>
     127    class NodeMap : public Parent1::template NodeMap<Value>,
     128                    public Parent2::template NodeMap<Value> {
     129      typedef typename Parent1::template NodeMap<Value> ParentMap1;
     130      typedef typename Parent2::template NodeMap<Value> ParentMap2;
     131    public:
     132      NodeMap(const MergeNodeGraphWrapper<Graph1, Graph2>& gw) :
     133        ParentMap1(gw),
     134        ParentMap2(gw) { }
     135      NodeMap(const MergeNodeGraphWrapper<Graph1, Graph2>& gw,
     136              const Value& value)
     137        : ParentMap1(gw, value),
     138          ParentMap2(gw, value) { }
     139      NodeMap(const NodeMap& copy)
     140        : ParentMap1(copy),
     141          ParentMap2(copy) { }
     142      template <typename TT>
     143      NodeMap(const NodeMap<TT>& copy)
     144        : ParentMap1(copy),
     145          ParentMap2(copy) { }
     146      NodeMap& operator=(const NodeMap& copy) {
     147        ParentMap1::operator=(copy);
     148        ParentMap2::operator=(copy);
     149        return *this;
     150      }
     151      template <typename TT>
     152      NodeMap& operator=(const NodeMap<TT>& copy) {
     153        ParentMap1::operator=(copy);
     154        ParentMap2::operator=(copy);
     155        return *this;
     156      }
     157      Value operator[](const Node& n) const {
     158        if (!n.backward)
     159          return ParentMap1::operator[](n);
     160        else
     161          return ParentMap2::operator[](n);
     162      }
     163      void set(const Node& n, const Value& value) {
     164        if (!n.backward)
     165          ParentMap1::set(n, value);
     166        else
     167          ParentMap2::set(n, value);
     168      }
     169      using ParentMap1::operator[];
     170      using ParentMap2::operator[];
     171    };
     172   
    119173  };
    120174
  • src/work/marci/merge_node_graph_wrapper_test.cc

    r915 r917  
    1111
    1212int main() {
    13   SmartGraph g;
    14   ListGraph h;
    15   typedef MergeNodeGraphWrapper<SmartGraph, ListGraph> GW;
     13  typedef SmartGraph Graph1;
     14  typedef ListGraph Graph2;
     15  Graph1 g;
     16  Graph2 h;
     17  typedef MergeNodeGraphWrapper<Graph1, Graph2> GW;
    1618  GW gw(g, h);
    17   g.addNode();
    18   g.addNode();
    19   g.addNode();
    20   h.addNode();
    21   h.addNode();
     19  Graph1::Node n1=g.addNode();
     20  Graph1::Node n2=g.addNode();
     21  Graph1::Node n3=g.addNode();
     22  Graph2::Node n4=h.addNode();
     23  Graph2::Node n5=h.addNode();
    2224  //GW::NodeIt n(gw)
    2325  for (GW::NodeIt n(gw); n!=INVALID; ++n) {
    2426    cout << gw.id(n) << endl;
    2527  }
     28
     29  GW::NodeMap<int> nm(gw);
     30  int i=0;
     31  for (GW::NodeIt n(gw); n!=INVALID; ++n) {
     32    ++i;
     33    nm.set(n, i);
     34  }
     35  for (Graph1::NodeIt n(g); n!=INVALID; ++n) {
     36    cout << nm[n] << endl;
     37  }
     38  for (Graph2::NodeIt n(h); n!=INVALID; ++n) {
     39    cout << nm[n] << endl;
     40  }
    2641}
Note: See TracChangeset for help on using the changeset viewer.