1.1 --- a/src/work/marci/merge_node_graph_wrapper.h Thu Nov 18 14:37:22 2004 +0000
1.2 +++ b/src/work/marci/merge_node_graph_wrapper.h Thu Nov 18 22:31:21 2004 +0000
1.3 @@ -22,6 +22,8 @@
1.4 #include <lemon/map_defines.h>
1.5 #include <lemon/graph_wrapper.h>
1.6 #include <iostream>
1.7 +using std::cout;
1.8 +using std::endl;
1.9
1.10 #include <boost/type_traits.hpp>
1.11 #include <boost/utility/enable_if.hpp>
1.12 @@ -125,24 +127,6 @@
1.13 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw,
1.14 const _Value& value) :
1.15 ParentMap1(gw, value), ParentMap2(gw, value) { }
1.16 -// NodeMap(const NodeMap& copy)
1.17 -// : ParentMap1(copy),
1.18 -// ParentMap2(copy) { }
1.19 -// template <typename TT>
1.20 -// NodeMap(const NodeMap<TT>& copy)
1.21 -// : ParentMap1(copy),
1.22 -// ParentMap2(copy) { }
1.23 -// NodeMap& operator=(const NodeMap& copy) {
1.24 -// ParentMap1::operator=(copy);
1.25 -// ParentMap2::operator=(copy);
1.26 -// return *this;
1.27 -// }
1.28 -// template <typename TT>
1.29 -// NodeMap& operator=(const NodeMap<TT>& copy) {
1.30 -// ParentMap1::operator=(copy);
1.31 -// ParentMap2::operator=(copy);
1.32 -// return *this;
1.33 -// }
1.34 _Value operator[](const Node& n) const {
1.35 if (!n.backward)
1.36 return ParentMap1::operator[](n);
1.37 @@ -161,6 +145,7 @@
1.38
1.39 };
1.40
1.41 + //not yet working
1.42 template <typename _Graph1, typename _Graph2>
1.43 class MergeNodeGraphWrapperBase<
1.44 _Graph1, _Graph2, typename boost::enable_if<
1.45 @@ -183,6 +168,7 @@
1.46 void next() const;
1.47 };
1.48
1.49 + //not yet working
1.50 template <typename _Graph1, typename _Graph2>
1.51 class MergeNodeGraphWrapperBase<
1.52 _Graph1, _Graph2, typename boost::enable_if<
1.53 @@ -205,6 +191,7 @@
1.54 void next() const;
1.55 };
1.56
1.57 + //not yet working
1.58 template <typename _Graph1, typename _Graph2>
1.59 class MergeNodeGraphWrapperBase<
1.60 _Graph1, _Graph2, typename boost::enable_if<
1.61 @@ -245,6 +232,128 @@
1.62 }
1.63 };
1.64
1.65 +
1.66 + template <typename _Graph, typename _EdgeSetGraph>
1.67 + class NewEdgeSetGraphWrapperBase : public GraphWrapperBase<_Graph> {
1.68 + public:
1.69 + typedef GraphWrapperBase<_Graph> Parent;
1.70 + typedef _Graph Graph;
1.71 + typedef _EdgeSetGraph EdgeSetGraph;
1.72 + typedef typename _Graph::Node Node;
1.73 + typedef typename _EdgeSetGraph::Node ENode;
1.74 + protected:
1.75 + EdgeSetGraph* edge_set_graph;
1.76 + typename Graph::NodeMap<ENode>* e_node;
1.77 + typename EdgeSetGraph::NodeMap<Node>* n_node;
1.78 + void setEdgeSetGraph(EdgeSetGraph& _edge_set_graph) {
1.79 + edge_set_graph=&_edge_set_graph;
1.80 + }
1.81 + /// For each node of \c Graph, this gives a node of \c EdgeSetGraph .
1.82 + void setNodeMap(typename EdgeSetGraph::NodeMap<Node>& _n_node) {
1.83 + n_node=&_n_node;
1.84 + }
1.85 + /// For each node of \c EdgeSetGraph, this gives a node of \c Graph .
1.86 + void setENodeMap(typename Graph::NodeMap<ENode>& _e_node) {
1.87 + e_node=&_e_node;
1.88 + }
1.89 + public:
1.90 + class Edge : public EdgeSetGraph::Edge {
1.91 + typedef typename EdgeSetGraph::Edge Parent;
1.92 + public:
1.93 + Edge() { }
1.94 + Edge(const Parent& e) : Parent(e) { }
1.95 + Edge(Invalid i) : Parent(i) { }
1.96 + };
1.97 +
1.98 + using Parent::first;
1.99 + void first(Edge &e) const {
1.100 + edge_set_graph->first(e);
1.101 + }
1.102 + void firstOut(Edge& e, const Node& n) const {
1.103 +// cout << e_node << endl;
1.104 +// cout << n_node << endl;
1.105 + edge_set_graph->firstOut(e, (*e_node)[n]);
1.106 + }
1.107 + void firstIn(Edge& e, const Node& n) const {
1.108 + edge_set_graph->firstIn(e, (*e_node)[n]);
1.109 + }
1.110 +
1.111 + using Parent::next;
1.112 + void next(Edge &e) const {
1.113 + edge_set_graph->next(e);
1.114 + }
1.115 + void nextOut(Edge& e) const {
1.116 + edge_set_graph->nextOut(e);
1.117 + }
1.118 + void nextIn(Edge& e) const {
1.119 + edge_set_graph->nextIn(e);
1.120 + }
1.121 +
1.122 + Node source(const Edge& e) const {
1.123 + return (*n_node)[edge_set_graph->source(e)];
1.124 + }
1.125 + Node target(const Edge& e) const {
1.126 + return (*n_node)[edge_set_graph->target(e)];
1.127 + }
1.128 +
1.129 + int edgeNum() const { return edge_set_graph->edgeNum(); }
1.130 +
1.131 + Edge addEdge(const Node& u, const Node& v) {
1.132 + return edge_set_graph->addEdge((*e_node)[u], (*e_node)[v]);
1.133 + }
1.134 +
1.135 + using Parent::erase;
1.136 + void erase(const Edge& i) const { edge_set_graph->erase(i); }
1.137 +
1.138 + void clear() const { Parent::clear(); edge_set_graph->clear(); }
1.139 +
1.140 + bool forward(const Edge& e) const { return edge_set_graph->forward(e); }
1.141 + bool backward(const Edge& e) const { return edge_set_graph->backward(e); }
1.142 +
1.143 + using Parent::id;
1.144 + int id(const Edge& e) const { return edge_set_graph->id(e); }
1.145 +
1.146 + Edge opposite(const Edge& e) const { return edge_set_graph->opposite(e); }
1.147 +
1.148 + template <typename _Value>
1.149 + class EdgeMap : public EdgeSetGraph::EdgeMap<_Value> {
1.150 + public:
1.151 + typedef typename EdgeSetGraph::EdgeMap<_Value> Parent;
1.152 + typedef _Value Value;
1.153 + typedef Edge Key;
1.154 + EdgeMap(const NewEdgeSetGraphWrapperBase& gw) :
1.155 + Parent(*(gw.edge_set_graph)) { }
1.156 + EdgeMap(const NewEdgeSetGraphWrapperBase& gw, const _Value& _value) :
1.157 + Parent(*(gw.edge_set_graph), _value) { }
1.158 + };
1.159 +
1.160 + };
1.161 +
1.162 + template <typename _Graph, typename _EdgeSetGraph>
1.163 + class NewEdgeSetGraphWrapper :
1.164 + public IterableGraphExtender<
1.165 + NewEdgeSetGraphWrapperBase<_Graph, _EdgeSetGraph> > {
1.166 + public:
1.167 + typedef _Graph Graph;
1.168 + typedef _EdgeSetGraph EdgeSetGraph;
1.169 + typedef IterableGraphExtender<
1.170 + NewEdgeSetGraphWrapper<_Graph, _EdgeSetGraph> > Parent;
1.171 + protected:
1.172 + NewEdgeSetGraphWrapper() { }
1.173 + public:
1.174 + NewEdgeSetGraphWrapper(_Graph& _graph,
1.175 + _EdgeSetGraph& _edge_set_graph,
1.176 + typename _Graph::
1.177 + NodeMap<typename _EdgeSetGraph::Node>& _e_node,
1.178 + typename _EdgeSetGraph::
1.179 + NodeMap<typename _Graph::Node>& _n_node) {
1.180 + setGraph(_graph);
1.181 + setEdgeSetGraph(_edge_set_graph);
1.182 + setNodeMap(_n_node);
1.183 + setENodeMap(_e_node);
1.184 + }
1.185 + };
1.186 +
1.187 } //namespace lemon
1.188
1.189 #endif //LEMON_MERGE_NODE_GRAPH_WRAPPER_H
2.1 --- a/src/work/marci/merge_node_graph_wrapper_test.cc Thu Nov 18 14:37:22 2004 +0000
2.2 +++ b/src/work/marci/merge_node_graph_wrapper_test.cc Thu Nov 18 22:31:21 2004 +0000
2.3 @@ -4,10 +4,14 @@
2.4 #include <lemon/smart_graph.h>
2.5 #include <merge_node_graph_wrapper.h>
2.6
2.7 +#include<lemon/concept_check.h>
2.8 +#include<lemon/concept/graph.h>
2.9 +
2.10 using std::cout;
2.11 using std::endl;
2.12
2.13 using namespace lemon;
2.14 +using namespace lemon::concept;
2.15
2.16 class Graph3 : ListGraph {
2.17 public:
2.18 @@ -18,6 +22,11 @@
2.19 int main() {
2.20 typedef SmartGraph Graph1;
2.21 typedef ListGraph Graph2;
2.22 +
2.23 +// {
2.24 +// checkConcept<StaticGraph, NewEdgeSetGraphWrapper<Graph1, Graph2> >();
2.25 +// }
2.26 + {
2.27 Graph1 g;
2.28 Graph2 h;
2.29 typedef MergeNodeGraphWrapper<Graph1, Graph2> GW;
2.30 @@ -77,4 +86,56 @@
2.31 GW gw(g, h);
2.32 gw.print();
2.33 }
2.34 + }
2.35 + {
2.36 + Graph1 g;
2.37 + Graph2 h;
2.38 + typedef Graph1::Node Node1;
2.39 + typedef Graph2::Node Node2;
2.40 + typedef NewEdgeSetGraphWrapper<Graph1, Graph2> GW;
2.41 + Graph1::NodeMap<Graph2::Node> e_node(g);
2.42 + Graph2::NodeMap<Graph1::Node> n_node(h);
2.43 + GW gw(g, h, e_node, n_node);
2.44 + for (int i=0; i<4; ++i) {
2.45 + Node1 n=g.addNode();
2.46 + e_node.set(n, INVALID);
2.47 + }
2.48 + for (int i=0; i<4; ++i) {
2.49 + Graph1::Node n1=g.addNode();
2.50 + Graph2::Node n2=h.addNode();
2.51 + e_node.set(n1, n2);
2.52 + n_node.set(n2, n1);
2.53 + }
2.54 + for (Graph2::NodeIt n(h); n!=INVALID; ++n)
2.55 + for (Graph2::NodeIt m(h); m!=INVALID; ++m)
2.56 + if ((h.id(n)+h.id(m))%3==0) h.addEdge(n, m);
2.57 +// Graph1::NodeIt n(g);
2.58 +// Node1 n1=n;
2.59 +// Node1 n2=++n;
2.60 +// Node1 n3=++n;
2.61 +// Node1 n4=n;
2.62 +// gw.addEdge(n1, n2);
2.63 +// gw.addEdge(n1, n2);
2.64 +// for (EdgeIt(e))
2.65 +// Graph1::Node n1=g.addNode();
2.66 +// Graph1::Node n2=g.addNode();
2.67 +// Graph1::Node n3=g.addNode();
2.68 +// Graph2::Node n4=h.addNode();
2.69 +// Graph2::Node n5=h.addNode();
2.70 + for (GW::EdgeIt e(gw); e!=INVALID; ++e)
2.71 + cout << gw.id(e) << endl;
2.72 + for (GW::NodeIt n(gw); n!=INVALID; ++n) {
2.73 + if (e_node[n]==INVALID) {
2.74 + cout<<gw.id(n)<<" INVALID"<<endl;
2.75 + } else {
2.76 + cout <<gw.id(n)<<" "<<h.id(e_node[n])<<" out_edges: ";
2.77 + // cout << &e_node << endl;
2.78 + //cout << &n_node << endl;
2.79 + for (GW::OutEdgeIt e(gw, n); e!=INVALID; ++e) {
2.80 + cout<<gw.id(e)<<" ";
2.81 + }
2.82 + cout<< endl;
2.83 + }
2.84 + }
2.85 + }
2.86 }