cupid’s arrow

57
Cupid’s Arrow 電電b99901090 電電電 電電b99901117 電電電 電電電 b96502031 電電電

Upload: chase

Post on 06-Feb-2016

44 views

Category:

Documents


0 download

DESCRIPTION

Cupid’s Arrow. 電機一 b99901090 黃翔致 電機一 b99901117 吳名弘 電機 三 b96502031 李宗燁. men to women. The Basic Model – a Matrix. preference number 0 > 1 > 2. women to men. The Basic Model – a Matrix. sum!!. The Basic Model – a Matrix. min = 1 + 0 + 2 = 3 This is the best solution !. Notation. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Cupid’s Arrow

Cupid’s Arrow

電機一 b99901090 黃翔致電機一 b99901117 吳名弘電機三 b96502031 李宗燁

Page 2: Cupid’s Arrow

The Basic Model – a Matrix

1 2 0

2 0 1

0 1 2

preference number

0 > 1 > 2

men to women

Page 3: Cupid’s Arrow

The Basic Model – a Matrix

1 + 0 2 + 2 0 + 2

2 + 2 0 + 0 1+ 1

0 + 1 1 + 1 2 + 0

women to men

Page 4: Cupid’s Arrow

The Basic Model – a Matrix

1 4 2

4 0 2

1 2 2min = 1 + 0 + 2 = 3

This is the best solution !

sum!!

Page 5: Cupid’s Arrow

Notation1. The model absolutely has the solution.2. But the solution may not be unique.

Page 6: Cupid’s Arrow

Find The Best Solution

• Standard Answer: C++ naïve method• Solution:– Best Choice Method– Worst Choice Method

• Purpose:– Quick!– Accurate!

Page 7: Cupid’s Arrow

1

2

3

1

2

3

1

2

3

1

2

3

1

2

3

1

2

3

C++ naïve method

Page 8: Cupid’s Arrow

C++ Naïve Solution

1 4 2

4 0 2

1 2 2

Page 9: Cupid’s Arrow

C++ Naïve Solution

1 4 2

4 0 2

1 2 2

Answer: 1+0+2=3

Page 10: Cupid’s Arrow

C++ Naïve Solution

1 4 2

4 0 2

1 2 2

Answer: 1+0+2=3

Page 11: Cupid’s Arrow

C++ Naïve Solution

1 4 2

4 0 2

1 2 2

Answer: 1+2+2=5

Page 12: Cupid’s Arrow

C++ Naïve Solution

1 4 2

4 0 2

1 2 2

Answer: 4+4+2=10

Page 13: Cupid’s Arrow

C++ Naïve Solution

1 4 2

4 0 2

1 2 2

Answer: 4+2+1=7

Page 14: Cupid’s Arrow

C++ Naïve Solution

1 4 2

4 0 2

1 2 2

Answer: 2+4+2=8

Page 15: Cupid’s Arrow

C++ Naïve Solution

1 4 2

4 0 2

1 2 2

Answer: 2+0+1=3

Page 16: Cupid’s Arrow

C++ Naïve Solution

1 4 2

4 0 2

1 2 2

Best: 3Worst:10

Page 17: Cupid’s Arrow

Best Choice Method

• Each round, choose the best choice.

Page 18: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Step 1: Find the best choice

Page 19: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Step 1: Find the best choice

Page 20: Cupid’s Arrow

Best Choice Method

1(min) 4 2

4 0 2

1 2 2

Step 1: Find the best choice

Page 21: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Step 1: Find the best choice

Page 22: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Step 1: Find the best choice

Page 23: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Step 1: Find the best choice

Page 24: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Step 1: Find the best choice

Page 25: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Step 1: Find the best choice

Page 26: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Step 1: Find the best choice

Page 27: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Step 1: Find the best choice

Page 28: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Again : Find the best choice

Page 29: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Page 30: Cupid’s Arrow

Best Choice Method

1 4 2

4 0 2

1 2 2

Solution: 1+0+2=3

Page 31: Cupid’s Arrow

Improvement of Best Choice Method

1 4 2

4 0 2

1 2 2

Finding best choice is a repeating step

Page 32: Cupid’s Arrow

Improvement of Best Choice Method

1 (0,0) 4(0,1) 2(0,2)

4(1,0) 0(1,1) 2(1,2)

1(2,0) 2(2,1) 2(2,2)

Page 33: Cupid’s Arrow

Improvement of Best Choice Method

• Using Sorting Algorithm:– 0(1,1)– 1(0,0)– 1(2,0)– 2(0,2)– 2(1,2)– 2(2,1)– 2(2,2)– 4(0,1)– 4(1,0)

Page 34: Cupid’s Arrow

Improvement of Best Choice Method

• Using Sorting Algorithm:– 0(1,1)– 1(0,0)– 1(2,0)– 2(0,2)– 2(1,2)– 2(2,1)– 2(2,2)– 4(0,1)– 4(1,0)

Page 35: Cupid’s Arrow

Improvement of Best Choice Method

• Using Sorting Algorithm:– 0(1,1)– 1(0,0)– 1(2,0)– 2(0,2)– 2(1,2)– 2(2,1)– 2(2,2)– 4(0,1)– 4(1,0)

Page 36: Cupid’s Arrow

Improvement of Best Choice Method

• Using Sorting Algorithm:– 0(1,1)– 1(0,0)– 1(2,0)– 2(0,2)– 2(1,2)– 2(2,1)– 2(2,2)– 4(0,1)– 4(1,0) It doesn’t do the same step.

Page 37: Cupid’s Arrow

Worst Choice Method

• The Defect of Best Choice Method is that it may choose a worst choice accidently.

4 3 1

3 1 22 2 0

Page 38: Cupid’s Arrow

Worst Choice Method

4 3 1

3 1 2

2 2 0

Step1 : Find the worst choice

Page 39: Cupid’s Arrow

Worst Choice Method

4 3 1

3 1 2

2 2 0

Step 2 : To prevent the worst choice

Page 40: Cupid’s Arrow

Worst Choice Method

4 3 1

3 1 2

2 2 0

Step 2 : To prevent the worst choice,find the best choice on its row/column

Page 41: Cupid’s Arrow

Worst Choice Method

4 3 1

3 1 2

2 2 0

Repeat the step1:Find the worst choice

Page 42: Cupid’s Arrow

Worst Choice Method

4 3 1

3 1 2

2 2 0

Repeat the step2:Find the best choice on its row/column

Page 43: Cupid’s Arrow

Worst Choice Method

4 3 1

3 1 2

2 2 0

Answer: 1+1+2=4Correct!

Page 44: Cupid’s Arrow

ComparisonNaïve Method Best CM Worst CM

Time Complexity

O(n!) Unimproved: O(n3)Improved: O(n2 log n)

O(n3)

Average of answer (3vs3)

3.26389 3.4841 3.55635

Average of answer (4vs4)(100000)

7.75434 8.36789 8.94615

Page 45: Cupid’s Arrow

Comparison

2 3 4 5 6 7 8 90

10

20

30

40

50

60

standard answer

BCM

WCM

Page 46: Cupid’s Arrow

Special situation-Judge by face

0 1 2

0 1 2

0 1 2

Page 47: Cupid’s Arrow

0 + 0 1 + 0 2 + 0

0 + 1 1 + 1 2+ 1

0 + 2 1 + 2 2 + 2

Page 48: Cupid’s Arrow

0 1 2

1 2 3

2 3 4

0 1 2

1 2 3

2 3 4

0 1 2

1 2 3

2 3 4

0 1 2

1 2 3

2 3 4

0 1 2

1 2 3

2 3 4

0 1 2

1 2 3

2 3 4

Answer=6 Answer=6 Answer=6

Answer=6 Answer=6 Answer=6

Page 49: Cupid’s Arrow

Homosexual

-1 1 2 00 -1 1 20 2 -1 12 0 1 -1

A B C D A B C D

Page 50: Cupid’s Arrow

Homosexual

-1 1+0 2+0 0+20+1 -1 1+2 2+00+2 2+1 -1 1+12+0 0+2 1+1 -1

A B C D A B C D

Page 51: Cupid’s Arrow

Homosexual

-1 1 2 21 -1 3 22 3 -1 22 2 2 -1

A B C D A B C D

min = 1 + 2 =3

Page 52: Cupid’s Arrow

Boys are more than Girls

0 1 2 3

0 2 3 1

A B C D

ab

Page 53: Cupid’s Arrow

Boys are more than Girls

0+1 1+0 2+0 3+0

0+0 2+1 3+1 1+1

A B C D

ab

Page 54: Cupid’s Arrow

Boys are more than Girls

1 1 2 3

0 3 4 2

A B C D

ab

min = 1 + 0 =1

Page 55: Cupid’s Arrow

Couple Index• You really don’t want to be with the girl or the boy.

→You need a preference number bigger than 0, 1 ,2

Page 56: Cupid’s Arrow

1002 2 200

501 2 100

0 1 50

a b c

A

B

Cmin = 2 + 100 + 0 =102

Page 57: Cupid’s Arrow

DEMO