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