0
4
0
| ... | ... |
@@ -322,111 +322,111 @@ |
| 322 | 322 |
arc_notifier.clear(); |
| 323 | 323 |
node_notifier.clear(); |
| 324 | 324 |
} |
| 325 | 325 |
}; |
| 326 | 326 |
|
| 327 | 327 |
/// \ingroup _graphbits |
| 328 | 328 |
/// |
| 329 | 329 |
/// \brief Extender for the Graphs |
| 330 | 330 |
template <typename Base> |
| 331 | 331 |
class GraphExtender : public Base {
|
| 332 | 332 |
public: |
| 333 | 333 |
|
| 334 | 334 |
typedef Base Parent; |
| 335 | 335 |
typedef GraphExtender Graph; |
| 336 | 336 |
|
| 337 | 337 |
typedef True UndirectedTag; |
| 338 | 338 |
|
| 339 | 339 |
typedef typename Parent::Node Node; |
| 340 | 340 |
typedef typename Parent::Arc Arc; |
| 341 | 341 |
typedef typename Parent::Edge Edge; |
| 342 | 342 |
|
| 343 | 343 |
// Graph extension |
| 344 | 344 |
|
| 345 | 345 |
int maxId(Node) const {
|
| 346 | 346 |
return Parent::maxNodeId(); |
| 347 | 347 |
} |
| 348 | 348 |
|
| 349 | 349 |
int maxId(Arc) const {
|
| 350 | 350 |
return Parent::maxArcId(); |
| 351 | 351 |
} |
| 352 | 352 |
|
| 353 | 353 |
int maxId(Edge) const {
|
| 354 | 354 |
return Parent::maxEdgeId(); |
| 355 | 355 |
} |
| 356 | 356 |
|
| 357 | 357 |
Node fromId(int id, Node) const {
|
| 358 | 358 |
return Parent::nodeFromId(id); |
| 359 | 359 |
} |
| 360 | 360 |
|
| 361 | 361 |
Arc fromId(int id, Arc) const {
|
| 362 | 362 |
return Parent::arcFromId(id); |
| 363 | 363 |
} |
| 364 | 364 |
|
| 365 | 365 |
Edge fromId(int id, Edge) const {
|
| 366 | 366 |
return Parent::edgeFromId(id); |
| 367 | 367 |
} |
| 368 | 368 |
|
| 369 | 369 |
Node oppositeNode(const Node &n, const Edge &e) const {
|
| 370 |
if( n == Parent::source(e)) |
|
| 371 |
return Parent::target(e); |
|
| 372 |
else if( n == Parent::target(e)) |
|
| 373 |
return Parent::source(e); |
|
| 370 |
if( n == Parent::u(e)) |
|
| 371 |
return Parent::v(e); |
|
| 372 |
else if( n == Parent::v(e)) |
|
| 373 |
return Parent::u(e); |
|
| 374 | 374 |
else |
| 375 | 375 |
return INVALID; |
| 376 | 376 |
} |
| 377 | 377 |
|
| 378 | 378 |
Arc oppositeArc(const Arc &arc) const {
|
| 379 | 379 |
return Parent::direct(arc, !Parent::direction(arc)); |
| 380 | 380 |
} |
| 381 | 381 |
|
| 382 | 382 |
using Parent::direct; |
| 383 | 383 |
Arc direct(const Edge &edge, const Node &node) const {
|
| 384 |
return Parent::direct(edge, Parent:: |
|
| 384 |
return Parent::direct(edge, Parent::u(edge) == node); |
|
| 385 | 385 |
} |
| 386 | 386 |
|
| 387 | 387 |
// Alterable extension |
| 388 | 388 |
|
| 389 | 389 |
typedef AlterationNotifier<GraphExtender, Node> NodeNotifier; |
| 390 | 390 |
typedef AlterationNotifier<GraphExtender, Arc> ArcNotifier; |
| 391 | 391 |
typedef AlterationNotifier<GraphExtender, Edge> EdgeNotifier; |
| 392 | 392 |
|
| 393 | 393 |
|
| 394 | 394 |
protected: |
| 395 | 395 |
|
| 396 | 396 |
mutable NodeNotifier node_notifier; |
| 397 | 397 |
mutable ArcNotifier arc_notifier; |
| 398 | 398 |
mutable EdgeNotifier edge_notifier; |
| 399 | 399 |
|
| 400 | 400 |
public: |
| 401 | 401 |
|
| 402 | 402 |
NodeNotifier& notifier(Node) const {
|
| 403 | 403 |
return node_notifier; |
| 404 | 404 |
} |
| 405 | 405 |
|
| 406 | 406 |
ArcNotifier& notifier(Arc) const {
|
| 407 | 407 |
return arc_notifier; |
| 408 | 408 |
} |
| 409 | 409 |
|
| 410 | 410 |
EdgeNotifier& notifier(Edge) const {
|
| 411 | 411 |
return edge_notifier; |
| 412 | 412 |
} |
| 413 | 413 |
|
| 414 | 414 |
|
| 415 | 415 |
|
| 416 | 416 |
class NodeIt : public Node {
|
| 417 | 417 |
const Graph* _graph; |
| 418 | 418 |
public: |
| 419 | 419 |
|
| 420 | 420 |
NodeIt() {}
|
| 421 | 421 |
|
| 422 | 422 |
NodeIt(Invalid i) : Node(i) { }
|
| 423 | 423 |
|
| 424 | 424 |
explicit NodeIt(const Graph& graph) : _graph(&graph) {
|
| 425 | 425 |
_graph->first(static_cast<Node&>(*this)); |
| 426 | 426 |
} |
| 427 | 427 |
|
| 428 | 428 |
NodeIt(const Graph& graph, const Node& node) |
| 429 | 429 |
: Node(node), _graph(&graph) {}
|
| 430 | 430 |
|
| 431 | 431 |
NodeIt& operator++() {
|
| 432 | 432 |
_graph->next(*this); |
| ... | ... |
@@ -541,103 +541,103 @@ |
| 541 | 541 |
|
| 542 | 542 |
IncEdgeIt(const Graph& graph, const Node &node) : _graph(&graph) {
|
| 543 | 543 |
_graph->firstInc(*this, _direction, node); |
| 544 | 544 |
} |
| 545 | 545 |
|
| 546 | 546 |
IncEdgeIt(const Graph& graph, const Edge &edge, const Node &node) |
| 547 | 547 |
: _graph(&graph), Edge(edge) {
|
| 548 | 548 |
_direction = (_graph->source(edge) == node); |
| 549 | 549 |
} |
| 550 | 550 |
|
| 551 | 551 |
IncEdgeIt& operator++() {
|
| 552 | 552 |
_graph->nextInc(*this, _direction); |
| 553 | 553 |
return *this; |
| 554 | 554 |
} |
| 555 | 555 |
}; |
| 556 | 556 |
|
| 557 | 557 |
/// \brief Base node of the iterator |
| 558 | 558 |
/// |
| 559 | 559 |
/// Returns the base node (ie. the source in this case) of the iterator |
| 560 | 560 |
Node baseNode(const OutArcIt &arc) const {
|
| 561 | 561 |
return Parent::source(static_cast<const Arc&>(arc)); |
| 562 | 562 |
} |
| 563 | 563 |
/// \brief Running node of the iterator |
| 564 | 564 |
/// |
| 565 | 565 |
/// Returns the running node (ie. the target in this case) of the |
| 566 | 566 |
/// iterator |
| 567 | 567 |
Node runningNode(const OutArcIt &arc) const {
|
| 568 | 568 |
return Parent::target(static_cast<const Arc&>(arc)); |
| 569 | 569 |
} |
| 570 | 570 |
|
| 571 | 571 |
/// \brief Base node of the iterator |
| 572 | 572 |
/// |
| 573 | 573 |
/// Returns the base node (ie. the target in this case) of the iterator |
| 574 | 574 |
Node baseNode(const InArcIt &arc) const {
|
| 575 | 575 |
return Parent::target(static_cast<const Arc&>(arc)); |
| 576 | 576 |
} |
| 577 | 577 |
/// \brief Running node of the iterator |
| 578 | 578 |
/// |
| 579 | 579 |
/// Returns the running node (ie. the source in this case) of the |
| 580 | 580 |
/// iterator |
| 581 | 581 |
Node runningNode(const InArcIt &arc) const {
|
| 582 | 582 |
return Parent::source(static_cast<const Arc&>(arc)); |
| 583 | 583 |
} |
| 584 | 584 |
|
| 585 | 585 |
/// Base node of the iterator |
| 586 | 586 |
/// |
| 587 | 587 |
/// Returns the base node of the iterator |
| 588 | 588 |
Node baseNode(const IncEdgeIt &edge) const {
|
| 589 |
return edge._direction ? |
|
| 589 |
return edge._direction ? u(edge) : v(edge); |
|
| 590 | 590 |
} |
| 591 | 591 |
/// Running node of the iterator |
| 592 | 592 |
/// |
| 593 | 593 |
/// Returns the running node of the iterator |
| 594 | 594 |
Node runningNode(const IncEdgeIt &edge) const {
|
| 595 |
return edge._direction ? |
|
| 595 |
return edge._direction ? v(edge) : u(edge); |
|
| 596 | 596 |
} |
| 597 | 597 |
|
| 598 | 598 |
// Mappable extension |
| 599 | 599 |
|
| 600 | 600 |
template <typename _Value> |
| 601 | 601 |
class NodeMap |
| 602 | 602 |
: public MapExtender<DefaultMap<Graph, Node, _Value> > {
|
| 603 | 603 |
public: |
| 604 | 604 |
typedef GraphExtender Graph; |
| 605 | 605 |
typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent; |
| 606 | 606 |
|
| 607 | 607 |
NodeMap(const Graph& graph) |
| 608 | 608 |
: Parent(graph) {}
|
| 609 | 609 |
NodeMap(const Graph& graph, const _Value& value) |
| 610 | 610 |
: Parent(graph, value) {}
|
| 611 | 611 |
|
| 612 | 612 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 613 | 613 |
return operator=<NodeMap>(cmap); |
| 614 | 614 |
} |
| 615 | 615 |
|
| 616 | 616 |
template <typename CMap> |
| 617 | 617 |
NodeMap& operator=(const CMap& cmap) {
|
| 618 | 618 |
Parent::operator=(cmap); |
| 619 | 619 |
return *this; |
| 620 | 620 |
} |
| 621 | 621 |
|
| 622 | 622 |
}; |
| 623 | 623 |
|
| 624 | 624 |
template <typename _Value> |
| 625 | 625 |
class ArcMap |
| 626 | 626 |
: public MapExtender<DefaultMap<Graph, Arc, _Value> > {
|
| 627 | 627 |
public: |
| 628 | 628 |
typedef GraphExtender Graph; |
| 629 | 629 |
typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent; |
| 630 | 630 |
|
| 631 | 631 |
ArcMap(const Graph& graph) |
| 632 | 632 |
: Parent(graph) {}
|
| 633 | 633 |
ArcMap(const Graph& graph, const _Value& value) |
| 634 | 634 |
: Parent(graph, value) {}
|
| 635 | 635 |
|
| 636 | 636 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 637 | 637 |
return operator=<ArcMap>(cmap); |
| 638 | 638 |
} |
| 639 | 639 |
|
| 640 | 640 |
template <typename CMap> |
| 641 | 641 |
ArcMap& operator=(const CMap& cmap) {
|
| 642 | 642 |
Parent::operator=(cmap); |
| 643 | 643 |
return *this; |
| ... | ... |
@@ -422,65 +422,65 @@ |
| 422 | 422 |
/// Gives back the opposite node on the given arc. |
| 423 | 423 |
Node oppositeNode(const Node&, const Arc&) const { return INVALID; }
|
| 424 | 424 |
|
| 425 | 425 |
/// \brief Read write map of the nodes to type \c T. |
| 426 | 426 |
/// |
| 427 | 427 |
/// ReadWrite map of the nodes to type \c T. |
| 428 | 428 |
/// \sa Reference |
| 429 | 429 |
template<class T> |
| 430 | 430 |
class NodeMap : public ReadWriteMap< Node, T > {
|
| 431 | 431 |
public: |
| 432 | 432 |
|
| 433 | 433 |
///\e |
| 434 | 434 |
NodeMap(const Digraph&) { }
|
| 435 | 435 |
///\e |
| 436 | 436 |
NodeMap(const Digraph&, T) { }
|
| 437 | 437 |
|
| 438 | 438 |
///Copy constructor |
| 439 | 439 |
NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
|
| 440 | 440 |
///Assignment operator |
| 441 | 441 |
template <typename CMap> |
| 442 | 442 |
NodeMap& operator=(const CMap&) {
|
| 443 | 443 |
checkConcept<ReadMap<Node, T>, CMap>(); |
| 444 | 444 |
return *this; |
| 445 | 445 |
} |
| 446 | 446 |
}; |
| 447 | 447 |
|
| 448 | 448 |
/// \brief Read write map of the arcs to type \c T. |
| 449 | 449 |
/// |
| 450 | 450 |
/// Reference map of the arcs to type \c T. |
| 451 | 451 |
/// \sa Reference |
| 452 | 452 |
template<class T> |
| 453 | 453 |
class ArcMap : public ReadWriteMap<Arc,T> {
|
| 454 | 454 |
public: |
| 455 | 455 |
|
| 456 | 456 |
///\e |
| 457 | 457 |
ArcMap(const Digraph&) { }
|
| 458 | 458 |
///\e |
| 459 | 459 |
ArcMap(const Digraph&, T) { }
|
| 460 | 460 |
///Copy constructor |
| 461 | 461 |
ArcMap(const ArcMap& em) : ReadWriteMap<Arc,T>(em) { }
|
| 462 | 462 |
///Assignment operator |
| 463 | 463 |
template <typename CMap> |
| 464 | 464 |
ArcMap& operator=(const CMap&) {
|
| 465 | 465 |
checkConcept<ReadMap<Arc, T>, CMap>(); |
| 466 | 466 |
return *this; |
| 467 | 467 |
} |
| 468 | 468 |
}; |
| 469 | 469 |
|
| 470 |
template <typename |
|
| 470 |
template <typename _Digraph> |
|
| 471 | 471 |
struct Constraints {
|
| 472 | 472 |
void constraints() {
|
| 473 |
checkConcept<IterableDigraphComponent<>, Digraph>(); |
|
| 474 |
checkConcept<IDableDigraphComponent<>, Digraph>(); |
|
| 475 |
checkConcept< |
|
| 473 |
checkConcept<IterableDigraphComponent<>, _Digraph>(); |
|
| 474 |
checkConcept<IDableDigraphComponent<>, _Digraph>(); |
|
| 475 |
checkConcept<MappableDigraphComponent<>, _Digraph>(); |
|
| 476 | 476 |
} |
| 477 | 477 |
}; |
| 478 | 478 |
|
| 479 | 479 |
}; |
| 480 | 480 |
|
| 481 | 481 |
} //namespace concepts |
| 482 | 482 |
} //namespace lemon |
| 483 | 483 |
|
| 484 | 484 |
|
| 485 | 485 |
|
| 486 | 486 |
#endif // LEMON_CONCEPT_DIGRAPH_H |
| ... | ... |
@@ -686,64 +686,64 @@ |
| 686 | 686 |
int maxId(Node) const { return -1; }
|
| 687 | 687 |
// Dummy parameter. |
| 688 | 688 |
int maxId(Edge) const { return -1; }
|
| 689 | 689 |
// Dummy parameter. |
| 690 | 690 |
int maxId(Arc) const { return -1; }
|
| 691 | 691 |
|
| 692 | 692 |
/// \brief Base node of the iterator |
| 693 | 693 |
/// |
| 694 | 694 |
/// Returns the base node (the source in this case) of the iterator |
| 695 | 695 |
Node baseNode(OutArcIt e) const {
|
| 696 | 696 |
return source(e); |
| 697 | 697 |
} |
| 698 | 698 |
/// \brief Running node of the iterator |
| 699 | 699 |
/// |
| 700 | 700 |
/// Returns the running node (the target in this case) of the |
| 701 | 701 |
/// iterator |
| 702 | 702 |
Node runningNode(OutArcIt e) const {
|
| 703 | 703 |
return target(e); |
| 704 | 704 |
} |
| 705 | 705 |
|
| 706 | 706 |
/// \brief Base node of the iterator |
| 707 | 707 |
/// |
| 708 | 708 |
/// Returns the base node (the target in this case) of the iterator |
| 709 | 709 |
Node baseNode(InArcIt e) const {
|
| 710 | 710 |
return target(e); |
| 711 | 711 |
} |
| 712 | 712 |
/// \brief Running node of the iterator |
| 713 | 713 |
/// |
| 714 | 714 |
/// Returns the running node (the source in this case) of the |
| 715 | 715 |
/// iterator |
| 716 | 716 |
Node runningNode(InArcIt e) const {
|
| 717 | 717 |
return source(e); |
| 718 | 718 |
} |
| 719 | 719 |
|
| 720 | 720 |
/// \brief Base node of the iterator |
| 721 | 721 |
/// |
| 722 | 722 |
/// Returns the base node of the iterator |
| 723 | 723 |
Node baseNode(IncEdgeIt) const {
|
| 724 | 724 |
return INVALID; |
| 725 | 725 |
} |
| 726 | 726 |
|
| 727 | 727 |
/// \brief Running node of the iterator |
| 728 | 728 |
/// |
| 729 | 729 |
/// Returns the running node of the iterator |
| 730 | 730 |
Node runningNode(IncEdgeIt) const {
|
| 731 | 731 |
return INVALID; |
| 732 | 732 |
} |
| 733 | 733 |
|
| 734 |
template <typename |
|
| 734 |
template <typename _Graph> |
|
| 735 | 735 |
struct Constraints {
|
| 736 | 736 |
void constraints() {
|
| 737 |
checkConcept<IterableGraphComponent<>, Graph>(); |
|
| 738 |
checkConcept<IDableGraphComponent<>, Graph>(); |
|
| 739 |
checkConcept< |
|
| 737 |
checkConcept<IterableGraphComponent<>, _Graph>(); |
|
| 738 |
checkConcept<IDableGraphComponent<>, _Graph>(); |
|
| 739 |
checkConcept<MappableGraphComponent<>, _Graph>(); |
|
| 740 | 740 |
} |
| 741 | 741 |
}; |
| 742 | 742 |
|
| 743 | 743 |
}; |
| 744 | 744 |
|
| 745 | 745 |
} |
| 746 | 746 |
|
| 747 | 747 |
} |
| 748 | 748 |
|
| 749 | 749 |
#endif |
| ... | ... |
@@ -425,98 +425,98 @@ |
| 425 | 425 |
bool operator<(const Node& node) const {return _id < node._id;}
|
| 426 | 426 |
}; |
| 427 | 427 |
|
| 428 | 428 |
class Edge {
|
| 429 | 429 |
friend class SmartGraphBase; |
| 430 | 430 |
protected: |
| 431 | 431 |
|
| 432 | 432 |
int _id; |
| 433 | 433 |
explicit Edge(int id) { _id = id;}
|
| 434 | 434 |
|
| 435 | 435 |
public: |
| 436 | 436 |
Edge() {}
|
| 437 | 437 |
Edge (Invalid) { _id = -1; }
|
| 438 | 438 |
bool operator==(const Edge& arc) const {return _id == arc._id;}
|
| 439 | 439 |
bool operator!=(const Edge& arc) const {return _id != arc._id;}
|
| 440 | 440 |
bool operator<(const Edge& arc) const {return _id < arc._id;}
|
| 441 | 441 |
}; |
| 442 | 442 |
|
| 443 | 443 |
class Arc {
|
| 444 | 444 |
friend class SmartGraphBase; |
| 445 | 445 |
protected: |
| 446 | 446 |
|
| 447 | 447 |
int _id; |
| 448 | 448 |
explicit Arc(int id) { _id = id;}
|
| 449 | 449 |
|
| 450 | 450 |
public: |
| 451 | 451 |
operator Edge() const { return edgeFromId(_id / 2); }
|
| 452 | 452 |
|
| 453 | 453 |
Arc() {}
|
| 454 | 454 |
Arc (Invalid) { _id = -1; }
|
| 455 | 455 |
bool operator==(const Arc& arc) const {return _id == arc._id;}
|
| 456 | 456 |
bool operator!=(const Arc& arc) const {return _id != arc._id;}
|
| 457 | 457 |
bool operator<(const Arc& arc) const {return _id < arc._id;}
|
| 458 | 458 |
}; |
| 459 | 459 |
|
| 460 | 460 |
|
| 461 | 461 |
|
| 462 | 462 |
SmartGraphBase() |
| 463 | 463 |
: nodes(), arcs() {}
|
| 464 | 464 |
|
| 465 | 465 |
|
| 466 | 466 |
int maxNodeId() const { return nodes.size()-1; }
|
| 467 | 467 |
int maxEdgeId() const { return arcs.size() / 2 - 1; }
|
| 468 | 468 |
int maxArcId() const { return arcs.size()-1; }
|
| 469 | 469 |
|
| 470 | 470 |
Node source(Arc e) const { return Node(arcs[e._id ^ 1].target); }
|
| 471 | 471 |
Node target(Arc e) const { return Node(arcs[e._id].target); }
|
| 472 | 472 |
|
| 473 |
Node source(Edge e) const { return Node(arcs[2 * e._id].target); }
|
|
| 474 |
Node target(Edge e) const { return Node(arcs[2 * e._id + 1].target); }
|
|
| 473 |
Node u(Edge e) const { return Node(arcs[2 * e._id].target); }
|
|
| 474 |
Node v(Edge e) const { return Node(arcs[2 * e._id + 1].target); }
|
|
| 475 | 475 |
|
| 476 | 476 |
static bool direction(Arc e) {
|
| 477 | 477 |
return (e._id & 1) == 1; |
| 478 | 478 |
} |
| 479 | 479 |
|
| 480 | 480 |
static Arc direct(Edge e, bool d) {
|
| 481 | 481 |
return Arc(e._id * 2 + (d ? 1 : 0)); |
| 482 | 482 |
} |
| 483 | 483 |
|
| 484 | 484 |
void first(Node& node) const {
|
| 485 | 485 |
node._id = nodes.size() - 1; |
| 486 | 486 |
} |
| 487 | 487 |
|
| 488 | 488 |
void next(Node& node) const {
|
| 489 | 489 |
--node._id; |
| 490 | 490 |
} |
| 491 | 491 |
|
| 492 | 492 |
void first(Arc& arc) const {
|
| 493 | 493 |
arc._id = arcs.size() - 1; |
| 494 | 494 |
} |
| 495 | 495 |
|
| 496 | 496 |
void next(Arc& arc) const {
|
| 497 | 497 |
--arc._id; |
| 498 | 498 |
} |
| 499 | 499 |
|
| 500 | 500 |
void first(Edge& arc) const {
|
| 501 | 501 |
arc._id = arcs.size() / 2 - 1; |
| 502 | 502 |
} |
| 503 | 503 |
|
| 504 | 504 |
void next(Edge& arc) const {
|
| 505 | 505 |
--arc._id; |
| 506 | 506 |
} |
| 507 | 507 |
|
| 508 | 508 |
void firstOut(Arc &arc, const Node& v) const {
|
| 509 | 509 |
arc._id = nodes[v._id].first_out; |
| 510 | 510 |
} |
| 511 | 511 |
void nextOut(Arc &arc) const {
|
| 512 | 512 |
arc._id = arcs[arc._id].next_out; |
| 513 | 513 |
} |
| 514 | 514 |
|
| 515 | 515 |
void firstIn(Arc &arc, const Node& v) const {
|
| 516 | 516 |
arc._id = ((nodes[v._id].first_out) ^ 1); |
| 517 | 517 |
if (arc._id == -2) arc._id = -1; |
| 518 | 518 |
} |
| 519 | 519 |
void nextIn(Arc &arc) const {
|
| 520 | 520 |
arc._id = ((arcs[arc._id ^ 1].next_out) ^ 1); |
| 521 | 521 |
if (arc._id == -2) arc._id = -1; |
| 522 | 522 |
} |
0 comments (0 inline)