Hungarian method: Difference between revisions
Line 46: | Line 46: | ||
### Insert <math>w</math> in <math>T</math> and <math>u</math> in <math>S</math>. | ### Insert <math>w</math> in <math>T</math> and <math>u</math> in <math>S</math>. | ||
## Set <math>\delta:=\min\{c(\{u,w\})-x(u)-y(w)|u\in S,w\in V_2\setminus T\}</math>. | ## Set <math>\delta:=\min\{c(\{u,w\})-x(u)-y(w)|u\in S,w\in V_2\setminus T\}</math>. | ||
## For all <math>v\in | ## For all <math>v\in S</math>, decrease <math>x(v)</math> by <math>\delta</math>. | ||
## For all <math>w\in | ## For all <math>w\in T</math>, increase <math>y(v)</math> by <math>\delta</math>. | ||
'''Remark:''' | '''Remark:''' | ||
Line 55: | Line 55: | ||
Note that <math>w</math> is indeed matched because, otherwise, step 2 had found an augmenting path. Hence, step 4.5 is well defined (the only step for which this fact is not obvious). | Note that <math>w</math> is indeed matched because, otherwise, step 2 had found an augmenting path. Hence, step 4.5 is well defined (the only step for which this fact is not obvious). | ||
The first point of the invariant is clear, so consider the second point. | The first point of the invariant is clear, so consider the second point. We have to show that steps 4-6 maintain this point. Let <math>v\in V_1</math> and <math>w\in V_2</math>. If <math>v\in S</math>, <math>x(v)+y(w)</math> increases, so consider the case <math>v\not\in S</math>. If <math>w\not\in T</math>, <math>x(v)+y(w)</math> does not change, so let <math>w\in T</math>. In this case, the specific choice of <math>\delta</math> ensures the second point of the invariant. | ||
In particular, these observations ensure that each edge <math>\{v,w\}</math> that fulfills <math>c(\{v,w\})</math> immediately before the current iteration, also fulfills this equation immediately after the current iteration. The specific choice of <math>\delta</math> implies that at least one more edge will fulfill this equation immediately after the current iteration. | |||
== Correctness == | == Correctness == |
Revision as of 08:46, 23 November 2014
Abstract view
Algorithmic problem: Maximum-weight matching in complete bipartite graphs [math]\displaystyle{ G=(V_1\dot\cup V_2,E) }[/math] with [math]\displaystyle{ |V_1|=|V_2| }[/math].
Type of algorithm: loop.
Auxiliary data:
- A real number [math]\displaystyle{ x(v) }[/math] for each node [math]\displaystyle{ v\in V_1 }[/math].
- A real number [math]\displaystyle{ y(w) }[/math] for each node [math]\displaystyle{ w\in V_2 }[/math].
Invariant:
- [math]\displaystyle{ M }[/math] is a matching in [math]\displaystyle{ G }[/math].
- For each edge [math]\displaystyle{ e=\{v,w\}\in M }[/math], where [math]\displaystyle{ v\in V_1 }[/math] and [math]\displaystyle{ w\in V_2 }[/math], it is [math]\displaystyle{ c(e)\leq x(v)+y(w) }[/math].
Variant: In each iteration, one of the following two changes will occur:
- [math]\displaystyle{ |M| }[/math] increases by one.
- The number of edges [math]\displaystyle{ \{v,w\} }[/math] ([math]\displaystyle{ v\in V_1 }[/math], [math]\displaystyle{ w\in V_2 }[/math]) such that [math]\displaystyle{ c(e)=x(v)+y(w) }[/math], is increased.
Break condition: For each edge [math]\displaystyle{ e=\{v,w\}\in M }[/math], where [math]\displaystyle{ v\in V_1 }[/math] and [math]\displaystyle{ w\in V_2 }[/math], it is [math]\displaystyle{ c(e)=x(v)+y(w) }[/math].
Induction basis
- initialize [math]\displaystyle{ M }[/math] to be a feasible matching, for example, the empty matching.
- Initialize all [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math] values such that the invariant is fulfilled, for example:
- [math]\displaystyle{ x(v):=\max\{c(\{v,w\})|w\in V_2\} }[/math] for all [math]\displaystyle{ v\in V_1 }[/math].
- [math]\displaystyle{ y(w):=0 }[/math] for all [math]\displaystyle{ w\in V_2 }[/math],
Induction step
Notation:
- For a node [math]\displaystyle{ v\in V_1 }[/math]: [math]\displaystyle{ N(v):=\{w\in V_2|c(\{v,w\})=x(v)+y(w)\} }[/math], the "neighbors" of [math]\displaystyle{ v }[/math].
- For a set [math]\displaystyle{ S\subseteq V_1 }[/math]: [math]\displaystyle{ N(S):=\bigcup_{v\in S}N(v) }[/math].
Abstract view:
- Let [math]\displaystyle{ G'=(V,E') }[/math] be the subgraph of [math]\displaystyle{ G }[/math] where [math]\displaystyle{ E' }[/math] comprises all edges [math]\displaystyle{ e=\{v,w\}\in E }[/math] ([math]\displaystyle{ v\in V_1 }[/math], [math]\displaystyle{ w\in V_2 }[/math]) such that [math]\displaystyle{ c(e)=x(v)+y(w) }[/math].
- Try to find an augmenting path in [math]\displaystyle{ G' }[/math] with respect to [math]\displaystyle{ M }[/math].
- If step 2 succeeds, augment [math]\displaystyle{ M }[/math] along this path.
- Otherwise:
- Choose some exposed node [math]\displaystyle{ v\in V_1 }[/math].
- Initialize two sets, [math]\displaystyle{ S:=\{v\} }[/math], [math]\displaystyle{ T:=\emptyset }[/math].
- While [math]\displaystyle{ T\subsetneq N(S) }[/math]:
- Let [math]\displaystyle{ w\in N(s)\setminus T }[/math].
- Let [math]\displaystyle{ \{u,w\} }[/math] be the unique edge incident to [math]\displaystyle{ w }[/math] that is in [math]\displaystyle{ M }[/math].
- Insert [math]\displaystyle{ w }[/math] in [math]\displaystyle{ T }[/math] and [math]\displaystyle{ u }[/math] in [math]\displaystyle{ S }[/math].
- Set [math]\displaystyle{ \delta:=\min\{c(\{u,w\})-x(u)-y(w)|u\in S,w\in V_2\setminus T\} }[/math].
- For all [math]\displaystyle{ v\in S }[/math], decrease [math]\displaystyle{ x(v) }[/math] by [math]\displaystyle{ \delta }[/math].
- For all [math]\displaystyle{ w\in T }[/math], increase [math]\displaystyle{ y(v) }[/math] by [math]\displaystyle{ \delta }[/math].
Remark: Steps 2 and 4 can be folded into one loop, which breaks if [math]\displaystyle{ N(S)=T }[/math] or an exposed node (and thus an augmenting path) is found.
Proof: Note that [math]\displaystyle{ w }[/math] is indeed matched because, otherwise, step 2 had found an augmenting path. Hence, step 4.5 is well defined (the only step for which this fact is not obvious).
The first point of the invariant is clear, so consider the second point. We have to show that steps 4-6 maintain this point. Let [math]\displaystyle{ v\in V_1 }[/math] and [math]\displaystyle{ w\in V_2 }[/math]. If [math]\displaystyle{ v\in S }[/math], [math]\displaystyle{ x(v)+y(w) }[/math] increases, so consider the case [math]\displaystyle{ v\not\in S }[/math]. If [math]\displaystyle{ w\not\in T }[/math], [math]\displaystyle{ x(v)+y(w) }[/math] does not change, so let [math]\displaystyle{ w\in T }[/math]. In this case, the specific choice of [math]\displaystyle{ \delta }[/math] ensures the second point of the invariant.
In particular, these observations ensure that each edge [math]\displaystyle{ \{v,w\} }[/math] that fulfills [math]\displaystyle{ c(\{v,w\}) }[/math] immediately before the current iteration, also fulfills this equation immediately after the current iteration. The specific choice of [math]\displaystyle{ \delta }[/math] implies that at least one more edge will fulfill this equation immediately after the current iteration.
Correctness
Termination of the main loop will follow from the complexity considerations below. Let [math]\displaystyle{ M }[/math] be a perfect matching and [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math] be given such that [math]\displaystyle{ c(e)=x(v)+y(w) }[/math] for all [math]\displaystyle{ e=\{v,w\}\in M }[/math], where [math]\displaystyle{ v\in V_1 }[/math] and [math]\displaystyle{ w\in V_2 }[/math]. Let [math]\displaystyle{ M' }[/math] be another matching. Due to the invariant, it is
- [math]\displaystyle{ c(M)=\sum_{v\in V_1,w\in V_2\atop e=\{v,w\}\in M}c(e)=\sum_{v\in V_1}x(v)+\sum_{w\in V_2}y(w)\geq\sum_{v\in V_1,w\in V_2\atop e=\{v,w\}\in M'}c(e) }[/math].
Therefore, [math]\displaystyle{ M }[/math] is maximal.
Remark: In particular, the following equivalence is proved: A perfect matching [math]\displaystyle{ M }[/math] has maximum weight if, and only if, there are [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math] such that [math]\displaystyle{ c(e)=x(v)+y(w) }[/math] for all [math]\displaystyle{ e=\{v,w\}\in M }[/math].