Changeset 1008:3fef334f5f37 in lemon0.x for src/work
 Timestamp:
 11/18/04 23:31:21 (20 years ago)
 Branch:
 default
 Phase:
 public
 Convert:
 svn:c9d7d8f590d60310b91f818b3a526b0e/lemon/trunk@1398
 Location:
 src/work/marci
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

src/work/marci/merge_node_graph_wrapper.h
r1007 r1008 23 23 #include <lemon/graph_wrapper.h> 24 24 #include <iostream> 25 using std::cout; 26 using std::endl; 25 27 26 28 #include <boost/type_traits.hpp> … … 126 128 const _Value& value) : 127 129 ParentMap1(gw, value), ParentMap2(gw, value) { } 128 // NodeMap(const NodeMap& copy)129 // : ParentMap1(copy),130 // ParentMap2(copy) { }131 // template <typename TT>132 // NodeMap(const NodeMap<TT>& copy)133 // : ParentMap1(copy),134 // ParentMap2(copy) { }135 // NodeMap& operator=(const NodeMap& copy) {136 // ParentMap1::operator=(copy);137 // ParentMap2::operator=(copy);138 // return *this;139 // }140 // template <typename TT>141 // NodeMap& operator=(const NodeMap<TT>& copy) {142 // ParentMap1::operator=(copy);143 // ParentMap2::operator=(copy);144 // return *this;145 // }146 130 _Value operator[](const Node& n) const { 147 131 if (!n.backward) … … 162 146 }; 163 147 148 //not yet working 164 149 template <typename _Graph1, typename _Graph2> 165 150 class MergeNodeGraphWrapperBase< … … 184 169 }; 185 170 171 //not yet working 186 172 template <typename _Graph1, typename _Graph2> 187 173 class MergeNodeGraphWrapperBase< … … 206 192 }; 207 193 194 //not yet working 208 195 template <typename _Graph1, typename _Graph2> 209 196 class MergeNodeGraphWrapperBase< … … 246 233 }; 247 234 235 236 template <typename _Graph, typename _EdgeSetGraph> 237 class NewEdgeSetGraphWrapperBase : public GraphWrapperBase<_Graph> { 238 public: 239 typedef GraphWrapperBase<_Graph> Parent; 240 typedef _Graph Graph; 241 typedef _EdgeSetGraph EdgeSetGraph; 242 typedef typename _Graph::Node Node; 243 typedef typename _EdgeSetGraph::Node ENode; 244 protected: 245 EdgeSetGraph* edge_set_graph; 246 typename Graph::NodeMap<ENode>* e_node; 247 typename EdgeSetGraph::NodeMap<Node>* n_node; 248 void setEdgeSetGraph(EdgeSetGraph& _edge_set_graph) { 249 edge_set_graph=&_edge_set_graph; 250 } 251 /// For each node of \c Graph, this gives a node of \c EdgeSetGraph . 252 void setNodeMap(typename EdgeSetGraph::NodeMap<Node>& _n_node) { 253 n_node=&_n_node; 254 } 255 /// For each node of \c EdgeSetGraph, this gives a node of \c Graph . 256 void setENodeMap(typename Graph::NodeMap<ENode>& _e_node) { 257 e_node=&_e_node; 258 } 259 public: 260 class Edge : public EdgeSetGraph::Edge { 261 typedef typename EdgeSetGraph::Edge Parent; 262 public: 263 Edge() { } 264 Edge(const Parent& e) : Parent(e) { } 265 Edge(Invalid i) : Parent(i) { } 266 }; 267 268 using Parent::first; 269 void first(Edge &e) const { 270 edge_set_graph>first(e); 271 } 272 void firstOut(Edge& e, const Node& n) const { 273 // cout << e_node << endl; 274 // cout << n_node << endl; 275 edge_set_graph>firstOut(e, (*e_node)[n]); 276 } 277 void firstIn(Edge& e, const Node& n) const { 278 edge_set_graph>firstIn(e, (*e_node)[n]); 279 } 280 281 using Parent::next; 282 void next(Edge &e) const { 283 edge_set_graph>next(e); 284 } 285 void nextOut(Edge& e) const { 286 edge_set_graph>nextOut(e); 287 } 288 void nextIn(Edge& e) const { 289 edge_set_graph>nextIn(e); 290 } 291 292 Node source(const Edge& e) const { 293 return (*n_node)[edge_set_graph>source(e)]; 294 } 295 Node target(const Edge& e) const { 296 return (*n_node)[edge_set_graph>target(e)]; 297 } 298 299 int edgeNum() const { return edge_set_graph>edgeNum(); } 300 301 Edge addEdge(const Node& u, const Node& v) { 302 return edge_set_graph>addEdge((*e_node)[u], (*e_node)[v]); 303 } 304 305 using Parent::erase; 306 void erase(const Edge& i) const { edge_set_graph>erase(i); } 307 308 void clear() const { Parent::clear(); edge_set_graph>clear(); } 309 310 bool forward(const Edge& e) const { return edge_set_graph>forward(e); } 311 bool backward(const Edge& e) const { return edge_set_graph>backward(e); } 312 313 using Parent::id; 314 int id(const Edge& e) const { return edge_set_graph>id(e); } 315 316 Edge opposite(const Edge& e) const { return edge_set_graph>opposite(e); } 317 318 template <typename _Value> 319 class EdgeMap : public EdgeSetGraph::EdgeMap<_Value> { 320 public: 321 typedef typename EdgeSetGraph::EdgeMap<_Value> Parent; 322 typedef _Value Value; 323 typedef Edge Key; 324 EdgeMap(const NewEdgeSetGraphWrapperBase& gw) : 325 Parent(*(gw.edge_set_graph)) { } 326 EdgeMap(const NewEdgeSetGraphWrapperBase& gw, const _Value& _value) : 327 Parent(*(gw.edge_set_graph), _value) { } 328 }; 329 330 }; 331 332 template <typename _Graph, typename _EdgeSetGraph> 333 class NewEdgeSetGraphWrapper : 334 public IterableGraphExtender< 335 NewEdgeSetGraphWrapperBase<_Graph, _EdgeSetGraph> > { 336 public: 337 typedef _Graph Graph; 338 typedef _EdgeSetGraph EdgeSetGraph; 339 typedef IterableGraphExtender< 340 NewEdgeSetGraphWrapper<_Graph, _EdgeSetGraph> > Parent; 341 protected: 342 NewEdgeSetGraphWrapper() { } 343 public: 344 NewEdgeSetGraphWrapper(_Graph& _graph, 345 _EdgeSetGraph& _edge_set_graph, 346 typename _Graph:: 347 NodeMap<typename _EdgeSetGraph::Node>& _e_node, 348 typename _EdgeSetGraph:: 349 NodeMap<typename _Graph::Node>& _n_node) { 350 setGraph(_graph); 351 setEdgeSetGraph(_edge_set_graph); 352 setNodeMap(_n_node); 353 setENodeMap(_e_node); 354 } 355 }; 356 248 357 } //namespace lemon 249 358 
src/work/marci/merge_node_graph_wrapper_test.cc
r1007 r1008 5 5 #include <merge_node_graph_wrapper.h> 6 6 7 #include<lemon/concept_check.h> 8 #include<lemon/concept/graph.h> 9 7 10 using std::cout; 8 11 using std::endl; 9 12 10 13 using namespace lemon; 14 using namespace lemon::concept; 11 15 12 16 class Graph3 : ListGraph { … … 19 23 typedef SmartGraph Graph1; 20 24 typedef ListGraph Graph2; 25 26 // { 27 // checkConcept<StaticGraph, NewEdgeSetGraphWrapper<Graph1, Graph2> >(); 28 // } 29 { 21 30 Graph1 g; 22 31 Graph2 h; … … 78 87 gw.print(); 79 88 } 89 } 90 { 91 Graph1 g; 92 Graph2 h; 93 typedef Graph1::Node Node1; 94 typedef Graph2::Node Node2; 95 typedef NewEdgeSetGraphWrapper<Graph1, Graph2> GW; 96 Graph1::NodeMap<Graph2::Node> e_node(g); 97 Graph2::NodeMap<Graph1::Node> n_node(h); 98 GW gw(g, h, e_node, n_node); 99 for (int i=0; i<4; ++i) { 100 Node1 n=g.addNode(); 101 e_node.set(n, INVALID); 102 } 103 for (int i=0; i<4; ++i) { 104 Graph1::Node n1=g.addNode(); 105 Graph2::Node n2=h.addNode(); 106 e_node.set(n1, n2); 107 n_node.set(n2, n1); 108 } 109 for (Graph2::NodeIt n(h); n!=INVALID; ++n) 110 for (Graph2::NodeIt m(h); m!=INVALID; ++m) 111 if ((h.id(n)+h.id(m))%3==0) h.addEdge(n, m); 112 // Graph1::NodeIt n(g); 113 // Node1 n1=n; 114 // Node1 n2=++n; 115 // Node1 n3=++n; 116 // Node1 n4=n; 117 // gw.addEdge(n1, n2); 118 // gw.addEdge(n1, n2); 119 // for (EdgeIt(e)) 120 // Graph1::Node n1=g.addNode(); 121 // Graph1::Node n2=g.addNode(); 122 // Graph1::Node n3=g.addNode(); 123 // Graph2::Node n4=h.addNode(); 124 // Graph2::Node n5=h.addNode(); 125 for (GW::EdgeIt e(gw); e!=INVALID; ++e) 126 cout << gw.id(e) << endl; 127 for (GW::NodeIt n(gw); n!=INVALID; ++n) { 128 if (e_node[n]==INVALID) { 129 cout<<gw.id(n)<<" INVALID"<<endl; 130 } else { 131 cout <<gw.id(n)<<" "<<h.id(e_node[n])<<" out_edges: "; 132 // cout << &e_node << endl; 133 //cout << &n_node << endl; 134 for (GW::OutEdgeIt e(gw, n); e!=INVALID; ++e) { 135 cout<<gw.id(e)<<" "; 136 } 137 cout<< endl; 138 } 139 } 140 } 80 141 }
Note: See TracChangeset
for help on using the changeset viewer.