# HG changeset patch # User marci # Date 1100817081 0 # Node ID 3fef334f5f3730c4c81a29a58fb38cf2c9fec4ab # Parent a7d5fe18d8f994eb9e2d2342c88217c7ec67040f RoadMap to MergeGraphWrapper and STGraphWrapper, NewEdgeSetGraphWrapper which is similar to the old EdgeSet diff -r a7d5fe18d8f9 -r 3fef334f5f37 src/work/marci/merge_node_graph_wrapper.h --- a/src/work/marci/merge_node_graph_wrapper.h Thu Nov 18 14:37:22 2004 +0000 +++ b/src/work/marci/merge_node_graph_wrapper.h Thu Nov 18 22:31:21 2004 +0000 @@ -22,6 +22,8 @@ #include #include #include +using std::cout; +using std::endl; #include #include @@ -125,24 +127,6 @@ NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& 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); @@ -161,6 +145,7 @@ }; + //not yet working template class MergeNodeGraphWrapperBase< _Graph1, _Graph2, typename boost::enable_if< @@ -183,6 +168,7 @@ void next() const; }; + //not yet working template class MergeNodeGraphWrapperBase< _Graph1, _Graph2, typename boost::enable_if< @@ -205,6 +191,7 @@ void next() const; }; + //not yet working template class MergeNodeGraphWrapperBase< _Graph1, _Graph2, typename boost::enable_if< @@ -245,6 +232,128 @@ } }; + + template + class NewEdgeSetGraphWrapperBase : public GraphWrapperBase<_Graph> { + public: + typedef GraphWrapperBase<_Graph> Parent; + typedef _Graph Graph; + typedef _EdgeSetGraph EdgeSetGraph; + typedef typename _Graph::Node Node; + typedef typename _EdgeSetGraph::Node ENode; + protected: + EdgeSetGraph* edge_set_graph; + typename Graph::NodeMap* e_node; + typename EdgeSetGraph::NodeMap* n_node; + void setEdgeSetGraph(EdgeSetGraph& _edge_set_graph) { + edge_set_graph=&_edge_set_graph; + } + /// For each node of \c Graph, this gives a node of \c EdgeSetGraph . + void setNodeMap(typename EdgeSetGraph::NodeMap& _n_node) { + n_node=&_n_node; + } + /// For each node of \c EdgeSetGraph, this gives a node of \c Graph . + void setENodeMap(typename Graph::NodeMap& _e_node) { + e_node=&_e_node; + } + public: + class Edge : public EdgeSetGraph::Edge { + typedef typename EdgeSetGraph::Edge Parent; + public: + Edge() { } + Edge(const Parent& e) : Parent(e) { } + Edge(Invalid i) : Parent(i) { } + }; + + using Parent::first; + void first(Edge &e) const { + edge_set_graph->first(e); + } + void firstOut(Edge& e, const Node& n) const { +// cout << e_node << endl; +// cout << n_node << endl; + edge_set_graph->firstOut(e, (*e_node)[n]); + } + void firstIn(Edge& e, const Node& n) const { + edge_set_graph->firstIn(e, (*e_node)[n]); + } + + using Parent::next; + void next(Edge &e) const { + edge_set_graph->next(e); + } + void nextOut(Edge& e) const { + edge_set_graph->nextOut(e); + } + void nextIn(Edge& e) const { + edge_set_graph->nextIn(e); + } + + Node source(const Edge& e) const { + return (*n_node)[edge_set_graph->source(e)]; + } + Node target(const Edge& e) const { + return (*n_node)[edge_set_graph->target(e)]; + } + + int edgeNum() const { return edge_set_graph->edgeNum(); } + + Edge addEdge(const Node& u, const Node& v) { + return edge_set_graph->addEdge((*e_node)[u], (*e_node)[v]); + } + + using Parent::erase; + void erase(const Edge& i) const { edge_set_graph->erase(i); } + + void clear() const { Parent::clear(); edge_set_graph->clear(); } + + bool forward(const Edge& e) const { return edge_set_graph->forward(e); } + bool backward(const Edge& e) const { return edge_set_graph->backward(e); } + + using Parent::id; + int id(const Edge& e) const { return edge_set_graph->id(e); } + + Edge opposite(const Edge& e) const { return edge_set_graph->opposite(e); } + + template + class EdgeMap : public EdgeSetGraph::EdgeMap<_Value> { + public: + typedef typename EdgeSetGraph::EdgeMap<_Value> Parent; + typedef _Value Value; + typedef Edge Key; + EdgeMap(const NewEdgeSetGraphWrapperBase& gw) : + Parent(*(gw.edge_set_graph)) { } + EdgeMap(const NewEdgeSetGraphWrapperBase& gw, const _Value& _value) : + Parent(*(gw.edge_set_graph), _value) { } + }; + + }; + + template + class NewEdgeSetGraphWrapper : + public IterableGraphExtender< + NewEdgeSetGraphWrapperBase<_Graph, _EdgeSetGraph> > { + public: + typedef _Graph Graph; + typedef _EdgeSetGraph EdgeSetGraph; + typedef IterableGraphExtender< + NewEdgeSetGraphWrapper<_Graph, _EdgeSetGraph> > Parent; + protected: + NewEdgeSetGraphWrapper() { } + public: + NewEdgeSetGraphWrapper(_Graph& _graph, + _EdgeSetGraph& _edge_set_graph, + typename _Graph:: + NodeMap& _e_node, + typename _EdgeSetGraph:: + NodeMap& _n_node) { + setGraph(_graph); + setEdgeSetGraph(_edge_set_graph); + setNodeMap(_n_node); + setENodeMap(_e_node); + } + }; + } //namespace lemon #endif //LEMON_MERGE_NODE_GRAPH_WRAPPER_H diff -r a7d5fe18d8f9 -r 3fef334f5f37 src/work/marci/merge_node_graph_wrapper_test.cc --- a/src/work/marci/merge_node_graph_wrapper_test.cc Thu Nov 18 14:37:22 2004 +0000 +++ b/src/work/marci/merge_node_graph_wrapper_test.cc Thu Nov 18 22:31:21 2004 +0000 @@ -4,10 +4,14 @@ #include #include +#include +#include + using std::cout; using std::endl; using namespace lemon; +using namespace lemon::concept; class Graph3 : ListGraph { public: @@ -18,6 +22,11 @@ int main() { typedef SmartGraph Graph1; typedef ListGraph Graph2; + +// { +// checkConcept >(); +// } + { Graph1 g; Graph2 h; typedef MergeNodeGraphWrapper GW; @@ -77,4 +86,56 @@ GW gw(g, h); gw.print(); } + } + { + Graph1 g; + Graph2 h; + typedef Graph1::Node Node1; + typedef Graph2::Node Node2; + typedef NewEdgeSetGraphWrapper GW; + Graph1::NodeMap e_node(g); + Graph2::NodeMap n_node(h); + GW gw(g, h, e_node, n_node); + for (int i=0; i<4; ++i) { + Node1 n=g.addNode(); + e_node.set(n, INVALID); + } + for (int i=0; i<4; ++i) { + Graph1::Node n1=g.addNode(); + Graph2::Node n2=h.addNode(); + e_node.set(n1, n2); + n_node.set(n2, n1); + } + for (Graph2::NodeIt n(h); n!=INVALID; ++n) + for (Graph2::NodeIt m(h); m!=INVALID; ++m) + if ((h.id(n)+h.id(m))%3==0) h.addEdge(n, m); +// Graph1::NodeIt n(g); +// Node1 n1=n; +// Node1 n2=++n; +// Node1 n3=++n; +// Node1 n4=n; +// gw.addEdge(n1, n2); +// gw.addEdge(n1, n2); +// for (EdgeIt(e)) +// 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(); + for (GW::EdgeIt e(gw); e!=INVALID; ++e) + cout << gw.id(e) << endl; + for (GW::NodeIt n(gw); n!=INVALID; ++n) { + if (e_node[n]==INVALID) { + cout<