# HG changeset patch # User marci # Date 1096379139 0 # Node ID 751ed145bdae5d27edc576360245028ff96b6c79 # Parent 174490f545f803d99ff251984b393d2f3dbf7a45 beginning of a modular, generic merge_graph_wrapper... diff -r 174490f545f8 -r 751ed145bdae src/work/marci/makefile --- a/src/work/marci/makefile Tue Sep 28 10:32:23 2004 +0000 +++ b/src/work/marci/makefile Tue Sep 28 13:45:39 2004 +0000 @@ -4,7 +4,7 @@ INCLUDEDIRS ?= -I../{jacint,marci,alpar,klao,akos,athos} -I../.. -I.. -I$(BOOSTROOT) LEDABINARIES = leda_graph_demo leda_bfs_dfs max_bipartite_matching_demo -BINARIES = sub_graph_wrapper_demo.cc graph_wrapper_time max_flow_demo iterator_bfs_demo macro_test lg_vs_sg_vs_sg bfsit_vs_byhand bipartite_graph_wrapper_test bipartite_matching_demo top_sort_test max_flow_1 proba7 proba10 +BINARIES = merge_node_graph_wrapper_test#sub_graph_wrapper_demo.cc graph_wrapper_time max_flow_demo iterator_bfs_demo macro_test lg_vs_sg_vs_sg bfsit_vs_byhand bipartite_graph_wrapper_test bipartite_matching_demo top_sort_test max_flow_1 proba7 proba10 #BINARIES = preflow_bug #gw_vs_not preflow_demo_boost edmonds_karp_demo_boost preflow_demo_jacint preflow_demo_athos edmonds_karp_demo_alpar preflow_demo_leda diff -r 174490f545f8 -r 751ed145bdae src/work/marci/merge_node_graph_wrapper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/merge_node_graph_wrapper.h Tue Sep 28 13:45:39 2004 +0000 @@ -0,0 +1,123 @@ +/* -*- C++ -*- + * src/hugo/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). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#include +#include +#include +#include +#include + +#ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H +#define HUGO_MERGE_NODE_GRAPH_WRAPPER_H + +namespace hugo { + + template + class MergeNodeGraphWrapper : + public GraphWrapper, public GraphWrapper { + typedef GraphWrapper Parent1; + typedef GraphWrapper Parent2; + typedef typename GraphWrapper::Node Graph1Node; + typedef typename GraphWrapper::Node Graph2Node; + public: + class Node; + class NodeIt; + friend class Node; + friend class NodeIt; + + MergeNodeGraphWrapper(Graph1& _graph1, Graph2& _graph2) : + Parent1(_graph1), Parent2(_graph2) { } + + class Node : public Graph1Node, public Graph2Node { + friend class MergeNodeGraphWrapper; + //template friend class NodeMap; + protected: + bool backward; //true, iff backward + public: + Node() { } + /// \todo =false is needed, or causes problems? + /// If \c _backward is false, then we get an edge corresponding to the + /// original one, otherwise its oppositely directed pair is obtained. + Node(const Graph1Node& n1, + const Graph2Node& n2, bool _backward) : + Graph1Node(n1), Graph2Node(n2), backward(_backward) { } + Node(Invalid i) : Graph1Node(i), Graph2Node(i), backward(true) { } + bool operator==(const Node& v) const { + return (this->backward==v.backward && + static_cast(*this)== + static_cast(v) && + static_cast(*this)== + static_cast(v)); + } + bool operator!=(const Node& v) const { + return (this->backward!=v.backward || + static_cast(*this)!= + static_cast(v) || + static_cast(*this)!= + static_cast(v)); + } + }; + + class NodeIt : public Node { + friend class MergeNodeGraphWrapper; + protected: + const MergeNodeGraphWrapper* gw; + public: + NodeIt() { } + NodeIt(Invalid i) : Node(i) { } + NodeIt(const MergeNodeGraphWrapper& _gw) : + Node(typename Graph1::NodeIt(*_gw.Parent1::graph), + typename Graph2::NodeIt(), + false), gw(&_gw) { + if (*static_cast(this)==INVALID) { + *static_cast(this)= + Node(Graph1Node(INVALID), + typename Graph2::NodeIt(*_gw.Parent2::graph), + true); + } + } + NodeIt(const MergeNodeGraphWrapper& _gw, + const Node& n) : + Node(n), gw(&_gw) { } + NodeIt& operator++() { + if (!this->backward) { + *(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); + } + } else { + *(static_cast(this))= + ++(typename Graph2::NodeIt(*gw->Parent2::graph, *this)); + } + return *this; + } + }; + + int id(const Node& n) const { + if (!n.backward) + return this->Parent1::graph->id(n); + else + return this->Parent2::graph->id(n); + } + + }; + +} //namespace hugo + +#endif //HUGO_MERGE_NODE_GRAPH_WRAPPER_H diff -r 174490f545f8 -r 751ed145bdae src/work/marci/merge_node_graph_wrapper_test.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/merge_node_graph_wrapper_test.cc Tue Sep 28 13:45:39 2004 +0000 @@ -0,0 +1,26 @@ +#include + +#include +#include +#include + +using std::cout; +using std::endl; + +using namespace hugo; + +int main() { + SmartGraph g; + ListGraph h; + typedef MergeNodeGraphWrapper GW; + GW gw(g, h); + g.addNode(); + g.addNode(); + g.addNode(); + h.addNode(); + h.addNode(); + //GW::NodeIt n(gw) + for (GW::NodeIt n(gw); n!=INVALID; ++n) { + cout << gw.id(n) << endl; + } +}