Skip to content
Snippets Groups Projects
Commit c021ff83 authored by Mohamed Fall's avatar Mohamed Fall
Browse files

changes 16/10

parent 2bb1d49b
No related branches found
No related tags found
No related merge requests found
package agt
import (
"ia04/comsoc"
)
type AgentID int
type Agent struct {
ID AgentID
Name string
Prefs []Alternative
}
type Alternative comsoc.Alternative
type AgentI interface {
Equal(ag AgentI) bool
DeepEqual(ag AgentI) bool
Clone() AgentI
String() string
Prefers(a Alternative, b Alternative)
Start()
}
package agt
package agt
package comsoc
func CopelandSWF(p Profile) (count Count, err error) {
alts := p[0]
for _, alt1 := range alts {
for _, alt2 := range alts {
if alt1 != alt2 {
}
}
}
return
}
//func CopelandSCF(p Profile) (bestAlts []Alternative, err error)
package comsoc
func MajoritySWF(p Profile) (count Count, err error) {
for _, voter := range p {
count[voter[0]] += 1
for _, alts := range p {
count[alts[0]] += 1
} // 0-votes alternatives are not included
return count, nil
}
......
......@@ -45,9 +45,10 @@ func maxCount(count Count) (bestAlts []Alternative) {
// vérifier que tout le monde a les mêmes alternatives, qu'il n'est pas vide
// vérifie le profil donné, par ex. qu'ils sont tous complets et que chaque alternative de alts apparaît exactement une fois par préférences
func checkProfileAlternative(prefs Profile, alts []Alternative) error {
func checkProfile(prefs Profile) error {
norm := len(prefs[0]) // Si un des profiles n'a pas la même taille: erreur
for _, voter := range prefs {
if len(voter) != len(alts) {
if len(voter) != norm {
return errors.New("001: ProfileErrors")
}
check := make(map[Alternative]int)
......@@ -61,4 +62,29 @@ func checkProfileAlternative(prefs Profile, alts []Alternative) error {
return nil
}
func checkProfileAlternative(prefs Profile, alts []Alternative) error {
present := func(alt Alternative, pref []Alternative) bool {
for _, alt2 := range pref {
if alt == alt2 {
return true
}
}
return false
}
err := checkProfile(prefs)
if err != nil {
return err
}
for _, alt := range alts {
for _, pref := range prefs {
if !present(alt, pref) {
return errors.New("001: ProfileErrors")
}
}
}
return nil
}
//jerome.gaigne@hds.utc.fr
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