Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package comsoc
func CopelandSWF(p Profile) (count Count, err error) {
count = make(Count)
alts := make([]Alternative, 0)
for i := 1; i <= len(p[0]); i++ {
alts = append(alts, Alternative(i))
}
err = checkProfileAlternative(p, alts)
if err != nil {
return nil, err
}
for alt1 := 0; alt1 < len(p); alt1++ {
for alt2 := alt1 + 1; alt2 < len(p); alt2++ {
score1, score2 := 0, 0
for _, pref := range p {
if isPref(Alternative(alt1), Alternative(alt2), pref) {
score1++
} else {
score2++
}
}
if score1 > score2 {
count[Alternative(alt1)]++
} else if score2 > score1 {
count[Alternative(alt2)]++
}
}
}
return
}
func CopelandSCF(p Profile) (bestAlts []Alternative, err error) {
count, err := MajoritySWF(p)
if err != nil {
return nil, err
}
return maxCount(count), err
}