Atama ve eşleme (eşleştirme) problemleri (Matching and

Download Report

Transcript Atama ve eşleme (eşleştirme) problemleri (Matching and

Atama ve eşleme (eşleştirme) problemleri (Matching and Assignment problems)

G

 (

V

,

E

) grafı,

V

X

Y

X

Y

  ikikümeli graf (bipartite) olsun. bölümü üzerine bir

A

R

(

A

)

X

 olsun ( 

y

Y

x

A A

: kümesi,   

E

 

Y X

´in bir altkümesi olsun). kümesine,

A

´nın

G

grafındaki görüntüsü diyelim. Sözel olarak:

R

(

A

) 

Y

köşeler kümesidir. ,

A

´nın en az bir köşesine komşu olan

A

´nın eksiği (deficiency)  (

A

) 

A

R

(

A

) Grafın eksiği (deficiency)  (

G

)  max

A

X

 (

A

)

Hall Teoremi

: 

A

 vardır.

X

için

A

R

(

A

) dir  Grafta

tam atama

veya

Hall Teoremi

: vardır. 

A

X

için  (

G

)   0  (

A

)  0 dır  Grafta

tam atama

Hall Teoremi

: Sözel olarak: • Eğer her bir erkek grubu için onların hoşlandıkları kızlar grubu daha genişse, • her bir erkek isteğine göre kız bulabilir

Not

: Teoremin koşuluna (“ 

A

X

için

A

R

(

A

) koşuluna), Hall’un evlenme koşulu denir. ise”

x y z w a b c d e

X

 {

x

,

y

,

z

,

w

}; No

A

X

1. 2. 3. 4. 5. 6. { { { { {

z x

 ,

y w

} } } }

y

}

Y

 {

a

,

b

,

c

,

d

,

e

} dir. {

a

,

c

} {

R

 {

a

}

a

( ,

A c

) } {

b

,

d

,

e

} {

a

,

c

} 7. {

x

,

z

} {

a

,

c

} 8. 9. 10. {

x

,

w

} { {

y y

, ,

z w

} } {

a

,

b

,

d

,

e

} {

a

,

c

} {

a

,

b

,

c

,

d

,

e

} 11. 12. { {

z

,

w

}

x

,

y

,

z

} {

a

,

b

,

c

,

d

,

e

} {

a

,

c

} 13. 14. 15. 16. { {

x

,

y

,

w

} {

x

,

z

,

w

} {

y

,

z

,

w

}

x

,

y

,

z

,

w

} { { { {

a a a a

, , , ,

b b b b

, , , ,

c c c c

, , , ,

d d d d

, , , ,

e e e e

} } } } |

A

| 0 1 1 1 1 2 2 2 2 2 2 3 3 3 3 4 |

R

(

A

) |  (

A

) 

A

R

(

A

) 0 1 2 2 3 2 0 0  1  1  2 0 2 4 2 5 0  2 0  3  3 5 2 5 5 5 5  (

G

) 

1

 2  2  2  1 max

A

X

 (

A

)  1

Teorem

1: Grafta

maksimal atama değeri

=

X

  (

G

) dir.

Teorem

2 (

Tam atama

için

yeterli koşul

): 

k

Z

 

x

X

y

Y

: deg(

x

) 

k

 deg(

y

) ise,

tam atama

vardır. veya min

x

deg(

x

)  max

y

deg(

y

) ise,

tam atama

vardır.

• Sözel olarak: Eğer her bir erkek yeterince istekli ise (

k

´dan fazla kızla ilgileniyorsa) ve • hiç bir kız özel ilgi görmüyorsa (

k

´dan fazla ilgi görmüyorsa), • her bir erkek isteğine göre kız bulabilir.

Ör.

: 50 öğrenciden oluşan bir sınıfta 25 erkek ve 25 kız vardır. Her erkek =5 kızdan hoşlanıyor. Her kız için ondan hoşlanan =5 erkek vardır. Bir okul partisine her erkek hoşlandığı bir kız ile katılabilir mi?

Çözüm

: Bir atama problemidir: Her erkek hoşlandığı bir kızı seçecektir.

k

 5 olmak üzere

Tam atama

için

yeterli koşul

sağlanıyor.

Teorem

2 geçerlidir.  Evet.

Ör.

: 45 öğrenciden oluşan bir sınıfta 20 erkek ve 25 kız vardır. Her erkek =5 kızdan hoşlanıyor. Her kız için ondan hoşlanan =4 erkek vardır. Bir okul partisine her erkek hoşlandığı bir kız ile katılabilir mi?

k

Çözüm

: Bir atama problemidir: Her erkek hoşlandığı bir kızı seçecektir.  4 (veya

k

 5 ) olmak üzere

Tam atama

için

yeterli koşul

sağlanıyor.

Teorem

2 geçerlidir.  Evet.

Ör.

:

c

1

,

c

2

,

c

3 topluluklar,

s

1

,

s

2

,

s

3

,

s

4

,

s

5 öğrenciler. Hangi topluluklara hangi öğrencilerin üye oldukları tabloda verilmiştir

öğrenc i

s

1 toplulu k

c

1

c c

2 3

s

2

s

3

s

4

s

5 √ √ deg(

s

1 ) =2 √ √ √ deg(

s

2 ) =1 deg(

s

3 ) =2 √ √ √ deg(

s

4 ) =1 deg(

s

5 ) =2 deg(

c

1 ) =2 deg(

c

2 ) =3 deg(

c

3 ) =3

Okul yönetimi ile görüşmek için her topluluk bir temsilci seçecektir. Tüm toplulukları farklı öğrencilerle temsil etmek mümkün mü?

Çözüm

: Bir atama problemidir: Her topluluk için bir öğrenci (“öz öğrenci”) atanacaktır. min max deg(

c i

deg(

s j

) )   2 2     min deg(

c i

)  max deg(

s j

)

Teorem

 2

Tam atama

vardır.  Evet. Not:

c

1 

s

3

,

c

2  tam atamalardır.

s

1

,

c

3 

s

2 veya

c

1 

s

4

,

c

2 

s

3

,

c

3 

s

1 birer

Ör.

: Bir iddia oyununda kişilerin tuttukları takımlar tabloda verilmiştir: Takımlar Albert Canada, Slovakia, USA Finland, Bruce Craig Slovakia, Romania Russia, Slovakia Camelia Russia, Romania Oana Yuri Canada, Finland, Russia, Romania, USA Russia, Slovakia, Romania

Her bir kişinin diğerlerinkinden farklı bir takıma oynaması mümkün mü?

Çözüm

:

Not

1: min

x

deg(

x

)  2  4  max

y

deg(

y

)

yanlış

olduğundan

Teorem

2 uygulanamaz.

Unweighted Bipartite Matching

Definitions

Matching Free Vertex

Definitions

• Maximum Matching: matching with the largest number of edges

Definition

• Note that maximum matching is not unique.

Intuition

• Let the top set of vertices be men • Let the bottom set of vertices be women • Suppose each edge represents a pair of man and woman who like each other • Maximum matching number of couples!

tries to maximize the

Applications

• Matching has many applications. • This lecture lets you know how to find maximum matching.

Alternating Path

• Alternating between matching and non-matching edges.

a b c d e f g h i j d-h-e: alternating path a-f-b-h-d-i: alternating path starts and ends with free vertices f-b-h-e: not alternating path e-j: alternating path starts and ends with free vertices

Idea

• “ Flip” augmenting path to get better matching  • Note: After flipping, the number of matched edges will increase by 1!

Idea of Algorithm

• Start with an arbitrary matching • While we still can find an augmenting path – Find the augmenting path P – Flip the edges in P

Breadth-First Search Algorithm for Augmented Path • Use Breadth-First Search: LEVEL(0) = some unmatched vertex r for odd L > 0, LEVEL(L) = {u|{v,u} E – M when v LEVEL(L -1) and when u in no lower level} For even L > 0, LEVEL(L) = {u|{v,u} M • when v LEVEL(L -1) and u in no lower level} Assume G is bipartite graph with matching M.

Labelling Algorithm

• Start with arbitrary matching

Labelling Algorithm

• Pick a free vertex in the bottom

Labelling Algorithm

• Run BFS

Labelling Algorithm

• Alternate unmatched/matched edges

Labelling Algorithm

• Until a augmenting path is found

Augmenting Tree

Flip!

Repeat

• Pick another free vertex in the bottom

• Run BFS

Repeat

• Flip

Repeat

Answer

• Since we cannot find any augmenting path, stop!

Overall algorithm

• Start with an arbitrary matching (e.g., empty matching) • Repeat forever – For all free vertices in the bottom, • do bfs to find augmenting paths – If found, then flip the edges – If fail to find, stop and report the maximum matching.

Time analysis

• We can find at most |V| augmenting paths (why?) • To find an augmenting path, we use bfs! Time required = O( |V| + |E| ) • Total time: O(|V| 2 + |V| |E|)

Improvement

• We can try to find augmenting paths in parallel for all free nodes in every iteration.

• Using such approach, the time complexity is improved to O(|V| 0.5

|E|)

Stable Marriage Problem

Stable Marriage Problem

• Given N men and N women, each person list in order of preference all the people of the opposite sex who would like to marry.

• Problem: – Engage all the women to all the men in such a way as to respect all their preferences as much as possible.

Stable?

• A set of marriages is unstable if – two people who are not married both prefer each other than their spouses • E.g. Suppose we have A1 B3 C2 D4 E5. This is unstable since – A prefer 2 more than 1 – 2 prefer A more than C

A B C D E 1 2 3 4 5 2 5 1 3 4 1 2 3 4 5 2 3 5 4 1 1 3 2 4 5 5 3 2 1 4 E D A E A D C B D B D B B D C B C A C C E A E E A

Naïve solution

• Starting from a feasible solution.

• Check if it is stable.

– If yes, done!

– If not, remove an unstable couple.

• Is this work?

Naïve solution (2)

• Does not work!

• E.g.

– A 1 B3 C 2 D4 E5 – A 2 B 3 C1 D4 E5 – A3 B 2 C 1 D4 E5 – A 3 B 1 C2 D4 E5

A B C D E 2 5 1 3 4 1 2 3 4 5 2 3 5 4 1 1 3 2 4 5 5 3 2 1 4 1 2 3 4 5 E D A E A D C B D B D B B D C B C A C C E A E E A

Solution

1. Let X be the first man.

2. X proposes to the best woman in the remaining on his list. (Initially, the first woman on his list!) 3.

– If α is not engaged Pair up (X, α). Then, set X=next man and goto 1.

4.

– If α prefers X more than her fiancee Y, Pair up (X, α). Then, set X=Y and goto 1.

5. Goto 1

A B C D E 2 5 1 3 4 1 2 3 4 5 2 3 5 4 1 1 3 2 4 5 5 3 2 1 4

Example

1 2 3 4 5 E D A E A D C B D B D B B D C B C A C C E A E E A A B C D E 2 5 1 3 4 1 2 2 3 5 1 3 5 3 2

Time analysis

• If there are N men and N women, – O(N 2 ) time