4.2 Bounded Perfet Mathing of a Complete Bipartite Graph
4.2.2 Algorithms, Data Strutures and Automati Program
Thesets
V
1
andV
2
are implementedaslistsofnaturalswithoutdupliations. WeindiatethelengthofthelistV
by|V|
. Weindiatebytail(V)
theoperation thatreturnthetailofthenonemptylistV
.ThesetE
ofweightsisimplemented by alist oftriple ofnaturals(i, j, v
i,j)
,withi∈V
1
,j∈V
2
andv
i,j
weight of theedge(i, j)
. Giveni∈V
1
,j∈V
2
,theweightofthear(i, j)
isindiatedbyE[i, j]
.AperfetmathingM
ofV
1
andV
2
isimplementedbyalistofnaturalsM
withthe following twoproperties:i)
for allj
,ifM[j] =k
then(V
1
[j], k)
, withV
2
[m] =
k
for somem
, belong to the perfet mathing andii)
for allj6=k
,M[j]6=M[k]
. Byi)
andii)
it followsthatM
isa permutationofV
2
. Undertheseassumptions thefuntionSUM:N→N→(N×N×N)
→N
(thattakesin inputthe vetor ofnodesV
1
, the mathingvetorM
, the the matrixofweightsE
andreturnstheweight ofM
)isdenedas follow:SUM
([],[], E) = 0
SUM
(v::V
1
, m::M, E) =E[v, m] +
SUM(V
1
, M, E)
Givenaompleteweightedbipartitegraph
G= (V
1
, V
2
, E)
,with|V
1
|=|V
2
|
,M
isaompletemathingofG
ifandonlyifMATCH(M, V
2
)
,withtheprediate MATCHdenedasfollow:rri
(M1)
MATCH((:),(:))
MATCH(M, V2\{n})
(M2)
V2[n] =m
MATCH(m::M, V2)
Proposition 4.2.1.∀l.
MATCH(l, l)
Proof. Casel= (:)
,by(M1)
. Casel= (a::l
′
)
,WehavetoproveMATCH
(l
′
, l
′
)
thatfollowbytheindutionhypothesis.
Now we supply a onstrutive proof of the existene (ornot) of aperfet
mathing(with weight higheror equalthana xedthreshold)of aomplete
bipartite graph. The used strategyis to enumerate all the possibilities, till
thedesiredsolutionisfound. Obviouslythissearhing methodis partiularly
ineient, anditrequireanexponentialnumberofstepswhenexeutedona
speiinputgraph.
Intherestofthehapterwewillusethefollowingonventions:
V
1
, V
2
, E, T
−→M
forM
isaperfetmathingbetweenV
1
andV
2
suhthatT≤
SUM(V
1
, M, E)
,thatisMATCH(M, V
2
)∧T
≤
SUM(M, V
1
, E)
V
1
, V
2
, E, T
−→
n
M
forV
1
6= (:)
,V
1
, V
2
, E, T
−→M
and|V
2
|−n≤♮(M[0], V
2
)
andwewroteV\{m}
toindiatethelistV
fromwhihisdroppedthenodein positionm
,withm: 0, . . . ,|V| −1
and♮(n, V
2
) =m
forV
2
[m] =n
.Theorem 4.2.2.
∀V
1
V
2
E, T.
(|V
1
|=|V
2
| ∧0≤T)→ ∃p.
p→(∃M.V
1
, V
2
, E, T
−→M)∧
(p→ ⊥)→(∃M.V
1
, V
2
, E, T
−→M)→ ⊥
Proof. By indution on
V
1
. CaseV
1
= (:)
: AssumeV
2
,E
,T
and ip:(|(:)|
=
|V
2
|)∧0≤T)
. ByipitfollowsV
2
= (:)
. Theurrentthesisbeame:∃p.
p→(∃M.(:),(:), E, T
−→M)∧
(p→ ⊥)→(∃M.(:),(:), E, T
−→M)→ ⊥
(4.1) Twoasesare possible: Case0< T
: thennoperfet mathingdoesexist. So weintrodue forp
. Thepositivepart of(4.1)is provedby(Efq). Toprove the negative part of (4.1) let's assume⊤
and ip:∃M.(:),(:), E, T
−→
M
. By ipdoes existsM
suhthat MATCH(M ,(:))
andT
≤
SUM(M ,(:), E)
. Butif MATCH(M ,(:))
by(M1)
we haveM
= (:)
, and so SUM((:),(:), E) = 0
that generate aontradition with thehypothesis0
< T
≤
SUM((:),(:), E)
. Case0 =T
: Introduettforp
. Thepositive partof(4.1)is provedintroduing(:)
forM
,and thenegativepart of(4.1) is provedby(Efq). CaseV
1
= (a::l)
: Assume∀V
2
E, T.
(|l|=|V
2
| ∧0≤T)→ ∃p.
p→(∃M.l, V
2
, E, T
−→M)∧
(p→ ⊥)→(∃M.l, V
2
, E, T
−→M)→ ⊥
(4.2)
V
2
,E
,T
andip:(|(a::l)|=|V
2
| ∧0≤T)
. Giventhenaturala
,weprove∃p.
p→(∃M.(a::l), V
2
, E, T
−→M)∧
(p→ ⊥)→(∃M.(a::l), V
2
, E, T
−→M)→ ⊥
(4.3)
Inordertoprove(4.3)weprovethefollowingassertion:
∀n.∃p.
p→(∃M.(a::l), V
2
, E, T
−→
n
M)∧
(p→ ⊥)→(∃M.(a::l), V
2
, E, T
−→
n
M)→ ⊥
(4.4)
Obviously(4.3) isobtainedinstantiating(4.4)on
|V
2
|
. Toprove(4.4)wepro- eed by indutiononn
. Casen
= 0
: Weshall look for a mathingM
suh that♮(M[0], V
2
)≥ |V
2
|
,butfromthisfollowaontradition. Sowe introdue forp
. Thepositivepart of(4.4) isprovedby (Efq). For thenegativepart, assume⊤
, and ip′
:∃M.(a
::l), V
2
, E, T
−→
|V
2|
M
. Fromip′
it follows thatthereexists
M
suhthat(a::l), V
2
, E, T
−→M
and|V
2
| ≤♮(M[0], V
2
)
. Butontradition. Nowlet'sassumethenestedindutivehypothesis
∃p.
p→(∃M.(a::l), V
2
, E, T
−→
n
M)∧
(p→ ⊥)→(∃M.(a::l), V
2
, E, T
−→
n
M)→ ⊥
(4.5)
anatural
n
,andweprove∃p.
p→(∃M.(a::l), V
2
, E, T
−→
n+1
M)∧
(p→ ⊥)→(∃M.(a::l), V
2
, E, T
−→
n+1
M)→ ⊥
(4.6)
Therearetwoases,Case
E[a, V
2
[|V
2
| −(n+ 1)]]< T
: Weinstantiate(4.2)onV
2
\{|V
2
| −(n+ 1)}
,E
and(T
−E[a, V
2
[|V
2
| −(n+ 1)]])
. Thisinstantiation produethefollowing hypothesis:(|l|=|V
2
\{|V
2
| −(n+ 1)}| ∧0≤(T−E[a, V
2
[|V
2
| −(n+ 1)]]))→ ∃p.
p→(∃M.l, V
2
\{|V
2
| −(n+ 1)}, E,(T−E[a, V
2
[|V
2
| −(n+ 1)]])−→M)∧
(p→ ⊥)→
(∃M.l, V
2
\{|V
2
| −(n+ 1)}, E,(T−E[a, V
2
[|V
2
| −(n+ 1)]])−→M)→ ⊥
(4.7)
Byip,
|(a::l)|=|V
2
|
thus|l|=|V
2
\{|V
2
| −(n+ 1)}|
,moreoverbyE[a, V
2
[|V
2
| −
(n+ 1)]]< T
it follows that0≤(T
−E[a, V
2
[|V
2
| −(n+ 1)]])
. Instantiating (4.7)onthesetwofats,weknowabooleanp
suhthatp→(∃M.l, V
2
\{|V
2
| −(n+ 1)}, E,(T−E[a, V
2
[|V
2
| −(n+ 1)]])−→M)∧
(p→ ⊥)→
(∃M.l, V
2
\{|V
2
| −(n+ 1)}, E,(T
−E[a, V
2
[|V
2
| −(n+ 1)]])−→M)→ ⊥
(4.8)
Twoasesarepossible,Case
p
: Weintroduettforp
inthegoalformula(4.6) obtainingthenewgoal:(
tt→ ∃M.(a::l), V
2
, E, T
−→
n+1
M)∧
⊥ →((∃M.(a::l), V
2
, E, T
−→
n+1
M)→ ⊥)
(4.9)
Toprovethepositivepartof(4.9): assumettand instantiatetheleftof(4.8) on
p
,fromwhihitfollowthatthereexistsM
suhthat:l, V
2
\{|V
2
| −(n+ 1)}, E,(T−E[a, V
2
[|V
2
| −(n+ 1)]])−→M
(4.10) Soweintrodue(V
2
[|V
2
| −(n+ 1)] ::M)
forM
. Wehavetoprove:•
MATCH((V
2
[|V
2
| −(n+ 1)] ::M), V
2
)
: by(M2)
thisorrespondtoprove MATCH(M , V
2
\{|V
2
| −(n+ 1)})
,thatholdby(4.10).•
T
≤
SUM(a::l,(V
2
[|V
2
| −(n+ 1)] ::M), E)
: Thisorrespondto proveT−E[a, V
2
[|V
2
| −(n+ 1)]]≤
SUM(l, M , E)
,thatfollowby(4.10).(n+ 1)] ::M)[0] =V
2
[|V
2
| −(n+ 1)]
andthen♮(V
2
, V
2
[|V
2
| −(n+ 1)]) =
|V
2
| −(n+ 1)
.Toprovethenegativepartof(4.9): by(Efq). Case
p→ ⊥
:by(4.5)thereexistsp
suhthat:p→(∃M.(a::l), V
2
, E, T
−→
n
M)∧
(p→ ⊥)→(∃M.(a::l), V
2
, E, T
−→
n
M)→ ⊥
(4.11)
Weintrodue
p
forp
in(4.6)obtainingthenewgoal:p→(∃M.(a::l), V
2
, E, T
−→
n+1
M)∧
(p→ ⊥)→(∃M.(a::l), V
2
, E, T
−→
n+1
M)→ ⊥
.
(4.12)
Toprovethepositivepartof(4.12): assume
p
andinstantiatethepositivepart of(4.11)onp
. ItfollowsthatthereexistsM
perfetmathingbetween(a::l)
andV
2
suhthat|V
2
| −n≤♮(M[0], V
2
)
,andthus,|V
2
| −(n+ 1)≤♮(M[0], V
2
)
. Toprovethenegativepartof(4.12): Assumep→ ⊥
. Now,onsideringthat:•
Instantiatingthenegative partof(4.8)on(p→ ⊥)
therenotexists anyM
suhthatl, V
2
\{|V
2
| −(n+ 1)}, E,(T−E[a, V
2
[|V
2
| −(n+ 1)]])−→M
. Thus,foreahmathingM
,namingδ
M
=
SUM(l, M, E)
,wehaveδ
M
<
T−E[a, V
2
[|V
2
| −(n+ 1)]]
andthusδ
M
+E[a, V
2
[|V
2
| −(n+ 1)]]< T
, i.e. thereexistsnomathingM
between(a::l)
andV
2
suhthatM[0] =
V
2
[|V
2
| −(n+ 1)]
.•
Instantiatingthenegativepart of(4.11) onp→ ⊥
therenotexists anyM
suhthat:(a::l), V
2
, E, T
−→
n
M
weonludethatthereexistsnomathing
M
suhthat:(a::l), V
2
, E, T
−→
n+1
M
. CaseE[a, V
2
[|V
2
| −(n+ 1)]]≥T
:Thevalueofthemathingbuiltsofaris higherthanT
,soweanstopthesearh. Instantiate(4.2)onV
2
\{|V
2
|−(n+1)}
,E
and0
. Thusthereexistsp
suhthatp→(∃M.l, V
2
\{|V
2
| −(n+ 1)}, E,0−→M)∧
(p→ ⊥)→(∃M.l, V
2
\{|V
2
| −(n+ 1)}, E,0−→M)→ ⊥
(4.13)
Eahmathingbetweentwosethasavaluegreaterorequalthanzero(exept
the ase inwhihwe onsider ars with negative weight). Thus
p
has tobe true. Westatethisfatassertingthevalidityofp
. Sowehavetwonewgoals:p
andp→
(4.6). Toprovep
: weassertthat theexisteneamathingbetweenl
andV
2
\{|V
2
| −(n+ 1)}
withavaluehigherorequalthan0
. Wereatetwo newsubgoals:(∃M.l, V
2
\{|V
2
| −(n+ 1)}, E,0−→M)→p.
(4.15) Toprove(4.14): by denitionthe returningmathing,ifit exists, is alist of naturals, permutationofV
2
\{|V
2
| −(n+ 1)}
. Sowe anreturnthe identity permutation,thatisweintrodueV
2
\{|V
2
| −(n+ 1)}
forM
. Wehavetoprove:•
MATCH(V
2
\{|V
2
| −(n+ 1)}, V
2
\{|V
2
| −(n+ 1)})
: ByProp. 4.2.1.•
0≤
SUM(l, V
2
\{|V
2
| −(n+ 1)}, E)
: Bydenitionof SUM. To prove (4.15): Assume ip′
:
∃M.l, V
2
\{|V
2
| −(n+ 1)}, E,0
−→
M
. The hypothesis(4.13) is aonjuntion, so both thebranheshaveto be true. In partiular, by ip,(∃M.l, V
2
\{|V
2
| −(n+ 1)}, E,0
−→M)
→ ⊥
is false, thusp→ ⊥
hastobefalseandp
true. Toprovep→
(4.6). Assumep
. Weintrodue ttforp
in(4.6)obtainingtt
→(∃M.(a::l), V
2
, E, T
−→
n+1
M)∧
⊥ →(∃M.(a::l), V
2
, E, T
−→
n+1
M)→ ⊥
(4.16)
Toprovethepositivepart of(4.16): assume tt. Instantiatetheleft of (4.13) on
p
,soweknowM
suhthat:l, V
2
\{|V
2
| −(n+ 1)}, E,0−→M
(4.17) Weintrodue(V
2
[|V
2
| −(n+ 1)] ::M)
forM
. Wehavetoprove:•
MATCH(V
2
[|V
2
| −(n+ 1)] ::
M , V
2
)
: By(M2)
it orresponds to prove MATCH(M , V
2
\{|V
2
| −(n+ 1)})
thatfollowby(4.17).•
T
≤
SUM((a::
l), V
2
[|V
2
| −(n+ 1)] ::
M , E)
: It is equivalent to proveT
≤
E[a, V
2
[|V
2
| −(n+ 1)]] +
SUM(l, M , E)
. This fat follows from SUM(l, M , E)≥0
,by(4.17), andby thehypothesisE[a, V
2
[|V
2
| −(n+
1)]]≥T
.• |V
2
| −(n+ 1)≤♮((V
2
[|V
2
| −(n+ 1)] ::
M)[0], V
2
)
: alreadyprovedas a validinequality.Toprovethenegativepartof(4.16): by(Efq).
TheomputationalontentoftheTheorem4.2.2isshowedinTable4.1(the algorithmiswrittenbymetarules)