#include <lemon/pr_bipartite_matching.h>
Public Member Functions | |
PrBipartiteMatching (const Graph &g) | |
Constructor. | |
Execution control | |
void | init () |
Initialize the data structures. | |
void | start () |
Start the main phase of the algorithm. | |
bool | startPerfect () |
Start the algorithm to find a perfect matching. | |
void | run () |
Runs the algorithm. | |
bool | runPerfect () |
Runs the algorithm to find a perfect matching. | |
bool | checkedRunPerfect () |
Runs the algorithm to find a perfect matching. | |
Query Functions | |
template<typename MatchingMap > | |
int | quickMatching (MatchingMap &mm) const |
Set true all matching uedge in the map. | |
template<class MatchingMap > | |
int | matching (MatchingMap &mm) const |
Set true all matching uedge in the map and the others to false. | |
template<class MatchingMap > | |
int | aMatching (MatchingMap &mm) const |
Gives back the matching in an ANodeMap. | |
template<class MatchingMap > | |
int | bMatching (MatchingMap &mm) const |
Gives back the matching in a BNodeMap. | |
bool | matchingEdge (const UEdge &e) const |
Returns true if the given uedge is in the matching. | |
UEdge | matchingEdge (const Node &n) const |
Returns the matching edge from the node. | |
int | matchingSize () const |
template<class BarrierMap > | |
void | aBarrier (BarrierMap &bar) const |
Gives back a barrier on the A-nodes. | |
template<class BarrierMap > | |
void | bBarrier (BarrierMap &bar) const |
Gives back a barrier on the B-nodes. | |
template<class CoverMap > | |
int | coverSet (CoverMap &covering) const |
Returns a minimum covering of the nodes. |
PrBipartiteMatching | ( | const Graph & | g | ) | [inline] |
Constructor
void init | ( | ) | [inline] |
This function constructs a prematching first, which is a regular matching on the A-side of the graph, but on the B-side each node could cover more matching edges. After that, the B-nodes which multiple matched, will be pushed into the lowest level of the Elevator. The remaning B-nodes will be pushed to the consequent levels respect to a Bfs on following graph: the nodes are the B-nodes of the original bipartite graph and two nodes are adjacent if a node can pass over a matching edge to an other node. The source of the Bfs are the lowest level nodes. Last, the reached B-nodes without covered matching edge becomes active.
void start | ( | ) | [inline] |
This algorithm calculates the maximum matching with the push-relabel principle. This function should be called just after the init() function which already set the initial prematching, the level function on the B-nodes and the active, ie. unmatched B-nodes.
The algorithm always takes highest active B-node, and it try to find a B-node which is eligible to pass over one of it's matching edge. This condition holds when the B-node is one level lower, and the opposite node of it's matching edge is adjacent to the highest active node. In this case the current node steals the matching edge and becomes inactive. If there is not eligible node then the highest active node should be lift to the next proper level.
The nodes should not lift higher than the number of the B-nodes, if a node reach this level it remains unmatched. If during the execution one level becomes empty the nodes above it can be deactivated and lift to the highest level.
bool startPerfect | ( | ) | [inline] |
This function is close to identical to the simple start() member function but it calculates just perfect matching. However, the perfect property is only checked on the B-side of the graph
The main difference between the two function is the handling of the empty levels. The simple start() function let the nodes above the empty levels unmatched while this variant if it find an empty level immediately terminates and gives back false return value.
bool runPerfect | ( | ) | [inline] |
Just a shortcut for the next code:
init(); startPerfect();
bool checkedRunPerfect | ( | ) | [inline] |
Just a shortcut for the next code:
init(); startPerfect();
int quickMatching | ( | MatchingMap & | mm | ) | const [inline] |
Set true all matching uedge in the map. It does not change the value mapped to the other uedges.
int matching | ( | MatchingMap & | mm | ) | const [inline] |
Set true all matching uedge in the map and the others to false.
int aMatching | ( | MatchingMap & | mm | ) | const [inline] |
Gives back the matching in an ANodeMap. The parameter should be a write ANodeMap of UEdge values.
int bMatching | ( | MatchingMap & | mm | ) | const [inline] |
Gives back the matching in a BNodeMap. The parameter should be a write BNodeMap of UEdge values.
bool matchingEdge | ( | const UEdge & | e | ) | const [inline] |
It returns true if the given uedge is in the matching.
UEdge matchingEdge | ( | const Node & | n | ) | const [inline] |
Returns the matching edge from the node. If there is not such edge it gives back INVALID
.
int matchingSize | ( | ) | const [inline] |
Gives back the number of the matching edges.
void aBarrier | ( | BarrierMap & | bar | ) | const [inline] |
The barrier is s subset of the nodes on the same side of the graph. If we tried to find a perfect matching and it failed then the barrier size will be greater than its neighbours. If the maximum matching searched then the barrier size minus its neighbours will be exactly the unmatched nodes on the A-side.
bar | A WriteMap on the ANodes with bool value. |
void bBarrier | ( | BarrierMap & | bar | ) | const [inline] |
The barrier is s subset of the nodes on the same side of the graph. If we tried to find a perfect matching and it failed then the barrier size will be greater than its neighbours. If the maximum matching searched then the barrier size minus its neighbours will be exactly the unmatched nodes on the B-side.
bar | A WriteMap on the BNodes with bool value. |
int coverSet | ( | CoverMap & | covering | ) | const [inline] |
The minimum covering set problem is the dual solution of the maximum bipartite matching. It provides a solution for this problem what is proof of the optimality of the matching.
covering | NodeMap of bool values, the nodes of the cover set will set true while the others false. |