Changeset 2463:19651a04d056 in lemon-0.x for lemon/pr_bipartite_matching.h
- Timestamp:
- 08/21/07 15:22:21 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@3301
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/pr_bipartite_matching.h
r2462 r2463 316 316 ///@{ 317 317 318 /// \briefSet true all matching uedge in the map.319 /// 320 /// 321 /// 322 /// 318 ///Set true all matching uedge in the map. 319 320 ///Set true all matching uedge in the map. It does not change the 321 ///value mapped to the other uedges. 322 ///\return The number of the matching edges. 323 323 template <typename MatchingMap> 324 324 int quickMatching(MatchingMap& mm) const { … … 329 329 } 330 330 331 /// \briefSet true all matching uedge in the map and the others to false.331 ///Set true all matching uedge in the map and the others to false. 332 332 333 333 ///Set true all matching uedge in the map and the others to false. … … 337 337 for (UEdgeIt e(_g);e!=INVALID;++e) { 338 338 mm.set(e,e==_matching[_g.aNode(e)]); 339 } 340 return _matching_size; 341 } 342 343 ///Gives back the matching in an ANodeMap. 344 345 ///Gives back the matching in an ANodeMap. The parameter should 346 ///be a write ANodeMap of UEdge values. 347 ///\return The number of the matching edges. 348 template<class MatchingMap> 349 int aMatching(MatchingMap& mm) const { 350 for (ANodeIt n(_g);n!=INVALID;++n) { 351 mm.set(n,_matching[n]); 352 } 353 return _matching_size; 354 } 355 356 ///Gives back the matching in a BNodeMap. 357 358 ///Gives back the matching in a BNodeMap. The parameter should 359 ///be a write BNodeMap of UEdge values. 360 ///\return The number of the matching edges. 361 template<class MatchingMap> 362 int bMatching(MatchingMap& mm) const { 363 for (BNodeIt n(_g);n!=INVALID;++n) { 364 mm.set(n,INVALID); 365 } 366 for (ANodeIt n(_g);n!=INVALID;++n) { 367 if (_matching[n]!=INVALID) 368 mm.set(_g.bNode(_matching[n]),_matching[n]); 339 369 } 340 370 return _matching_size; … … 458 488 ///in a bipartite graph \c g. 459 489 ///\param g An undirected bipartite graph. 460 ///\retval matching A write UEdgeMap of value type \c bool. 461 /// The found edges will be returned in this map. 490 ///\retval matching A write ANodeMap of value type \c UEdge. 491 /// The found edges will be returned in this map, 492 /// i.e. for an \c ANode \c n the edge <tt>matching[n]</tt> is the one 493 /// that covers the node \c n. 462 494 ///\return The cardinality of the maximum matching. 463 495 /// … … 469 501 PrBipartiteMatching<Graph> bpm(g); 470 502 bpm.run(); 471 bpm. matching(matching);503 bpm.aMatching(matching); 472 504 return bpm.matchingSize(); 473 505 } … … 479 511 ///in a bipartite graph \c g. 480 512 ///\param g An undirected bipartite graph. 481 ///\retval matching A write UEdgeMap of value type \c bool. 482 /// The found edges will be returned in this map. 513 ///\retval matching A write ANodeMap of value type \c UEdge. 514 /// The found edges will be returned in this map, 515 /// i.e. for an \c ANode \c n the edge <tt>matching[n]</tt> is the one 516 /// that covers the node \c n. 483 517 ///\retval barrier A \c bool WriteMap on the BNodes. The map will be set 484 518 /// exactly once for each BNode. The nodes with \c true value represent … … 495 529 PrBipartiteMatching<Graph> bpm(g); 496 530 bpm.run(); 497 bpm. matching(matching);531 bpm.aMatching(matching); 498 532 bpm.bBarrier(barrier); 499 533 return bpm.matchingSize(); … … 522 556 ///This function finds a perfect matching in a bipartite graph \c g. 523 557 ///\param g An undirected bipartite graph. 524 ///\retval matching A write UEdgeMap of value type \c bool. 525 /// The found edges will be returned in this map. 558 ///\retval matching A write ANodeMap of value type \c UEdge. 559 /// The found edges will be returned in this map, 560 /// i.e. for an \c ANode \c n the edge <tt>matching[n]</tt> is the one 561 /// that covers the node \c n. 526 562 /// The values are unchanged if the graph 527 563 /// has no perfect matching. … … 534 570 { 535 571 PrBipartiteMatching<Graph> bpm(g); 536 bool ret = bpm. runPerfect();537 if (ret) bpm. matching(matching);572 bool ret = bpm.checkedRunPerfect(); 573 if (ret) bpm.aMatching(matching); 538 574 return ret; 539 575 } … … 544 580 ///This function finds a perfect matching in a bipartite graph \c g. 545 581 ///\param g An undirected bipartite graph. 546 ///\retval matching A readwrite UEdgeMap of value type \c bool. 547 /// The found edges will be returned in this map. 582 ///\retval matching A write ANodeMap of value type \c UEdge. 583 /// The found edges will be returned in this map, 584 /// i.e. for an \c ANode \c n the edge <tt>matching[n]</tt> is the one 585 /// that covers the node \c n. 548 586 /// The values are unchanged if the graph 549 587 /// has no perfect matching. … … 558 596 ///on the push-relabel principle. 559 597 template<class Graph,class MT, class GT> 560 intprPerfectBipartiteMatching(const Graph &g,MT &matching,GT &barrier)598 bool prPerfectBipartiteMatching(const Graph &g,MT &matching,GT &barrier) 561 599 { 562 600 PrBipartiteMatching<Graph> bpm(g); 563 bool ret=bpm. runPerfect();601 bool ret=bpm.checkedRunPerfect(); 564 602 if(ret) 565 bpm. matching(matching);603 bpm.aMatching(matching); 566 604 else 567 605 bpm.bBarrier(barrier);
Note: See TracChangeset
for help on using the changeset viewer.