|
|
Corresponding max flow problem:
|
|
But... there is a much easier algorithm :-)
|
| Alternating path 1 | Alternating path 2 | ||
|---|---|---|---|
|
|
Note:
|
|
How to increase the matching:
|
| Alternating path | Improved matching |
|---|---|
|
|
| Alternating path | Improved matching |
|---|---|
|
|
Given: Bi-partite graph (X,Y)
A matching M in (X,Y)
for ( each x ∈ X and x is not matched )
{
label x by *; // x is current candidate
repeat
{
1. Apply the odd-edge label algorithm:
for ( each y ∈ Y and y is not labeled )
if ( some adjacent node xk of y has a label )
label y with xk;
2. Apply the even-edge label algorithm:
for ( each x ∈ X and x is not labeled )
if ( some adjacent node yk of x has a label )
label x with yk;
} until no more nodes can be labeled
/* ======================================
"Breakthrough" test
====================================== */
if ( a node yk ∈ Y is labeled and y ∉ M )
{
there is an alternating path from x to yk
}
else
{
try next node x (if there are more candidates left)
}
}
|
|
Note:
|
|
|
|
| Odd-edge: use edges ∉ matching | Even-edge: use edges ∈ matching |
|
|
| Breakthrough test | Alternating path |
|
|
Improved matching:
|
| Odd-edge: use edges ∉ matching | Even-edge: use edges ∈ matching |
|
|
| Breakthrough test | Alternating path |
|
|
Improved matching:
|
| Odd-edge: use edges ∉ matching | Even-edge: use edges ∈ matching | Odd-edge: use edges ∉ matching | Even-edge: use edges ∈ matching |
|
|
|
|
|
Ends without a breakthrough
|
|
Answer to the $64,000 question:
|