1.1 --- a/src/work/marci/merge_node_graph_wrapper.h Tue Sep 28 16:40:55 2004 +0000
1.2 +++ b/src/work/marci/merge_node_graph_wrapper.h Tue Sep 28 17:00:18 2004 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /* -*- C++ -*-
1.5 - * src/hugo/graph_wrapper.h - Part of HUGOlib, a generic C++ optimization library
1.6 + * src/hugo/merge_node_graph_wrapper.h - Part of HUGOlib, a generic C++ optimization library
1.7 *
1.8 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.9 * (Egervary Combinatorial Optimization Research Group, EGRES).
1.10 @@ -14,18 +14,18 @@
1.11 *
1.12 */
1.13
1.14 +#ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H
1.15 +#define HUGO_MERGE_NODE_GRAPH_WRAPPER_H
1.16 +
1.17 #include <hugo/invalid.h>
1.18 #include <hugo/maps.h>
1.19 #include <hugo/map_defines.h>
1.20 #include <hugo/graph_wrapper.h>
1.21 #include <iostream>
1.22
1.23 -#ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H
1.24 -#define HUGO_MERGE_NODE_GRAPH_WRAPPER_H
1.25 -
1.26 namespace hugo {
1.27
1.28 - template <typename Graph1, typename Graph2>
1.29 + template <typename Graph1, typename Graph2, typename Enable=void>
1.30 class MergeNodeGraphWrapper :
1.31 public GraphWrapper<Graph1>, public GraphWrapper<Graph2> {
1.32 typedef GraphWrapper<Graph1> Parent1;
1.33 @@ -37,13 +37,14 @@
1.34 class NodeIt;
1.35 friend class Node;
1.36 friend class NodeIt;
1.37 + template<typename Value> class NodeMap;
1.38
1.39 MergeNodeGraphWrapper(Graph1& _graph1, Graph2& _graph2) :
1.40 Parent1(_graph1), Parent2(_graph2) { }
1.41
1.42 class Node : public Graph1Node, public Graph2Node {
1.43 friend class MergeNodeGraphWrapper<Graph1, Graph2>;
1.44 - //template<typename T> friend class NodeMap;
1.45 + template<typename Value> friend class NodeMap;
1.46 protected:
1.47 bool backward; //true, iff backward
1.48 public:
1.49 @@ -80,13 +81,16 @@
1.50 NodeIt(Invalid i) : Node(i) { }
1.51 NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw) :
1.52 Node(typename Graph1::NodeIt(*_gw.Parent1::graph),
1.53 - typename Graph2::NodeIt(),
1.54 + typename Graph2::Node(),
1.55 false), gw(&_gw) {
1.56 if (*static_cast<Graph1Node*>(this)==INVALID) {
1.57 - *static_cast<Node*>(this)=
1.58 - Node(Graph1Node(INVALID),
1.59 - typename Graph2::NodeIt(*_gw.Parent2::graph),
1.60 - true);
1.61 +// *static_cast<Node*>(this)=
1.62 +// Node(Graph1Node(INVALID),
1.63 +// typename Graph2::NodeIt(*_gw.Parent2::graph),
1.64 +// true);
1.65 + *static_cast<Graph2Node*>(this)=
1.66 + typename Graph2::NodeIt(*_gw.Parent2::graph);
1.67 + backward=true;
1.68 }
1.69 }
1.70 NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw,
1.71 @@ -97,9 +101,12 @@
1.72 *(static_cast<Graph1Node*>(this))=
1.73 ++(typename Graph1::NodeIt(*gw->Parent1::graph, *this));
1.74 if (*static_cast<Graph1Node*>(this)==INVALID) {
1.75 - *static_cast<Node*>(this)=
1.76 - Node(typename Graph1::Node(INVALID),
1.77 - typename Graph2::NodeIt(*gw->Parent2::graph), true);
1.78 +// *static_cast<Node*>(this)=
1.79 +// Node(typename Graph1::Node(INVALID),
1.80 +// typename Graph2::NodeIt(*gw->Parent2::graph), true);
1.81 + *static_cast<Graph2Node*>(this)=
1.82 + typename Graph2::NodeIt(*gw->Parent2::graph);
1.83 + backward=true;
1.84 }
1.85 } else {
1.86 *(static_cast<Graph2Node*>(this))=
1.87 @@ -116,6 +123,53 @@
1.88 return this->Parent2::graph->id(n);
1.89 }
1.90
1.91 + template <typename Value>
1.92 + class NodeMap : public Parent1::template NodeMap<Value>,
1.93 + public Parent2::template NodeMap<Value> {
1.94 + typedef typename Parent1::template NodeMap<Value> ParentMap1;
1.95 + typedef typename Parent2::template NodeMap<Value> ParentMap2;
1.96 + public:
1.97 + NodeMap(const MergeNodeGraphWrapper<Graph1, Graph2>& gw) :
1.98 + ParentMap1(gw),
1.99 + ParentMap2(gw) { }
1.100 + NodeMap(const MergeNodeGraphWrapper<Graph1, Graph2>& gw,
1.101 + const Value& value)
1.102 + : ParentMap1(gw, value),
1.103 + ParentMap2(gw, value) { }
1.104 + NodeMap(const NodeMap& copy)
1.105 + : ParentMap1(copy),
1.106 + ParentMap2(copy) { }
1.107 + template <typename TT>
1.108 + NodeMap(const NodeMap<TT>& copy)
1.109 + : ParentMap1(copy),
1.110 + ParentMap2(copy) { }
1.111 + NodeMap& operator=(const NodeMap& copy) {
1.112 + ParentMap1::operator=(copy);
1.113 + ParentMap2::operator=(copy);
1.114 + return *this;
1.115 + }
1.116 + template <typename TT>
1.117 + NodeMap& operator=(const NodeMap<TT>& copy) {
1.118 + ParentMap1::operator=(copy);
1.119 + ParentMap2::operator=(copy);
1.120 + return *this;
1.121 + }
1.122 + Value operator[](const Node& n) const {
1.123 + if (!n.backward)
1.124 + return ParentMap1::operator[](n);
1.125 + else
1.126 + return ParentMap2::operator[](n);
1.127 + }
1.128 + void set(const Node& n, const Value& value) {
1.129 + if (!n.backward)
1.130 + ParentMap1::set(n, value);
1.131 + else
1.132 + ParentMap2::set(n, value);
1.133 + }
1.134 + using ParentMap1::operator[];
1.135 + using ParentMap2::operator[];
1.136 + };
1.137 +
1.138 };
1.139
1.140 } //namespace hugo
2.1 --- a/src/work/marci/merge_node_graph_wrapper_test.cc Tue Sep 28 16:40:55 2004 +0000
2.2 +++ b/src/work/marci/merge_node_graph_wrapper_test.cc Tue Sep 28 17:00:18 2004 +0000
2.3 @@ -10,17 +10,32 @@
2.4 using namespace hugo;
2.5
2.6 int main() {
2.7 - SmartGraph g;
2.8 - ListGraph h;
2.9 - typedef MergeNodeGraphWrapper<SmartGraph, ListGraph> GW;
2.10 + typedef SmartGraph Graph1;
2.11 + typedef ListGraph Graph2;
2.12 + Graph1 g;
2.13 + Graph2 h;
2.14 + typedef MergeNodeGraphWrapper<Graph1, Graph2> GW;
2.15 GW gw(g, h);
2.16 - g.addNode();
2.17 - g.addNode();
2.18 - g.addNode();
2.19 - h.addNode();
2.20 - h.addNode();
2.21 + Graph1::Node n1=g.addNode();
2.22 + Graph1::Node n2=g.addNode();
2.23 + Graph1::Node n3=g.addNode();
2.24 + Graph2::Node n4=h.addNode();
2.25 + Graph2::Node n5=h.addNode();
2.26 //GW::NodeIt n(gw)
2.27 for (GW::NodeIt n(gw); n!=INVALID; ++n) {
2.28 cout << gw.id(n) << endl;
2.29 }
2.30 +
2.31 + GW::NodeMap<int> nm(gw);
2.32 + int i=0;
2.33 + for (GW::NodeIt n(gw); n!=INVALID; ++n) {
2.34 + ++i;
2.35 + nm.set(n, i);
2.36 + }
2.37 + for (Graph1::NodeIt n(g); n!=INVALID; ++n) {
2.38 + cout << nm[n] << endl;
2.39 + }
2.40 + for (Graph2::NodeIt n(h); n!=INVALID; ++n) {
2.41 + cout << nm[n] << endl;
2.42 + }
2.43 }