cupid’s arrow
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 PresentationTRANSCRIPT
Cupid’s Arrow
電機一 b99901090 黃翔致電機一 b99901117 吳名弘電機三 b96502031 李宗燁
The Basic Model – a Matrix
1 2 0
2 0 1
0 1 2
preference number
0 > 1 > 2
men to women
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
The Basic Model – a Matrix
1 4 2
4 0 2
1 2 2min = 1 + 0 + 2 = 3
This is the best solution !
sum!!
Notation1. The model absolutely has the solution.2. But the solution may not be unique.
Find The Best Solution
• Standard Answer: C++ naïve method• Solution:– Best Choice Method– Worst Choice Method
• Purpose:– Quick!– Accurate!
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
C++ naïve method
C++ Naïve Solution
1 4 2
4 0 2
1 2 2
C++ Naïve Solution
1 4 2
4 0 2
1 2 2
Answer: 1+0+2=3
C++ Naïve Solution
1 4 2
4 0 2
1 2 2
Answer: 1+0+2=3
C++ Naïve Solution
1 4 2
4 0 2
1 2 2
Answer: 1+2+2=5
C++ Naïve Solution
1 4 2
4 0 2
1 2 2
Answer: 4+4+2=10
C++ Naïve Solution
1 4 2
4 0 2
1 2 2
Answer: 4+2+1=7
C++ Naïve Solution
1 4 2
4 0 2
1 2 2
Answer: 2+4+2=8
C++ Naïve Solution
1 4 2
4 0 2
1 2 2
Answer: 2+0+1=3
C++ Naïve Solution
1 4 2
4 0 2
1 2 2
Best: 3Worst:10
Best Choice Method
• Each round, choose the best choice.
Best Choice Method
1 4 2
4 0 2
1 2 2
Step 1: Find the best choice
Best Choice Method
1 4 2
4 0 2
1 2 2
Step 1: Find the best choice
Best Choice Method
1(min) 4 2
4 0 2
1 2 2
Step 1: Find the best choice
Best Choice Method
1 4 2
4 0 2
1 2 2
Step 1: Find the best choice
Best Choice Method
1 4 2
4 0 2
1 2 2
Step 1: Find the best choice
Best Choice Method
1 4 2
4 0 2
1 2 2
Step 1: Find the best choice
Best Choice Method
1 4 2
4 0 2
1 2 2
Step 1: Find the best choice
Best Choice Method
1 4 2
4 0 2
1 2 2
Step 1: Find the best choice
Best Choice Method
1 4 2
4 0 2
1 2 2
Step 1: Find the best choice
Best Choice Method
1 4 2
4 0 2
1 2 2
Step 1: Find the best choice
Best Choice Method
1 4 2
4 0 2
1 2 2
Again : Find the best choice
Best Choice Method
1 4 2
4 0 2
1 2 2
Best Choice Method
1 4 2
4 0 2
1 2 2
Solution: 1+0+2=3
Improvement of Best Choice Method
1 4 2
4 0 2
1 2 2
Finding best choice is a repeating step
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)
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)
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)
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)
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.
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
Worst Choice Method
4 3 1
3 1 2
2 2 0
Step1 : Find the worst choice
Worst Choice Method
4 3 1
3 1 2
2 2 0
Step 2 : To prevent the worst choice
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
Worst Choice Method
4 3 1
3 1 2
2 2 0
Repeat the step1:Find the worst choice
Worst Choice Method
4 3 1
3 1 2
2 2 0
Repeat the step2:Find the best choice on its row/column
Worst Choice Method
4 3 1
3 1 2
2 2 0
Answer: 1+1+2=4Correct!
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
Comparison
2 3 4 5 6 7 8 90
10
20
30
40
50
60
standard answer
BCM
WCM
Special situation-Judge by face
0 1 2
0 1 2
0 1 2
0 + 0 1 + 0 2 + 0
0 + 1 1 + 1 2+ 1
0 + 2 1 + 2 2 + 2
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
Homosexual
-1 1 2 00 -1 1 20 2 -1 12 0 1 -1
A B C D A B C D
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
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
Boys are more than Girls
0 1 2 3
0 2 3 1
A B C D
ab
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
Boys are more than Girls
1 1 2 3
0 3 4 2
A B C D
ab
min = 1 + 0 =1
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
1002 2 200
501 2 100
0 1 50
a b c
A
B
Cmin = 2 + 100 + 0 =102
DEMO