Skip to content
Snippets Groups Projects
Commit b4b30880 authored by Balthazar Wilson's avatar Balthazar Wilson
Browse files

fix: stv vote

parent c0384fb6
No related branches found
No related tags found
1 merge request!9Copeland and stv
package comsoc
func getRandomKey(count Count) Alternative {
for k := range count {
return k
}
return 0 // should never happen
}
func countContains(count Count, alt Alternative) bool {
for k := range count {
if alt == k {
return true
}
}
return false
}
// renvoie une des pires alternatives pour un décompte donné
func minCount(count Count) (worstAlt Alternative) {
minPoints := count[Alternative(1)]
func minCount(count Count, alts []Alternative) (worstAlt Alternative) {
for _, alt := range alts {
if !countContains(count, alt) {
return alt
}
}
worstAlt = getRandomKey(count)
minPoints := count[worstAlt]
for i, points := range count {
if points < minPoints {
worstAlt = Alternative(i)
worstAlt = i
minPoints = points
}
}
......@@ -22,14 +44,25 @@ func STV_SWF(p Profile) (count Count, err error) {
if err != nil {
return nil, err
}
for round := 0; round < len(alts)-1; round++ {
majorityRes, _ := MajoritySWF(p)
worstAlt := minCount(majorityRes)
count[worstAlt] = round
nbRounds := len(alts)
for round := 0; round < nbRounds; round++ {
majorityRes := make(Count)
for _, pref := range p {
toDelRank := rank(worstAlt, pref)
pref[toDelRank] = pref[len(pref)-1]
majorityRes[pref[0]]++
}
worstAlt := minCount(majorityRes, alts)
count[worstAlt] = round
// On enlève la pire alt des alts
alts[rank(worstAlt, alts)] = alts[len(alts)-1]
alts = alts[:len(alts)-1]
// on enlève la pire alt de chacunes des preferences
for i, pref := range p {
pref[rank(worstAlt, pref)] = pref[len(pref)-1]
pref = pref[:len(pref)-1]
p[i] = pref
}
}
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment