beginning of a modular, generic merge_graph_wrapper...
1.1 --- a/src/work/marci/makefile Tue Sep 28 10:32:23 2004 +0000
1.2 +++ b/src/work/marci/makefile Tue Sep 28 13:45:39 2004 +0000
1.3 @@ -4,7 +4,7 @@
1.4 INCLUDEDIRS ?= -I../{jacint,marci,alpar,klao,akos,athos} -I../.. -I.. -I$(BOOSTROOT)
1.5
1.6 LEDABINARIES = leda_graph_demo leda_bfs_dfs max_bipartite_matching_demo
1.7 -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
1.8 +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
1.9 #BINARIES = preflow_bug
1.10 #gw_vs_not preflow_demo_boost edmonds_karp_demo_boost preflow_demo_jacint preflow_demo_athos edmonds_karp_demo_alpar preflow_demo_leda
1.11
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/work/marci/merge_node_graph_wrapper.h Tue Sep 28 13:45:39 2004 +0000
2.3 @@ -0,0 +1,123 @@
2.4 +/* -*- C++ -*-
2.5 + * src/hugo/graph_wrapper.h - Part of HUGOlib, a generic C++ optimization library
2.6 + *
2.7 + * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
2.8 + * (Egervary Combinatorial Optimization Research Group, EGRES).
2.9 + *
2.10 + * Permission to use, modify and distribute this software is granted
2.11 + * provided that this copyright notice appears in all copies. For
2.12 + * precise terms see the accompanying LICENSE file.
2.13 + *
2.14 + * This software is provided "AS IS" with no warranty of any kind,
2.15 + * express or implied, and with no claim as to its suitability for any
2.16 + * purpose.
2.17 + *
2.18 + */
2.19 +
2.20 +#include <hugo/invalid.h>
2.21 +#include <hugo/maps.h>
2.22 +#include <hugo/map_defines.h>
2.23 +#include <hugo/graph_wrapper.h>
2.24 +#include <iostream>
2.25 +
2.26 +#ifndef HUGO_MERGE_NODE_GRAPH_WRAPPER_H
2.27 +#define HUGO_MERGE_NODE_GRAPH_WRAPPER_H
2.28 +
2.29 +namespace hugo {
2.30 +
2.31 + template <typename Graph1, typename Graph2>
2.32 + class MergeNodeGraphWrapper :
2.33 + public GraphWrapper<Graph1>, public GraphWrapper<Graph2> {
2.34 + typedef GraphWrapper<Graph1> Parent1;
2.35 + typedef GraphWrapper<Graph2> Parent2;
2.36 + typedef typename GraphWrapper<Graph1>::Node Graph1Node;
2.37 + typedef typename GraphWrapper<Graph2>::Node Graph2Node;
2.38 + public:
2.39 + class Node;
2.40 + class NodeIt;
2.41 + friend class Node;
2.42 + friend class NodeIt;
2.43 +
2.44 + MergeNodeGraphWrapper(Graph1& _graph1, Graph2& _graph2) :
2.45 + Parent1(_graph1), Parent2(_graph2) { }
2.46 +
2.47 + class Node : public Graph1Node, public Graph2Node {
2.48 + friend class MergeNodeGraphWrapper<Graph1, Graph2>;
2.49 + //template<typename T> friend class NodeMap;
2.50 + protected:
2.51 + bool backward; //true, iff backward
2.52 + public:
2.53 + Node() { }
2.54 + /// \todo =false is needed, or causes problems?
2.55 + /// If \c _backward is false, then we get an edge corresponding to the
2.56 + /// original one, otherwise its oppositely directed pair is obtained.
2.57 + Node(const Graph1Node& n1,
2.58 + const Graph2Node& n2, bool _backward) :
2.59 + Graph1Node(n1), Graph2Node(n2), backward(_backward) { }
2.60 + Node(Invalid i) : Graph1Node(i), Graph2Node(i), backward(true) { }
2.61 + bool operator==(const Node& v) const {
2.62 + return (this->backward==v.backward &&
2.63 + static_cast<Graph1Node>(*this)==
2.64 + static_cast<Graph1Node>(v) &&
2.65 + static_cast<Graph2Node>(*this)==
2.66 + static_cast<Graph2Node>(v));
2.67 + }
2.68 + bool operator!=(const Node& v) const {
2.69 + return (this->backward!=v.backward ||
2.70 + static_cast<Graph1Node>(*this)!=
2.71 + static_cast<Graph1Node>(v) ||
2.72 + static_cast<Graph2Node>(*this)!=
2.73 + static_cast<Graph2Node>(v));
2.74 + }
2.75 + };
2.76 +
2.77 + class NodeIt : public Node {
2.78 + friend class MergeNodeGraphWrapper<Graph1, Graph2>;
2.79 + protected:
2.80 + const MergeNodeGraphWrapper<Graph1, Graph2>* gw;
2.81 + public:
2.82 + NodeIt() { }
2.83 + NodeIt(Invalid i) : Node(i) { }
2.84 + NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw) :
2.85 + Node(typename Graph1::NodeIt(*_gw.Parent1::graph),
2.86 + typename Graph2::NodeIt(),
2.87 + false), gw(&_gw) {
2.88 + if (*static_cast<Graph1Node*>(this)==INVALID) {
2.89 + *static_cast<Node*>(this)=
2.90 + Node(Graph1Node(INVALID),
2.91 + typename Graph2::NodeIt(*_gw.Parent2::graph),
2.92 + true);
2.93 + }
2.94 + }
2.95 + NodeIt(const MergeNodeGraphWrapper<Graph1, Graph2>& _gw,
2.96 + const Node& n) :
2.97 + Node(n), gw(&_gw) { }
2.98 + NodeIt& operator++() {
2.99 + if (!this->backward) {
2.100 + *(static_cast<Graph1Node*>(this))=
2.101 + ++(typename Graph1::NodeIt(*gw->Parent1::graph, *this));
2.102 + if (*static_cast<Graph1Node*>(this)==INVALID) {
2.103 + *static_cast<Node*>(this)=
2.104 + Node(typename Graph1::Node(INVALID),
2.105 + typename Graph2::NodeIt(*gw->Parent2::graph), true);
2.106 + }
2.107 + } else {
2.108 + *(static_cast<Graph2Node*>(this))=
2.109 + ++(typename Graph2::NodeIt(*gw->Parent2::graph, *this));
2.110 + }
2.111 + return *this;
2.112 + }
2.113 + };
2.114 +
2.115 + int id(const Node& n) const {
2.116 + if (!n.backward)
2.117 + return this->Parent1::graph->id(n);
2.118 + else
2.119 + return this->Parent2::graph->id(n);
2.120 + }
2.121 +
2.122 + };
2.123 +
2.124 +} //namespace hugo
2.125 +
2.126 +#endif //HUGO_MERGE_NODE_GRAPH_WRAPPER_H
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/src/work/marci/merge_node_graph_wrapper_test.cc Tue Sep 28 13:45:39 2004 +0000
3.3 @@ -0,0 +1,26 @@
3.4 +#include <iostream>
3.5 +
3.6 +#include <hugo/list_graph.h>
3.7 +#include <hugo/smart_graph.h>
3.8 +#include <merge_node_graph_wrapper.h>
3.9 +
3.10 +using std::cout;
3.11 +using std::endl;
3.12 +
3.13 +using namespace hugo;
3.14 +
3.15 +int main() {
3.16 + SmartGraph g;
3.17 + ListGraph h;
3.18 + typedef MergeNodeGraphWrapper<SmartGraph, ListGraph> GW;
3.19 + GW gw(g, h);
3.20 + g.addNode();
3.21 + g.addNode();
3.22 + g.addNode();
3.23 + h.addNode();
3.24 + h.addNode();
3.25 + //GW::NodeIt n(gw)
3.26 + for (GW::NodeIt n(gw); n!=INVALID; ++n) {
3.27 + cout << gw.id(n) << endl;
3.28 + }
3.29 +}