Changeset 956:141f9c0db4a3 in lemon for lemon/bits/edge_set_extender.h
 Timestamp:
 03/06/10 15:35:12 (10 years ago)
 Branch:
 default
 Children:
 957:f802439d2b58, 959:38213abd2911, 1041:f112c18bc304
 Phase:
 public
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

lemon/bits/edge_set_extender.h
r732 r956 1 /* * C++*1 /* * mode: C++; indenttabsmode: nil; * 2 2 * 3 * This file is a part of LEMON, a generic C++ optimization library 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 * Copyright (C) 200320 085 * Copyright (C) 20032010 6 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). … … 64 64 Node oppositeNode(const Node &n, const Arc &e) const { 65 65 if (n == Parent::source(e)) 66 66 return Parent::target(e); 67 67 else if(n==Parent::target(e)) 68 68 return Parent::source(e); 69 69 else 70 70 return INVALID; 71 71 } 72 72 … … 92 92 // Iterable extensions 93 93 94 class NodeIt : public Node { 94 class NodeIt : public Node { 95 95 const Digraph* digraph; 96 96 public: … … 101 101 102 102 explicit NodeIt(const Digraph& _graph) : digraph(&_graph) { 103 104 } 105 106 NodeIt(const Digraph& _graph, const Node& node) 107 108 109 NodeIt& operator++() { 110 111 return *this; 112 } 113 114 }; 115 116 117 class ArcIt : public Arc { 103 _graph.first(static_cast<Node&>(*this)); 104 } 105 106 NodeIt(const Digraph& _graph, const Node& node) 107 : Node(node), digraph(&_graph) {} 108 109 NodeIt& operator++() { 110 digraph>next(*this); 111 return *this; 112 } 113 114 }; 115 116 117 class ArcIt : public Arc { 118 118 const Digraph* digraph; 119 119 public: … … 124 124 125 125 explicit ArcIt(const Digraph& _graph) : digraph(&_graph) { 126 127 } 128 129 ArcIt(const Digraph& _graph, const Arc& e) : 130 131 132 ArcIt& operator++() { 133 134 return *this; 135 } 136 137 }; 138 139 140 class OutArcIt : public Arc { 126 _graph.first(static_cast<Arc&>(*this)); 127 } 128 129 ArcIt(const Digraph& _graph, const Arc& e) : 130 Arc(e), digraph(&_graph) { } 131 132 ArcIt& operator++() { 133 digraph>next(*this); 134 return *this; 135 } 136 137 }; 138 139 140 class OutArcIt : public Arc { 141 141 const Digraph* digraph; 142 142 public: … … 146 146 OutArcIt(Invalid i) : Arc(i) { } 147 147 148 OutArcIt(const Digraph& _graph, const Node& node) 149 150 151 } 152 153 OutArcIt(const Digraph& _graph, const Arc& arc) 154 155 156 OutArcIt& operator++() { 157 158 return *this; 159 } 160 161 }; 162 163 164 class InArcIt : public Arc { 148 OutArcIt(const Digraph& _graph, const Node& node) 149 : digraph(&_graph) { 150 _graph.firstOut(*this, node); 151 } 152 153 OutArcIt(const Digraph& _graph, const Arc& arc) 154 : Arc(arc), digraph(&_graph) {} 155 156 OutArcIt& operator++() { 157 digraph>nextOut(*this); 158 return *this; 159 } 160 161 }; 162 163 164 class InArcIt : public Arc { 165 165 const Digraph* digraph; 166 166 public: … … 170 170 InArcIt(Invalid i) : Arc(i) { } 171 171 172 InArcIt(const Digraph& _graph, const Node& node) 173 174 175 } 176 177 InArcIt(const Digraph& _graph, const Arc& arc) : 178 179 180 InArcIt& operator++() { 181 182 return *this; 172 InArcIt(const Digraph& _graph, const Node& node) 173 : digraph(&_graph) { 174 _graph.firstIn(*this, node); 175 } 176 177 InArcIt(const Digraph& _graph, const Arc& arc) : 178 Arc(arc), digraph(&_graph) {} 179 180 InArcIt& operator++() { 181 digraph>nextIn(*this); 182 return *this; 183 183 } 184 184 … … 216 216 217 217 // Mappable extension 218 218 219 219 template <typename _Value> 220 class ArcMap 220 class ArcMap 221 221 : public MapExtender<DefaultMap<Digraph, Arc, _Value> > { 222 222 typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; 223 223 224 224 public: 225 explicit ArcMap(const Digraph& _g) 226 227 ArcMap(const Digraph& _g, const _Value& _v) 228 225 explicit ArcMap(const Digraph& _g) 226 : Parent(_g) {} 227 ArcMap(const Digraph& _g, const _Value& _v) 228 : Parent(_g, _v) {} 229 229 230 230 ArcMap& operator=(const ArcMap& cmap) { 231 231 return operator=<ArcMap>(cmap); 232 232 } 233 233 … … 235 235 ArcMap& operator=(const CMap& cmap) { 236 236 Parent::operator=(cmap); 237 237 return *this; 238 238 } 239 239 … … 248 248 return arc; 249 249 } 250 250 251 251 void clear() { 252 252 notifier(Arc()).clear(); … … 311 311 Node oppositeNode(const Node &n, const Edge &e) const { 312 312 if( n == Parent::u(e)) 313 313 return Parent::v(e); 314 314 else if( n == Parent::v(e)) 315 315 return Parent::u(e); 316 316 else 317 317 return INVALID; 318 318 } 319 319 … … 339 339 340 340 using Parent::notifier; 341 341 342 342 ArcNotifier& notifier(Arc) const { 343 343 return arc_notifier; … … 349 349 350 350 351 class NodeIt : public Node { 351 class NodeIt : public Node { 352 352 const Graph* graph; 353 353 public: … … 358 358 359 359 explicit NodeIt(const Graph& _graph) : graph(&_graph) { 360 361 } 362 363 NodeIt(const Graph& _graph, const Node& node) 364 365 366 NodeIt& operator++() { 367 368 return *this; 369 } 370 371 }; 372 373 374 class ArcIt : public Arc { 360 _graph.first(static_cast<Node&>(*this)); 361 } 362 363 NodeIt(const Graph& _graph, const Node& node) 364 : Node(node), graph(&_graph) {} 365 366 NodeIt& operator++() { 367 graph>next(*this); 368 return *this; 369 } 370 371 }; 372 373 374 class ArcIt : public Arc { 375 375 const Graph* graph; 376 376 public: … … 381 381 382 382 explicit ArcIt(const Graph& _graph) : graph(&_graph) { 383 384 } 385 386 ArcIt(const Graph& _graph, const Arc& e) : 387 388 389 ArcIt& operator++() { 390 391 return *this; 392 } 393 394 }; 395 396 397 class OutArcIt : public Arc { 383 _graph.first(static_cast<Arc&>(*this)); 384 } 385 386 ArcIt(const Graph& _graph, const Arc& e) : 387 Arc(e), graph(&_graph) { } 388 389 ArcIt& operator++() { 390 graph>next(*this); 391 return *this; 392 } 393 394 }; 395 396 397 class OutArcIt : public Arc { 398 398 const Graph* graph; 399 399 public: … … 403 403 OutArcIt(Invalid i) : Arc(i) { } 404 404 405 OutArcIt(const Graph& _graph, const Node& node) 406 407 408 } 409 410 OutArcIt(const Graph& _graph, const Arc& arc) 411 412 413 OutArcIt& operator++() { 414 415 return *this; 416 } 417 418 }; 419 420 421 class InArcIt : public Arc { 405 OutArcIt(const Graph& _graph, const Node& node) 406 : graph(&_graph) { 407 _graph.firstOut(*this, node); 408 } 409 410 OutArcIt(const Graph& _graph, const Arc& arc) 411 : Arc(arc), graph(&_graph) {} 412 413 OutArcIt& operator++() { 414 graph>nextOut(*this); 415 return *this; 416 } 417 418 }; 419 420 421 class InArcIt : public Arc { 422 422 const Graph* graph; 423 423 public: … … 427 427 InArcIt(Invalid i) : Arc(i) { } 428 428 429 InArcIt(const Graph& _graph, const Node& node) 430 431 432 } 433 434 InArcIt(const Graph& _graph, const Arc& arc) : 435 436 437 InArcIt& operator++() { 438 439 return *this; 440 } 441 442 }; 443 444 445 class EdgeIt : public Parent::Edge { 429 InArcIt(const Graph& _graph, const Node& node) 430 : graph(&_graph) { 431 _graph.firstIn(*this, node); 432 } 433 434 InArcIt(const Graph& _graph, const Arc& arc) : 435 Arc(arc), graph(&_graph) {} 436 437 InArcIt& operator++() { 438 graph>nextIn(*this); 439 return *this; 440 } 441 442 }; 443 444 445 class EdgeIt : public Parent::Edge { 446 446 const Graph* graph; 447 447 public: … … 452 452 453 453 explicit EdgeIt(const Graph& _graph) : graph(&_graph) { 454 455 } 456 457 EdgeIt(const Graph& _graph, const Edge& e) : 458 459 460 EdgeIt& operator++() { 461 462 return *this; 454 _graph.first(static_cast<Edge&>(*this)); 455 } 456 457 EdgeIt(const Graph& _graph, const Edge& e) : 458 Edge(e), graph(&_graph) { } 459 460 EdgeIt& operator++() { 461 graph>next(*this); 462 return *this; 463 463 } 464 464 … … 476 476 477 477 IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) { 478 478 _graph.firstInc(*this, direction, n); 479 479 } 480 480 481 481 IncEdgeIt(const Graph& _graph, const Edge &ue, const Node &n) 482 483 482 : graph(&_graph), Edge(ue) { 483 direction = (_graph.source(ue) == n); 484 484 } 485 485 486 486 IncEdgeIt& operator++() { 487 488 return *this; 487 graph>nextInc(*this, direction); 488 return *this; 489 489 } 490 490 }; … … 533 533 534 534 template <typename _Value> 535 class ArcMap 535 class ArcMap 536 536 : public MapExtender<DefaultMap<Graph, Arc, _Value> > { 537 537 typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent; 538 538 539 539 public: 540 explicit ArcMap(const Graph& _g) 541 542 ArcMap(const Graph& _g, const _Value& _v) 543 540 explicit ArcMap(const Graph& _g) 541 : Parent(_g) {} 542 ArcMap(const Graph& _g, const _Value& _v) 543 : Parent(_g, _v) {} 544 544 545 545 ArcMap& operator=(const ArcMap& cmap) { 546 546 return operator=<ArcMap>(cmap); 547 547 } 548 548 … … 550 550 ArcMap& operator=(const CMap& cmap) { 551 551 Parent::operator=(cmap); 552 552 return *this; 553 553 } 554 554 … … 557 557 558 558 template <typename _Value> 559 class EdgeMap 559 class EdgeMap 560 560 : public MapExtender<DefaultMap<Graph, Edge, _Value> > { 561 561 typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent; 562 562 563 563 public: 564 explicit EdgeMap(const Graph& _g) 565 566 567 EdgeMap(const Graph& _g, const _Value& _v) 568 564 explicit EdgeMap(const Graph& _g) 565 : Parent(_g) {} 566 567 EdgeMap(const Graph& _g, const _Value& _v) 568 : Parent(_g, _v) {} 569 569 570 570 EdgeMap& operator=(const EdgeMap& cmap) { 571 571 return operator=<EdgeMap>(cmap); 572 572 } 573 573 … … 575 575 EdgeMap& operator=(const CMap& cmap) { 576 576 Parent::operator=(cmap); 577 577 return *this; 578 578 } 579 579 … … 592 592 return edge; 593 593 } 594 594 595 595 void clear() { 596 596 notifier(Arc()).clear(); … … 618 618 arc_notifier.clear(); 619 619 } 620 620 621 621 }; 622 622
Note: See TracChangeset
for help on using the changeset viewer.