0
4
0
| ... | ... |
@@ -274,207 +274,207 @@ |
| 274 | 274 |
Arc arc = Parent::addArc(from, to); |
| 275 | 275 |
notifier(Arc()).add(arc); |
| 276 | 276 |
return arc; |
| 277 | 277 |
} |
| 278 | 278 |
|
| 279 | 279 |
void clear() {
|
| 280 | 280 |
notifier(Arc()).clear(); |
| 281 | 281 |
notifier(Node()).clear(); |
| 282 | 282 |
Parent::clear(); |
| 283 | 283 |
} |
| 284 | 284 |
|
| 285 | 285 |
template <typename Digraph, typename NodeRefMap, typename ArcRefMap> |
| 286 | 286 |
void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
|
| 287 | 287 |
Parent::build(digraph, nodeRef, arcRef); |
| 288 | 288 |
notifier(Node()).build(); |
| 289 | 289 |
notifier(Arc()).build(); |
| 290 | 290 |
} |
| 291 | 291 |
|
| 292 | 292 |
void erase(const Node& node) {
|
| 293 | 293 |
Arc arc; |
| 294 | 294 |
Parent::firstOut(arc, node); |
| 295 | 295 |
while (arc != INVALID ) {
|
| 296 | 296 |
erase(arc); |
| 297 | 297 |
Parent::firstOut(arc, node); |
| 298 | 298 |
} |
| 299 | 299 |
|
| 300 | 300 |
Parent::firstIn(arc, node); |
| 301 | 301 |
while (arc != INVALID ) {
|
| 302 | 302 |
erase(arc); |
| 303 | 303 |
Parent::firstIn(arc, node); |
| 304 | 304 |
} |
| 305 | 305 |
|
| 306 | 306 |
notifier(Node()).erase(node); |
| 307 | 307 |
Parent::erase(node); |
| 308 | 308 |
} |
| 309 | 309 |
|
| 310 | 310 |
void erase(const Arc& arc) {
|
| 311 | 311 |
notifier(Arc()).erase(arc); |
| 312 | 312 |
Parent::erase(arc); |
| 313 | 313 |
} |
| 314 | 314 |
|
| 315 | 315 |
DigraphExtender() {
|
| 316 | 316 |
node_notifier.setContainer(*this); |
| 317 | 317 |
arc_notifier.setContainer(*this); |
| 318 | 318 |
} |
| 319 | 319 |
|
| 320 | 320 |
|
| 321 | 321 |
~DigraphExtender() {
|
| 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); |
| 433 | 433 |
return *this; |
| 434 | 434 |
} |
| 435 | 435 |
|
| 436 | 436 |
}; |
| 437 | 437 |
|
| 438 | 438 |
|
| 439 | 439 |
class ArcIt : public Arc {
|
| 440 | 440 |
const Graph* _graph; |
| 441 | 441 |
public: |
| 442 | 442 |
|
| 443 | 443 |
ArcIt() { }
|
| 444 | 444 |
|
| 445 | 445 |
ArcIt(Invalid i) : Arc(i) { }
|
| 446 | 446 |
|
| 447 | 447 |
explicit ArcIt(const Graph& graph) : _graph(&graph) {
|
| 448 | 448 |
_graph->first(static_cast<Arc&>(*this)); |
| 449 | 449 |
} |
| 450 | 450 |
|
| 451 | 451 |
ArcIt(const Graph& graph, const Arc& arc) : |
| 452 | 452 |
Arc(arc), _graph(&graph) { }
|
| 453 | 453 |
|
| 454 | 454 |
ArcIt& operator++() {
|
| 455 | 455 |
_graph->next(*this); |
| 456 | 456 |
return *this; |
| 457 | 457 |
} |
| 458 | 458 |
|
| 459 | 459 |
}; |
| 460 | 460 |
|
| 461 | 461 |
|
| 462 | 462 |
class OutArcIt : public Arc {
|
| 463 | 463 |
const Graph* _graph; |
| 464 | 464 |
public: |
| 465 | 465 |
|
| 466 | 466 |
OutArcIt() { }
|
| 467 | 467 |
|
| 468 | 468 |
OutArcIt(Invalid i) : Arc(i) { }
|
| 469 | 469 |
|
| 470 | 470 |
OutArcIt(const Graph& graph, const Node& node) |
| 471 | 471 |
: _graph(&graph) {
|
| 472 | 472 |
_graph->firstOut(*this, node); |
| 473 | 473 |
} |
| 474 | 474 |
|
| 475 | 475 |
OutArcIt(const Graph& graph, const Arc& arc) |
| 476 | 476 |
: Arc(arc), _graph(&graph) {}
|
| 477 | 477 |
|
| 478 | 478 |
OutArcIt& operator++() {
|
| 479 | 479 |
_graph->nextOut(*this); |
| 480 | 480 |
return *this; |
| ... | ... |
@@ -493,199 +493,199 @@ |
| 493 | 493 |
|
| 494 | 494 |
InArcIt(const Graph& graph, const Node& node) |
| 495 | 495 |
: _graph(&graph) {
|
| 496 | 496 |
_graph->firstIn(*this, node); |
| 497 | 497 |
} |
| 498 | 498 |
|
| 499 | 499 |
InArcIt(const Graph& graph, const Arc& arc) : |
| 500 | 500 |
Arc(arc), _graph(&graph) {}
|
| 501 | 501 |
|
| 502 | 502 |
InArcIt& operator++() {
|
| 503 | 503 |
_graph->nextIn(*this); |
| 504 | 504 |
return *this; |
| 505 | 505 |
} |
| 506 | 506 |
|
| 507 | 507 |
}; |
| 508 | 508 |
|
| 509 | 509 |
|
| 510 | 510 |
class EdgeIt : public Parent::Edge {
|
| 511 | 511 |
const Graph* _graph; |
| 512 | 512 |
public: |
| 513 | 513 |
|
| 514 | 514 |
EdgeIt() { }
|
| 515 | 515 |
|
| 516 | 516 |
EdgeIt(Invalid i) : Edge(i) { }
|
| 517 | 517 |
|
| 518 | 518 |
explicit EdgeIt(const Graph& graph) : _graph(&graph) {
|
| 519 | 519 |
_graph->first(static_cast<Edge&>(*this)); |
| 520 | 520 |
} |
| 521 | 521 |
|
| 522 | 522 |
EdgeIt(const Graph& graph, const Edge& edge) : |
| 523 | 523 |
Edge(edge), _graph(&graph) { }
|
| 524 | 524 |
|
| 525 | 525 |
EdgeIt& operator++() {
|
| 526 | 526 |
_graph->next(*this); |
| 527 | 527 |
return *this; |
| 528 | 528 |
} |
| 529 | 529 |
|
| 530 | 530 |
}; |
| 531 | 531 |
|
| 532 | 532 |
class IncEdgeIt : public Parent::Edge {
|
| 533 | 533 |
friend class GraphExtender; |
| 534 | 534 |
const Graph* _graph; |
| 535 | 535 |
bool _direction; |
| 536 | 536 |
public: |
| 537 | 537 |
|
| 538 | 538 |
IncEdgeIt() { }
|
| 539 | 539 |
|
| 540 | 540 |
IncEdgeIt(Invalid i) : Edge(i), _direction(false) { }
|
| 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; |
| 644 | 644 |
} |
| 645 | 645 |
}; |
| 646 | 646 |
|
| 647 | 647 |
|
| 648 | 648 |
template <typename _Value> |
| 649 | 649 |
class EdgeMap |
| 650 | 650 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > {
|
| 651 | 651 |
public: |
| 652 | 652 |
typedef GraphExtender Graph; |
| 653 | 653 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent; |
| 654 | 654 |
|
| 655 | 655 |
EdgeMap(const Graph& graph) |
| 656 | 656 |
: Parent(graph) {}
|
| 657 | 657 |
|
| 658 | 658 |
EdgeMap(const Graph& graph, const _Value& value) |
| 659 | 659 |
: Parent(graph, value) {}
|
| 660 | 660 |
|
| 661 | 661 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
| 662 | 662 |
return operator=<EdgeMap>(cmap); |
| 663 | 663 |
} |
| 664 | 664 |
|
| 665 | 665 |
template <typename CMap> |
| 666 | 666 |
EdgeMap& operator=(const CMap& cmap) {
|
| 667 | 667 |
Parent::operator=(cmap); |
| 668 | 668 |
return *this; |
| 669 | 669 |
} |
| 670 | 670 |
|
| 671 | 671 |
}; |
| 672 | 672 |
|
| 673 | 673 |
// Alteration extension |
| 674 | 674 |
|
| 675 | 675 |
Node addNode() {
|
| 676 | 676 |
Node node = Parent::addNode(); |
| 677 | 677 |
notifier(Node()).add(node); |
| 678 | 678 |
return node; |
| 679 | 679 |
} |
| 680 | 680 |
|
| 681 | 681 |
Edge addEdge(const Node& from, const Node& to) {
|
| 682 | 682 |
Edge edge = Parent::addEdge(from, to); |
| 683 | 683 |
notifier(Edge()).add(edge); |
| 684 | 684 |
std::vector<Arc> ev; |
| 685 | 685 |
ev.push_back(Parent::direct(edge, true)); |
| 686 | 686 |
ev.push_back(Parent::direct(edge, false)); |
| 687 | 687 |
notifier(Arc()).add(ev); |
| 688 | 688 |
return edge; |
| 689 | 689 |
} |
| 690 | 690 |
|
| 691 | 691 |
void clear() {
|
| ... | ... |
@@ -374,113 +374,113 @@ |
| 374 | 374 |
void next(Node&) const {}
|
| 375 | 375 |
|
| 376 | 376 |
void first(Arc&) const {}
|
| 377 | 377 |
void next(Arc&) const {}
|
| 378 | 378 |
|
| 379 | 379 |
|
| 380 | 380 |
void firstIn(Arc&, const Node&) const {}
|
| 381 | 381 |
void nextIn(Arc&) const {}
|
| 382 | 382 |
|
| 383 | 383 |
void firstOut(Arc&, const Node&) const {}
|
| 384 | 384 |
void nextOut(Arc&) const {}
|
| 385 | 385 |
|
| 386 | 386 |
// The second parameter is dummy. |
| 387 | 387 |
Node fromId(int, Node) const { return INVALID; }
|
| 388 | 388 |
// The second parameter is dummy. |
| 389 | 389 |
Arc fromId(int, Arc) const { return INVALID; }
|
| 390 | 390 |
|
| 391 | 391 |
// Dummy parameter. |
| 392 | 392 |
int maxId(Node) const { return -1; }
|
| 393 | 393 |
// Dummy parameter. |
| 394 | 394 |
int maxId(Arc) const { return -1; }
|
| 395 | 395 |
|
| 396 | 396 |
/// \brief The base node of the iterator. |
| 397 | 397 |
/// |
| 398 | 398 |
/// Gives back the base node of the iterator. |
| 399 | 399 |
/// It is always the target of the pointed arc. |
| 400 | 400 |
Node baseNode(const InArcIt&) const { return INVALID; }
|
| 401 | 401 |
|
| 402 | 402 |
/// \brief The running node of the iterator. |
| 403 | 403 |
/// |
| 404 | 404 |
/// Gives back the running node of the iterator. |
| 405 | 405 |
/// It is always the source of the pointed arc. |
| 406 | 406 |
Node runningNode(const InArcIt&) const { return INVALID; }
|
| 407 | 407 |
|
| 408 | 408 |
/// \brief The base node of the iterator. |
| 409 | 409 |
/// |
| 410 | 410 |
/// Gives back the base node of the iterator. |
| 411 | 411 |
/// It is always the source of the pointed arc. |
| 412 | 412 |
Node baseNode(const OutArcIt&) const { return INVALID; }
|
| 413 | 413 |
|
| 414 | 414 |
/// \brief The running node of the iterator. |
| 415 | 415 |
/// |
| 416 | 416 |
/// Gives back the running node of the iterator. |
| 417 | 417 |
/// It is always the target of the pointed arc. |
| 418 | 418 |
Node runningNode(const OutArcIt&) const { return INVALID; }
|
| 419 | 419 |
|
| 420 | 420 |
/// \brief The opposite node on the given arc. |
| 421 | 421 |
/// |
| 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 |
| ... | ... |
@@ -638,112 +638,112 @@ |
| 638 | 638 |
/// \pre The argument should be a valid node id in the graph. |
| 639 | 639 |
Node nodeFromId(int) const { return INVALID; }
|
| 640 | 640 |
|
| 641 | 641 |
/// \brief Returns the edge with the given id. |
| 642 | 642 |
/// |
| 643 | 643 |
/// \pre The argument should be a valid edge id in the graph. |
| 644 | 644 |
Edge edgeFromId(int) const { return INVALID; }
|
| 645 | 645 |
|
| 646 | 646 |
/// \brief Returns the arc with the given id. |
| 647 | 647 |
/// |
| 648 | 648 |
/// \pre The argument should be a valid arc id in the graph. |
| 649 | 649 |
Arc arcFromId(int) const { return INVALID; }
|
| 650 | 650 |
|
| 651 | 651 |
/// \brief Returns an upper bound on the node IDs. |
| 652 | 652 |
int maxNodeId() const { return -1; }
|
| 653 | 653 |
|
| 654 | 654 |
/// \brief Returns an upper bound on the edge IDs. |
| 655 | 655 |
int maxEdgeId() const { return -1; }
|
| 656 | 656 |
|
| 657 | 657 |
/// \brief Returns an upper bound on the arc IDs. |
| 658 | 658 |
int maxArcId() const { return -1; }
|
| 659 | 659 |
|
| 660 | 660 |
void first(Node&) const {}
|
| 661 | 661 |
void next(Node&) const {}
|
| 662 | 662 |
|
| 663 | 663 |
void first(Edge&) const {}
|
| 664 | 664 |
void next(Edge&) const {}
|
| 665 | 665 |
|
| 666 | 666 |
void first(Arc&) const {}
|
| 667 | 667 |
void next(Arc&) const {}
|
| 668 | 668 |
|
| 669 | 669 |
void firstOut(Arc&, Node) const {}
|
| 670 | 670 |
void nextOut(Arc&) const {}
|
| 671 | 671 |
|
| 672 | 672 |
void firstIn(Arc&, Node) const {}
|
| 673 | 673 |
void nextIn(Arc&) const {}
|
| 674 | 674 |
|
| 675 | 675 |
void firstInc(Edge &, bool &, const Node &) const {}
|
| 676 | 676 |
void nextInc(Edge &, bool &) const {}
|
| 677 | 677 |
|
| 678 | 678 |
// The second parameter is dummy. |
| 679 | 679 |
Node fromId(int, Node) const { return INVALID; }
|
| 680 | 680 |
// The second parameter is dummy. |
| 681 | 681 |
Edge fromId(int, Edge) const { return INVALID; }
|
| 682 | 682 |
// The second parameter is dummy. |
| 683 | 683 |
Arc fromId(int, Arc) const { return INVALID; }
|
| 684 | 684 |
|
| 685 | 685 |
// Dummy parameter. |
| 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 |
| ... | ... |
@@ -377,194 +377,194 @@ |
| 377 | 377 |
///a later state, in other word you cannot add again the arcs deleted |
| 378 | 378 |
///by restore(). |
| 379 | 379 |
void restore() |
| 380 | 380 |
{
|
| 381 | 381 |
_graph->restoreSnapshot(*this); |
| 382 | 382 |
} |
| 383 | 383 |
}; |
| 384 | 384 |
}; |
| 385 | 385 |
|
| 386 | 386 |
|
| 387 | 387 |
class SmartGraphBase {
|
| 388 | 388 |
|
| 389 | 389 |
protected: |
| 390 | 390 |
|
| 391 | 391 |
struct NodeT {
|
| 392 | 392 |
int first_out; |
| 393 | 393 |
}; |
| 394 | 394 |
|
| 395 | 395 |
struct ArcT {
|
| 396 | 396 |
int target; |
| 397 | 397 |
int next_out; |
| 398 | 398 |
}; |
| 399 | 399 |
|
| 400 | 400 |
std::vector<NodeT> nodes; |
| 401 | 401 |
std::vector<ArcT> arcs; |
| 402 | 402 |
|
| 403 | 403 |
int first_free_arc; |
| 404 | 404 |
|
| 405 | 405 |
public: |
| 406 | 406 |
|
| 407 | 407 |
typedef SmartGraphBase Digraph; |
| 408 | 408 |
|
| 409 | 409 |
class Node; |
| 410 | 410 |
class Arc; |
| 411 | 411 |
class Edge; |
| 412 | 412 |
|
| 413 | 413 |
class Node {
|
| 414 | 414 |
friend class SmartGraphBase; |
| 415 | 415 |
protected: |
| 416 | 416 |
|
| 417 | 417 |
int _id; |
| 418 | 418 |
explicit Node(int id) { _id = id;}
|
| 419 | 419 |
|
| 420 | 420 |
public: |
| 421 | 421 |
Node() {}
|
| 422 | 422 |
Node (Invalid) { _id = -1; }
|
| 423 | 423 |
bool operator==(const Node& node) const {return _id == node._id;}
|
| 424 | 424 |
bool operator!=(const Node& node) const {return _id != node._id;}
|
| 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 |
} |
| 523 | 523 |
|
| 524 | 524 |
void firstInc(Edge &arc, bool& d, const Node& v) const {
|
| 525 | 525 |
int de = nodes[v._id].first_out; |
| 526 | 526 |
if (de != -1) {
|
| 527 | 527 |
arc._id = de / 2; |
| 528 | 528 |
d = ((de & 1) == 1); |
| 529 | 529 |
} else {
|
| 530 | 530 |
arc._id = -1; |
| 531 | 531 |
d = true; |
| 532 | 532 |
} |
| 533 | 533 |
} |
| 534 | 534 |
void nextInc(Edge &arc, bool& d) const {
|
| 535 | 535 |
int de = (arcs[(arc._id * 2) | (d ? 1 : 0)].next_out); |
| 536 | 536 |
if (de != -1) {
|
| 537 | 537 |
arc._id = de / 2; |
| 538 | 538 |
d = ((de & 1) == 1); |
| 539 | 539 |
} else {
|
| 540 | 540 |
arc._id = -1; |
| 541 | 541 |
d = true; |
| 542 | 542 |
} |
| 543 | 543 |
} |
| 544 | 544 |
|
| 545 | 545 |
static int id(Node v) { return v._id; }
|
| 546 | 546 |
static int id(Arc e) { return e._id; }
|
| 547 | 547 |
static int id(Edge e) { return e._id; }
|
| 548 | 548 |
|
| 549 | 549 |
static Node nodeFromId(int id) { return Node(id);}
|
| 550 | 550 |
static Arc arcFromId(int id) { return Arc(id);}
|
| 551 | 551 |
static Edge edgeFromId(int id) { return Edge(id);}
|
| 552 | 552 |
|
| 553 | 553 |
Node addNode() {
|
| 554 | 554 |
int n = nodes.size(); |
| 555 | 555 |
nodes.push_back(NodeT()); |
| 556 | 556 |
nodes[n].first_out = -1; |
| 557 | 557 |
|
| 558 | 558 |
return Node(n); |
| 559 | 559 |
} |
| 560 | 560 |
|
| 561 | 561 |
Edge addArc(Node u, Node v) {
|
| 562 | 562 |
int n = arcs.size(); |
| 563 | 563 |
arcs.push_back(ArcT()); |
| 564 | 564 |
arcs.push_back(ArcT()); |
| 565 | 565 |
|
| 566 | 566 |
arcs[n].target = u._id; |
| 567 | 567 |
arcs[n | 1].target = v._id; |
| 568 | 568 |
|
| 569 | 569 |
arcs[n].next_out = nodes[v._id].first_out; |
| 570 | 570 |
nodes[v._id].first_out = n; |
0 comments (0 inline)