# HG changeset patch # User marci # Date 1096390818 0 # Node ID ffb8f0cbcb577024e71ba8ce0cedd4c0662f5c38 # Parent c0734a8c282c395018afc9aa05c47ed2d4a16c15 merge_node_graph_wrapper::nodemap diff -r c0734a8c282c -r ffb8f0cbcb57 src/work/marci/merge_node_graph_wrapper.h --- a/src/work/marci/merge_node_graph_wrapper.h Tue Sep 28 16:40:55 2004 +0000 +++ b/src/work/marci/merge_node_graph_wrapper.h Tue Sep 28 17:00:18 2004 +0000 @@ -1,5 +1,5 @@ /* -*- C++ -*- - * src/hugo/graph_wrapper.h - Part of HUGOlib, a generic C++ optimization library + * src/hugo/merge_node_graph_wrapper.h - Part of HUGOlib, a generic C++ optimization library * * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Combinatorial Optimization Research Group, EGRES). @@ -14,18 +14,18 @@ * */ +#ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H +#define HUGO_MERGE_NODE_GRAPH_WRAPPER_H + #include #include #include #include #include -#ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H -#define HUGO_MERGE_NODE_GRAPH_WRAPPER_H - namespace hugo { - template + template class MergeNodeGraphWrapper : public GraphWrapper, public GraphWrapper { typedef GraphWrapper Parent1; @@ -37,13 +37,14 @@ class NodeIt; friend class Node; friend class NodeIt; + template class NodeMap; MergeNodeGraphWrapper(Graph1& _graph1, Graph2& _graph2) : Parent1(_graph1), Parent2(_graph2) { } class Node : public Graph1Node, public Graph2Node { friend class MergeNodeGraphWrapper; - //template friend class NodeMap; + template friend class NodeMap; protected: bool backward; //true, iff backward public: @@ -80,13 +81,16 @@ NodeIt(Invalid i) : Node(i) { } NodeIt(const MergeNodeGraphWrapper& _gw) : Node(typename Graph1::NodeIt(*_gw.Parent1::graph), - typename Graph2::NodeIt(), + typename Graph2::Node(), false), gw(&_gw) { if (*static_cast(this)==INVALID) { - *static_cast(this)= - Node(Graph1Node(INVALID), - typename Graph2::NodeIt(*_gw.Parent2::graph), - true); +// *static_cast(this)= +// Node(Graph1Node(INVALID), +// typename Graph2::NodeIt(*_gw.Parent2::graph), +// true); + *static_cast(this)= + typename Graph2::NodeIt(*_gw.Parent2::graph); + backward=true; } } NodeIt(const MergeNodeGraphWrapper& _gw, @@ -97,9 +101,12 @@ *(static_cast(this))= ++(typename Graph1::NodeIt(*gw->Parent1::graph, *this)); if (*static_cast(this)==INVALID) { - *static_cast(this)= - Node(typename Graph1::Node(INVALID), - typename Graph2::NodeIt(*gw->Parent2::graph), true); +// *static_cast(this)= +// Node(typename Graph1::Node(INVALID), +// typename Graph2::NodeIt(*gw->Parent2::graph), true); + *static_cast(this)= + typename Graph2::NodeIt(*gw->Parent2::graph); + backward=true; } } else { *(static_cast(this))= @@ -116,6 +123,53 @@ return this->Parent2::graph->id(n); } + template + class NodeMap : public Parent1::template NodeMap, + public Parent2::template NodeMap { + typedef typename Parent1::template NodeMap ParentMap1; + typedef typename Parent2::template NodeMap ParentMap2; + public: + NodeMap(const MergeNodeGraphWrapper& gw) : + ParentMap1(gw), + ParentMap2(gw) { } + NodeMap(const MergeNodeGraphWrapper& gw, + const Value& value) + : ParentMap1(gw, value), + ParentMap2(gw, value) { } + NodeMap(const NodeMap& copy) + : ParentMap1(copy), + ParentMap2(copy) { } + template + NodeMap(const NodeMap& copy) + : ParentMap1(copy), + ParentMap2(copy) { } + NodeMap& operator=(const NodeMap& copy) { + ParentMap1::operator=(copy); + ParentMap2::operator=(copy); + return *this; + } + template + NodeMap& operator=(const NodeMap& copy) { + ParentMap1::operator=(copy); + ParentMap2::operator=(copy); + return *this; + } + Value operator[](const Node& n) const { + if (!n.backward) + return ParentMap1::operator[](n); + else + return ParentMap2::operator[](n); + } + void set(const Node& n, const Value& value) { + if (!n.backward) + ParentMap1::set(n, value); + else + ParentMap2::set(n, value); + } + using ParentMap1::operator[]; + using ParentMap2::operator[]; + }; + }; } //namespace hugo diff -r c0734a8c282c -r ffb8f0cbcb57 src/work/marci/merge_node_graph_wrapper_test.cc --- a/src/work/marci/merge_node_graph_wrapper_test.cc Tue Sep 28 16:40:55 2004 +0000 +++ b/src/work/marci/merge_node_graph_wrapper_test.cc Tue Sep 28 17:00:18 2004 +0000 @@ -10,17 +10,32 @@ using namespace hugo; int main() { - SmartGraph g; - ListGraph h; - typedef MergeNodeGraphWrapper GW; + typedef SmartGraph Graph1; + typedef ListGraph Graph2; + Graph1 g; + Graph2 h; + typedef MergeNodeGraphWrapper GW; GW gw(g, h); - g.addNode(); - g.addNode(); - g.addNode(); - h.addNode(); - h.addNode(); + Graph1::Node n1=g.addNode(); + Graph1::Node n2=g.addNode(); + Graph1::Node n3=g.addNode(); + Graph2::Node n4=h.addNode(); + Graph2::Node n5=h.addNode(); //GW::NodeIt n(gw) for (GW::NodeIt n(gw); n!=INVALID; ++n) { cout << gw.id(n) << endl; } + + GW::NodeMap nm(gw); + int i=0; + for (GW::NodeIt n(gw); n!=INVALID; ++n) { + ++i; + nm.set(n, i); + } + for (Graph1::NodeIt n(g); n!=INVALID; ++n) { + cout << nm[n] << endl; + } + for (Graph2::NodeIt n(h); n!=INVALID; ++n) { + cout << nm[n] << endl; + } }