Skip to content
Snippets Groups Projects
Commit 2bb1d49b authored by Antoine Kryus's avatar Antoine Kryus
Browse files

add condorcet

parent ab53dcd5
No related branches found
No related tags found
No related merge requests found
package main
import (
"fmt"
"log"
"math/rand"
"gitlab.utc.fr/lagruesy/ia04/demos/restagentdemo/restclientagent"
"gitlab.utc.fr/lagruesy/ia04/demos/restagentdemo/restserveragent"
"comsoc"
)
func main() {
const n = 100
const url1 = ":8080"
const url2 = "http://localhost:8080"
ops := [...]string{"+", "-", "*"}
clAgts := make([]restclientagent.RestClientAgent, 0, n)
servAgt := restserveragent.NewRestServerAgent(url1)
log.Println("démarrage du serveur...")
go servAgt.Start()
log.Println("démarrage des clients...")
for i := 0; i < n; i++ {
id := fmt.Sprintf("id%02d", i)
op := ops[rand.Intn(3)]
op1 := rand.Intn(100)
op2 := rand.Intn(100)
agt := restclientagent.NewRestClientAgent(id, url2, op, op1, op2)
clAgts = append(clAgts, *agt)
}
for _, agt := range clAgts {
// attention, obligation de passer par cette lambda pour faire capturer la valeur de l'itération par la goroutine
func(agt restclientagent.RestClientAgent) {
go agt.Start()
}(agt)
}
fmt.Scanln()
}
package main
import (
"fmt"
"gitlab.utc.fr/lagruesy/ia04/demos/restagentdemo/restclientagent"
)
func main() {
ag := restclientagent.NewRestClientAgent("id1", "http://localhost:8000", "+", 11, 1)
ag.Start()
fmt.Scanln()
}
package main
import (
"fmt"
ras "gitlab.utc.fr/lagruesy/ia04/demos/restagentdemo/restserveragent"
)
func main() {
server := ras.NewRestServerAgent(":8080")
server.Start()
fmt.Scanln()
}
package comsoc
func CondorcetWinner(p Profile) (bestAlts []Alternative, err error) {
count := Count(make(map[Alternative]int))
for d,_ := range(p[0]){
duel := Count(make(map[Alternative]int)) // un count
alt1 := p[0][d]
alt2 := p[0][d+1]
// pour la combination: ignorer les identités (2 boucles) et ignorer les permutations
for _,voterAlts := range(p){ // Gagant d'un duel
if isPref(alt1, alt2, voterAlts) {
duel[alt1] += 1
} else {
duel[alt2] += 1
}
winner := maxCount(duel)[0] // gagant d'un duel
count[winner] += 1
}
}
return
}
gitlab.utc.fr/lagruesy/ia04 v0.2.0 h1:bdxu+ks5f/+XmJYetden1uaJN4mSk08q0DUgmh/u7yM=
gitlab.utc.fr/lagruesy/ia04 v0.2.0/go.mod h1:C5yrbHcHhTHRq5bnmPafmdWr5SaN5HkiVl2k++pVC80=
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