Changeset 1025:3b1ad8bc21da in lemon-0.x for src/work/marci/merge_node_graph_wrapper.h
- Timestamp:
- 11/29/04 18:55:46 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1415
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/marci/merge_node_graph_wrapper.h
r1016 r1025 41 41 42 42 43 /*! A graph wrapper base class44 for merging the node-set of two node-disjoint graphs45 into the node-set of one graph.46 Generic implementation for unrelated _Graph1::Node and _Graph2::Node.47 */48 43 template <typename _Graph1, typename _Graph2, typename Enable=void> 49 class MergeNodeGraphWrapperBase :44 class MergeNodeGraphWrapperBaseBase : 50 45 public P1<_Graph1>, public P2<_Graph2> { 51 46 public: … … 58 53 typedef typename Parent2::Node Graph2Node; 59 54 protected: 60 MergeNodeGraphWrapperBase() { } 61 public: 62 template <typename _Value> class NodeMap; 55 MergeNodeGraphWrapperBaseBase() { } 56 public: 63 57 64 58 class Node : public Graph1Node, public Graph2Node { 65 friend class MergeNodeGraphWrapperBase<_Graph1, _Graph2>; 66 template <typename _Value> friend class NodeMap; 59 friend class MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2>; 67 60 protected: 68 61 bool backward; //true, iff backward … … 89 82 }; 90 83 91 //typedef void Edge; 92 class Edge { }; 93 94 void first(Node& i) const { 95 Parent1::graph->first(*static_cast<Graph1Node*>(&i)); 96 i.backward=false; 97 if (*static_cast<Graph1Node*>(&i)==INVALID) { 98 Parent2::graph->first(*static_cast<Graph2Node*>(&i)); 99 i.backward=true; 100 } 101 } 102 void next(Node& i) const { 103 if (!(i.backward)) { 104 Parent1::graph->next(*static_cast<Graph1Node*>(&i)); 105 if (*static_cast<Graph1Node*>(&i)==INVALID) { 106 Parent2::graph->first(*static_cast<Graph2Node*>(&i)); 107 i.backward=true; 108 } 109 } else { 110 Parent2::graph->next(*static_cast<Graph2Node*>(&i)); 111 } 112 } 113 114 int id(const Node& n) const { 115 if (!n.backward) 116 return this->Parent1::graph->id(n); 117 else 118 return this->Parent2::graph->id(n); 119 } 120 121 template <typename _Value> 122 class NodeMap { 123 protected: 124 typedef typename _Graph1::template NodeMap<_Value> ParentMap1; 125 typedef typename _Graph2::template NodeMap<_Value> ParentMap2; 126 ParentMap1 forward_map; 127 ParentMap2 backward_map; 128 public: 129 typedef _Value Value; 130 typedef Node Key; 131 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw) : 132 forward_map(*(gw.Parent1::graph)), 133 backward_map(*(gw.Parent2::graph)) { } 134 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw, 135 const _Value& value) : 136 forward_map(*(gw.Parent1::graph), value), 137 backward_map(*(gw.Parent2::graph), value) { } 138 _Value operator[](const Node& n) const { 139 if (!n.backward) 140 return forward_map[n]; 141 else 142 return backward_map[n]; 143 } 144 void set(const Node& n, const _Value& value) { 145 if (!n.backward) 146 forward_map.set(n, value); 147 else 148 backward_map.set(n, value); 149 } 150 // using ParentMap1::operator[]; 151 // using ParentMap2::operator[]; 152 }; 153 154 }; 155 156 157 /*! A graph wrapper base class 158 for merging the node-set of two node-disjoint graphs 159 into the node-set of one graph. 160 Specialization for the case when _Graph1::Node are the same _Graph2::Node. 161 */ 84 static bool forward(const Node& n) { return !n.backward; } 85 static bool backward(const Node& n) { return n.backward; } 86 static void setForward(Node& n) { n.backward=false; } 87 static void setBackward(Node& n) { n.backward=true; } 88 }; 89 90 162 91 template <typename _Graph1, typename _Graph2> 163 class MergeNodeGraphWrapperBase <92 class MergeNodeGraphWrapperBaseBase< 164 93 _Graph1, _Graph2, typename boost::enable_if< 165 94 boost::is_same<typename _Graph1::Node, typename _Graph2::Node> >::type> : … … 174 103 typedef typename Parent2::Node Graph2Node; 175 104 protected: 176 MergeNodeGraphWrapperBase() { } 177 public: 178 template <typename _Value> class NodeMap; 105 MergeNodeGraphWrapperBaseBase() { } 106 public: 179 107 180 108 class Node : public Graph1Node { 181 friend class MergeNodeGraphWrapperBase<_Graph1, _Graph2>; 182 template <typename _Value> friend class NodeMap; 109 friend class MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2>; 183 110 protected: 184 111 bool backward; //true, iff backward … … 190 117 Node(const Graph1Node& n1, 191 118 const Graph2Node& n2, bool _backward) : 192 Graph1Node(! backward ? n1 : n2), backward(_backward) { }119 Graph1Node(!_backward ? n1 : n2), backward(_backward) { } 193 120 Node(Invalid i) : Graph1Node(i), backward(true) { } 194 121 bool operator==(const Node& v) const { … … 201 128 }; 202 129 203 //typedef void Edge; 204 class Edge { }; 205 206 void first(Node& i) const { 207 Parent1::graph->first(*static_cast<Graph1Node*>(&i)); 208 i.backward=false; 209 if (*static_cast<Graph1Node*>(&i)==INVALID) { 210 Parent2::graph->first(*static_cast<Graph1Node*>(&i)); 211 i.backward=true; 212 } 213 } 214 void next(Node& i) const { 215 if (!(i.backward)) { 216 Parent1::graph->next(*static_cast<Graph1Node*>(&i)); 217 if (*static_cast<Graph1Node*>(&i)==INVALID) { 218 Parent2::graph->first(*static_cast<Graph1Node*>(&i)); 219 i.backward=true; 220 } 221 } else { 222 Parent2::graph->next(*static_cast<Graph1Node*>(&i)); 223 } 224 } 225 226 int id(const Node& n) const { 227 if (!n.backward) 228 return this->Parent1::graph->id(n); 229 else 230 return this->Parent2::graph->id(n); 231 } 232 233 template <typename _Value> 234 class NodeMap { 235 protected: 236 typedef typename _Graph1::template NodeMap<_Value> ParentMap1; 237 typedef typename _Graph2::template NodeMap<_Value> ParentMap2; 238 ParentMap1 forward_map; 239 ParentMap2 backward_map; 240 public: 241 typedef _Value Value; 242 typedef Node Key; 243 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw) : 244 forward_map(*(gw.Parent1::graph)), 245 backward_map(*(gw.Parent2::graph)) { } 246 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw, 247 const _Value& value) : 248 forward_map(*(gw.Parent1::graph), value), 249 backward_map(*(gw.Parent2::graph), value) { } 250 _Value operator[](const Node& n) const { 251 if (!n.backward) 252 return forward_map[n]; 253 else 254 return backward_map[n]; 255 } 256 void set(const Node& n, const _Value& value) { 257 if (!n.backward) 258 forward_map.set(n, value); 259 else 260 backward_map.set(n, value); 261 } 262 // using ParentMap1::operator[]; 263 // using ParentMap2::operator[]; 264 }; 265 266 }; 267 268 269 /*! A graph wrapper base class 270 for merging the node-set of two node-disjoint graphs 271 into the node-set of one graph. 272 Specialization for the case when 273 _Graph1::Node is a base class and _Graph2::Node is derived from it. 274 */ 130 static bool forward(const Node& n) { return !n.backward; } 131 static bool backward(const Node& n) { return n.backward; } 132 static void setForward(Node& n) { n.backward=false; } 133 static void setBackward(Node& n) { n.backward=true; } 134 }; 135 136 275 137 template <typename _Graph1, typename _Graph2> 276 class MergeNodeGraphWrapperBase <138 class MergeNodeGraphWrapperBaseBase< 277 139 _Graph1, _Graph2, typename boost::enable_if< 278 140 boost::is_base_and_derived<typename _Graph1::Node, typename _Graph2::Node> >::type> : … … 287 149 typedef typename Parent2::Node Graph2Node; 288 150 protected: 289 MergeNodeGraphWrapperBase() { } 290 public: 291 template <typename _Value> class NodeMap; 151 MergeNodeGraphWrapperBaseBase() { } 152 public: 292 153 293 154 class Node : public Graph2Node { 294 friend class MergeNodeGraphWrapperBase<_Graph1, _Graph2>; 295 template <typename _Value> friend class NodeMap; 155 friend class MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2>; 296 156 protected: 297 157 bool backward; //true, iff backward … … 320 180 }; 321 181 322 //typedef void Edge; 323 class Edge { }; 324 325 void first(Node& i) const { 326 Parent1::graph->first(*static_cast<Graph1Node*>(&i)); 327 i.backward=false; 328 if (*static_cast<Graph1Node*>(&i)==INVALID) { 329 Parent2::graph->first(*static_cast<Graph2Node*>(&i)); 330 i.backward=true; 331 } 332 } 333 void next(Node& i) const { 334 if (!(i.backward)) { 335 Parent1::graph->next(*static_cast<Graph1Node*>(&i)); 336 if (*static_cast<Graph1Node*>(&i)==INVALID) { 337 Parent2::graph->first(*static_cast<Graph2Node*>(&i)); 338 i.backward=true; 339 } 340 } else { 341 Parent2::graph->next(*static_cast<Graph2Node*>(&i)); 342 } 343 } 344 345 int id(const Node& n) const { 346 if (!n.backward) 347 return this->Parent1::graph->id(n); 348 else 349 return this->Parent2::graph->id(n); 350 } 351 352 template <typename _Value> 353 class NodeMap { 354 protected: 355 typedef typename _Graph1::template NodeMap<_Value> ParentMap1; 356 typedef typename _Graph2::template NodeMap<_Value> ParentMap2; 357 ParentMap1 forward_map; 358 ParentMap2 backward_map; 359 public: 360 typedef _Value Value; 361 typedef Node Key; 362 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw) : 363 forward_map(*(gw.Parent1::graph)), 364 backward_map(*(gw.Parent2::graph)) { } 365 NodeMap(const MergeNodeGraphWrapperBase<_Graph1, _Graph2>& gw, 366 const _Value& value) : 367 forward_map(*(gw.Parent1::graph), value), 368 backward_map(*(gw.Parent2::graph), value) { } 369 _Value operator[](const Node& n) const { 370 if (!n.backward) 371 return forward_map[n]; 372 else 373 return backward_map[n]; 374 } 375 void set(const Node& n, const _Value& value) { 376 if (!n.backward) 377 forward_map.set(n, value); 378 else 379 backward_map.set(n, value); 380 } 381 // using ParentMap1::operator[]; 382 // using ParentMap2::operator[]; 383 }; 384 385 }; 386 387 388 /*! A graph wrapper base class 389 for merging the node-set of two node-disjoint graphs 390 into the node-set of one graph. 391 Specialized implementaton for the case when _Graph1::Node is derived 392 from _Graph2::Node. 393 */ 182 static bool forward(const Node& n) { return !n.backward; } 183 static bool backward(const Node& n) { return n.backward; } 184 static void setForward(Node& n) { n.backward=false; } 185 static void setBackward(Node& n) { n.backward=true; } 186 }; 187 188 394 189 template <typename _Graph1, typename _Graph2> 395 class MergeNodeGraphWrapperBase <190 class MergeNodeGraphWrapperBaseBase< 396 191 _Graph1, _Graph2, typename boost::enable_if< 397 192 boost::is_base_and_derived<typename _Graph2::Node, typename _Graph1::Node> >::type> : … … 406 201 typedef typename Parent2::Node Graph2Node; 407 202 protected: 408 MergeNodeGraphWrapperBase() { } 409 public: 410 template <typename _Value> class NodeMap; 203 MergeNodeGraphWrapperBaseBase() { } 204 public: 411 205 412 206 class Node : public Graph1Node { 413 friend class MergeNodeGraphWrapperBase<_Graph1, _Graph2>; 414 template <typename _Value> friend class NodeMap; 207 friend class MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2>; 415 208 protected: 416 209 bool backward; //true, iff backward … … 439 232 }; 440 233 441 //typedef void Edge; 234 static bool forward(const Node& n) { return !n.backward; } 235 static bool backward(const Node& n) { return n.backward; } 236 static void setForward(Node& n) { n.backward=false; } 237 static void setBackward(Node& n) { n.backward=true; } 238 }; 239 240 241 template <typename _Graph1, typename _Graph2> 242 class MergeNodeGraphWrapperBase : 243 public MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2> { 244 public: 245 typedef MergeNodeGraphWrapperBaseBase<_Graph1, _Graph2> Parent; 246 typedef _Graph1 Graph1; 247 typedef _Graph2 Graph2; 248 typedef P1<_Graph1> Parent1; 249 typedef P2<_Graph2> Parent2; 250 typedef typename Parent1::Node Graph1Node; 251 typedef typename Parent2::Node Graph2Node; 252 253 typedef typename Parent::Node Node; 442 254 class Edge { }; 443 255 444 256 void first(Node& i) const { 445 257 Parent1::graph->first(*static_cast<Graph1Node*>(&i)); 446 i.backward=false;258 this->setForward(i); 447 259 if (*static_cast<Graph1Node*>(&i)==INVALID) { 448 260 Parent2::graph->first(*static_cast<Graph2Node*>(&i)); 449 i.backward=true;261 this->setBackward(i); 450 262 } 451 263 } 452 264 void next(Node& i) const { 453 if ( !(i.backward)) {265 if (this->forward(i)) { 454 266 Parent1::graph->next(*static_cast<Graph1Node*>(&i)); 455 267 if (*static_cast<Graph1Node*>(&i)==INVALID) { 456 268 Parent2::graph->first(*static_cast<Graph2Node*>(&i)); 457 i.backward=true;269 this->setBackward(i); 458 270 } 459 271 } else { … … 463 275 464 276 int id(const Node& n) const { 465 if ( !n.backward)277 if (this->forward(n)) 466 278 return this->Parent1::graph->id(n); 467 279 else … … 487 299 backward_map(*(gw.Parent2::graph), value) { } 488 300 _Value operator[](const Node& n) const { 489 if ( !n.backward)301 if (Parent::forward(n)) 490 302 return forward_map[n]; 491 303 else … … 493 305 } 494 306 void set(const Node& n, const _Value& value) { 495 if ( !n.backward)307 if (Parent::forward(n)) 496 308 forward_map.set(n, value); 497 309 else … … 506 318 507 319 /*! A graph wrapper class 508 fors merging the node-set of two node-disjoint graphs 509 into one node-set. It does not satisfy 320 for merging the node-set of two node-disjoint graphs 321 into the node-set of one graph. 322 Different implementations are according to the relation of 323 _Graph1::Node and _Graph2::Node. 324 If _Graph1::Node and _Graph2::Node are unrelated, then 325 MergeNodeGraphWrapper<_Graph1, _Graph2>::Node 326 is derived from both. 327 If _Graph1::Node and _Graph2::Node are the same type, then 328 MergeNodeGraphWrapper<_Graph1, _Graph2>::Node 329 is derived from _Graph1::Node. 330 If one of _Graph1::Node and _Graph2::Node 331 is derived from the other one, then 332 MergeNodeGraphWrapper<_Graph1, _Graph2>::Node 333 is derived from the derived type. 334 It does not satisfy 510 335 StaticGraph concept as it has no edge-set which 511 336 works together with the node-set. 512 337 */ 513 338 template <typename _Graph1, typename _Graph2> 514 339 class MergeNodeGraphWrapper : public … … 583 408 }; 584 409 410 using Parent::forward; 411 using Parent::backward; 412 bool forward(const Edge& e) const { return !e.backward; } 413 bool backward(const Edge& e) const { return e.backward; } 414 585 415 using Parent::first; 586 416 void first(Edge& i) const { … … 593 423 } 594 424 void firstIn(Edge& i, const Node& n) const { 595 Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n); 596 i.backward=false; 597 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 425 if (!backward(n)) { 426 Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n); 427 if (*static_cast<Graph1Edge*>(&i)==INVALID) 428 i=INVALID; 429 else 430 i.backward=false; 431 } else { 598 432 Parent2::graph->firstIn(*static_cast<Graph2Edge*>(&i), n); 599 433 i.backward=true; … … 601 435 } 602 436 void firstOut(Edge& i, const Node& n) const { 603 Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n); 604 i.backward=false; 605 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 437 if (!backward(n)) { 438 Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n); 439 if (*static_cast<Graph1Edge*>(&i)==INVALID) 440 i=INVALID; 441 else 442 i.backward=false; 443 } else { 606 444 Parent2::graph->firstOut(*static_cast<Graph2Edge*>(&i), n); 607 445 i.backward=true; … … 624 462 if (!(i.backward)) { 625 463 Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i)); 626 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 627 Parent2::graph->first(*static_cast<Graph2Edge*>(&i)); 628 i.backward=true; 629 } 464 if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID; 630 465 } else { 631 466 Parent2::graph->nextIn(*static_cast<Graph2Edge*>(&i)); … … 635 470 if (!(i.backward)) { 636 471 Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i)); 637 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 638 Parent2::graph->first(*static_cast<Graph2Edge*>(&i)); 639 i.backward=true; 640 } 472 if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID; 641 473 } else { 642 474 Parent2::graph->nextOut(*static_cast<Graph2Edge*>(&i)); … … 750 582 Edge(const Graph1Edge& n1, 751 583 const Graph2Edge& n2, bool _backward) : 752 Graph1Edge(! backward ? n1 : n2), backward(_backward) { }584 Graph1Edge(!_backward ? n1 : n2), backward(_backward) { } 753 585 Edge(Invalid i) : Graph1Edge(i), backward(true) { } 754 586 bool operator==(const Edge& v) const { … … 760 592 } 761 593 }; 594 595 using Parent::forward; 596 using Parent::backward; 597 bool forward(const Edge& e) const { return !e.backward; } 598 bool backward(const Edge& e) const { return e.backward; } 762 599 763 600 using Parent::first; … … 771 608 } 772 609 void firstIn(Edge& i, const Node& n) const { 773 Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n); 774 i.backward=false; 775 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 610 if (!backward(n)) { 611 Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n); 612 if (*static_cast<Graph1Edge*>(&i)==INVALID) 613 i=INVALID; 614 else 615 i.backward=false; 616 } else { 776 617 Parent2::graph->firstIn(*static_cast<Graph1Edge*>(&i), n); 777 618 i.backward=true; … … 779 620 } 780 621 void firstOut(Edge& i, const Node& n) const { 781 Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n); 782 i.backward=false; 783 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 622 if (!backward(n)) { 623 Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n); 624 if (*static_cast<Graph1Edge*>(&i)==INVALID) 625 i=INVALID; 626 else 627 i.backward=false; 628 } else { 784 629 Parent2::graph->firstOut(*static_cast<Graph1Edge*>(&i), n); 785 630 i.backward=true; … … 802 647 if (!(i.backward)) { 803 648 Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i)); 804 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 805 Parent2::graph->first(*static_cast<Graph1Edge*>(&i)); 806 i.backward=true; 807 } 649 if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID; 808 650 } else { 809 651 Parent2::graph->nextIn(*static_cast<Graph1Edge*>(&i)); … … 813 655 if (!(i.backward)) { 814 656 Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i)); 815 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 816 Parent2::graph->first(*static_cast<Graph1Edge*>(&i)); 817 i.backward=true; 818 } 657 if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID; 819 658 } else { 820 659 Parent2::graph->nextOut(*static_cast<Graph1Edge*>(&i)); … … 946 785 }; 947 786 787 using Parent::forward; 788 using Parent::backward; 789 bool forward(const Edge& e) const { return !e.backward; } 790 bool backward(const Edge& e) const { return e.backward; } 791 948 792 using Parent::first; 949 793 void first(Edge& i) const { … … 956 800 } 957 801 void firstIn(Edge& i, const Node& n) const { 958 Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n); 959 i.backward=false; 960 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 802 if (!backward(n)) { 803 Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n); 804 if (*static_cast<Graph1Edge*>(&i)==INVALID) 805 i=INVALID; 806 else 807 i.backward=false; 808 } else { 961 809 Parent2::graph->firstIn(*static_cast<Graph2Edge*>(&i), n); 962 810 i.backward=true; … … 964 812 } 965 813 void firstOut(Edge& i, const Node& n) const { 966 Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n); 967 i.backward=false; 968 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 814 if (!backward(n)) { 815 Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n); 816 if (*static_cast<Graph1Edge*>(&i)==INVALID) 817 i=INVALID; 818 else 819 i.backward=false; 820 } else { 969 821 Parent2::graph->firstOut(*static_cast<Graph2Edge*>(&i), n); 970 822 i.backward=true; … … 987 839 if (!(i.backward)) { 988 840 Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i)); 989 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 990 Parent2::graph->first(*static_cast<Graph2Edge*>(&i)); 991 i.backward=true; 992 } 841 if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID; 993 842 } else { 994 843 Parent2::graph->nextIn(*static_cast<Graph2Edge*>(&i)); … … 998 847 if (!(i.backward)) { 999 848 Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i)); 1000 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 1001 Parent2::graph->first(*static_cast<Graph2Edge*>(&i)); 1002 i.backward=true; 1003 } 849 if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID; 1004 850 } else { 1005 851 Parent2::graph->nextOut(*static_cast<Graph2Edge*>(&i)); … … 1130 976 }; 1131 977 978 using Parent::forward; 979 using Parent::backward; 980 bool forward(const Edge& e) const { return !e.backward; } 981 bool backward(const Edge& e) const { return e.backward; } 982 1132 983 using Parent::first; 1133 984 void first(Edge& i) const { … … 1140 991 } 1141 992 void firstIn(Edge& i, const Node& n) const { 1142 Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n); 1143 i.backward=false; 1144 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 993 if (!backward(n)) { 994 Parent1::graph->firstIn(*static_cast<Graph1Edge*>(&i), n); 995 if (*static_cast<Graph1Edge*>(&i)==INVALID) 996 i=INVALID; 997 else 998 i.backward=false; 999 } else { 1145 1000 Parent2::graph->firstIn(*static_cast<Graph2Edge*>(&i), n); 1146 1001 i.backward=true; … … 1148 1003 } 1149 1004 void firstOut(Edge& i, const Node& n) const { 1150 Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n); 1151 i.backward=false; 1152 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 1005 if (!backward(n)) { 1006 Parent1::graph->firstOut(*static_cast<Graph1Edge*>(&i), n); 1007 if (*static_cast<Graph1Edge*>(&i)==INVALID) 1008 i=INVALID; 1009 else 1010 i.backward=false; 1011 } else { 1153 1012 Parent2::graph->firstOut(*static_cast<Graph2Edge*>(&i), n); 1154 1013 i.backward=true; … … 1171 1030 if (!(i.backward)) { 1172 1031 Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i)); 1173 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 1174 Parent2::graph->first(*static_cast<Graph2Edge*>(&i)); 1175 i.backward=true; 1176 } 1032 if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID; 1177 1033 } else { 1178 1034 Parent2::graph->nextIn(*static_cast<Graph2Edge*>(&i)); … … 1182 1038 if (!(i.backward)) { 1183 1039 Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i)); 1184 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 1185 Parent2::graph->first(*static_cast<Graph2Edge*>(&i)); 1186 i.backward=true; 1187 } 1040 if (*static_cast<Graph1Edge*>(&i)==INVALID) i=INVALID; 1188 1041 } else { 1189 1042 Parent2::graph->nextOut(*static_cast<Graph2Edge*>(&i)); … … 1348 1201 int edgeNum() const { return edge_set_graph->edgeNum(); } 1349 1202 1203 // NNode addOldNode() { 1204 // return Parent::addNode(); 1205 // } 1206 1207 // ENode addNewNode() { 1208 // return edge_set_graph->addNode(); 1209 // } 1210 1350 1211 Edge addEdge(const Node& u, const Node& v) { 1351 1212 return edge_set_graph->addEdge((*e_node)[u], (*e_node)[v]); … … 1393 1254 typedef _EdgeSetGraph EdgeSetGraph; 1394 1255 typedef IterableGraphExtender< 1395 NewEdgeSetGraphWrapper <_Graph, _EdgeSetGraph> > Parent;1256 NewEdgeSetGraphWrapperBase<_Graph, _EdgeSetGraph> > Parent; 1396 1257 protected: 1397 1258 NewEdgeSetGraphWrapper() { } … … 1410 1271 }; 1411 1272 1273 /*! A graph wrapper class for the following functionality. 1274 The same as NewEdgeSetGrapWrapper, but the bijection and the graph of 1275 new edges is andled inthe class. 1276 */ 1277 template <typename _Graph, typename _EdgeSetGraph> 1278 class NewEdgeSetGraphWrapper2 : 1279 public IterableGraphExtender< 1280 NewEdgeSetGraphWrapperBase<_Graph, _EdgeSetGraph> > { 1281 public: 1282 typedef _Graph Graph; 1283 typedef _EdgeSetGraph EdgeSetGraph; 1284 typedef IterableGraphExtender< 1285 NewEdgeSetGraphWrapperBase<_Graph, _EdgeSetGraph> > Parent; 1286 protected: 1287 _EdgeSetGraph _edge_set_graph; 1288 typename Graph::template NodeMap<typename EdgeSetGraph::Node> _e_node; 1289 typename EdgeSetGraph::template NodeMap<typename Graph::Node> _n_node; 1290 NewEdgeSetGraphWrapper2() { } 1291 public: 1292 typedef typename Graph::Node Node; 1293 // typedef typename Parent::Edge Edge; 1294 1295 NewEdgeSetGraphWrapper2(_Graph& _graph) : 1296 _edge_set_graph(), 1297 _e_node(_graph), _n_node(_edge_set_graph) { 1298 setGraph(_graph); 1299 setEdgeSetGraph(_edge_set_graph); 1300 setNodeMap(_n_node); setENodeMap(_e_node); 1301 Node n; 1302 for (this->first(n); n!=INVALID; this->next(n)) { 1303 typename EdgeSetGraph::Node e=_edge_set_graph.addNode(); 1304 _e_node.set(n, e); 1305 _n_node.set(e, n); 1306 } 1307 } 1308 1309 // Node addNode() { 1310 // Node n=(*this).Parent::addNode(); 1311 // typename EdgeSetGraph::Node e=_edge_set_graph.addNode(); 1312 // _e_node.set(n, e); 1313 // _n_node.set(e, n); 1314 // return n; 1315 // } 1316 1317 }; 1412 1318 1413 1319 /*! A graph wrapper base class … … 1418 1324 In an other point of view, _Graph1 is extended with 1419 1325 the edge-set of _Graph2. 1326 \warning we need specialize dimplementations 1327 \todo we need specialize dimplementations 1328 \bug we need specialize dimplementations 1420 1329 */ 1421 1330 template <typename _Graph1, typename _Graph2, typename Enable=void> … … 1507 1416 void nextIn(Edge& i) const { 1508 1417 if (!(i.backward)) { 1418 Node n=target(i); 1509 1419 Parent1::graph->nextIn(*static_cast<Graph1Edge*>(&i)); 1510 1420 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 1511 graph2->first (*static_cast<Graph2Edge*>(&i));1421 graph2->firstIn(*static_cast<Graph2Edge*>(&i), n); 1512 1422 i.backward=true; 1513 1423 } … … 1518 1428 void nextOut(Edge& i) const { 1519 1429 if (!(i.backward)) { 1430 Node n=source(i); 1520 1431 Parent1::graph->nextOut(*static_cast<Graph1Edge*>(&i)); 1521 1432 if (*static_cast<Graph1Edge*>(&i)==INVALID) { 1522 graph2->first (*static_cast<Graph2Edge*>(&i));1433 graph2->firstOut(*static_cast<Graph2Edge*>(&i), n); 1523 1434 i.backward=true; 1524 1435 }
Note: See TracChangeset
for help on using the changeset viewer.