Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • fallmoha/IA04_TP3
1 result
Show changes
Commits on Source (4)
...@@ -112,7 +112,7 @@ func (rba *RestBallotAgent) doNewBallot(w http.ResponseWriter, r *http.Request) ...@@ -112,7 +112,7 @@ func (rba *RestBallotAgent) doNewBallot(w http.ResponseWriter, r *http.Request)
} }
log.Println("NEW BALLOT: Number of alternatives: ", req.Alts) log.Println("NEW BALLOT: Number of alternatives: ", req.Alts)
if rba.rule != "majority" && rba.rule != "borda" && rba.rule != "copeland" && rba.rule != "condorcet" && rba.rule != "approval" && rba.rule != "scoring" { if rba.rule != "majority" && rba.rule != "borda" && rba.rule != "copeland" && rba.rule != "condorcet" && rba.rule != "approval" && rba.rule != "single transferable vote" && rba.rule != "scoring" {
w.WriteHeader(http.StatusNotImplemented) w.WriteHeader(http.StatusNotImplemented)
msg := fmt.Sprintf("501: vote rule \"'%s'\" is not impemented in the system", req.Rule) msg := fmt.Sprintf("501: vote rule \"'%s'\" is not impemented in the system", req.Rule)
w.Write([]byte(msg)) w.Write([]byte(msg))
...@@ -145,6 +145,10 @@ func (rba *RestBallotAgent) doNewBallot(w http.ResponseWriter, r *http.Request) ...@@ -145,6 +145,10 @@ func (rba *RestBallotAgent) doNewBallot(w http.ResponseWriter, r *http.Request)
bestAlts, err = comsoc.MajoritySCF(rba.pfl) bestAlts, err = comsoc.MajoritySCF(rba.pfl)
case "approval": case "approval":
rba.count, err = comsoc.ApprovalSWF(rba.pfl, rba.options) rba.count, err = comsoc.ApprovalSWF(rba.pfl, rba.options)
bestAlts, err = comsoc.ApprovalSCF(rba.pfl, rba.options)
case "single transferable vote":
rba.count, err = comsoc.SingleTransferableVoteSWF(rba.pfl)
bestAlts, err = comsoc.SingleTransferableVoteSCF(rba.pfl)
case "scoring": case "scoring":
rba.count, err = comsoc.ScoringSWF(rba.pfl, rba.options) rba.count, err = comsoc.ScoringSWF(rba.pfl, rba.options)
bestAlts, err = comsoc.ScoringSCF(rba.pfl, rba.options) bestAlts, err = comsoc.ScoringSCF(rba.pfl, rba.options)
...@@ -154,6 +158,7 @@ func (rba *RestBallotAgent) doNewBallot(w http.ResponseWriter, r *http.Request) ...@@ -154,6 +158,7 @@ func (rba *RestBallotAgent) doNewBallot(w http.ResponseWriter, r *http.Request)
rba.bestAlt, err = tb(bestAlts) rba.bestAlt, err = tb(bestAlts)
if err != nil { if err != nil {
log.Println("Internal server error in results calculation.", err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
msg := fmt.Sprintf("500: internal server error.") msg := fmt.Sprintf("500: internal server error.")
w.Write([]byte(msg)) w.Write([]byte(msg))
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
) )
func shuffle(n int, pref []comsoc.Alternative) []comsoc.Alternative { func shuffle(n int, pref []comsoc.Alternative) []comsoc.Alternative {
rand.Seed(time.Now().UnixNano() % 100) rand.Seed(time.Now().UnixNano())
// source := rand.NewSource(time.Now().UnixNano()) // source := rand.NewSource(time.Now().UnixNano())
// r := rand.New(source // r := rand.New(source
rand.Shuffle(n, func(i, j int) { rand.Shuffle(n, func(i, j int) {
...@@ -38,15 +38,16 @@ func main() { ...@@ -38,15 +38,16 @@ func main() {
choice = -1 choice = -1
ts = -1 ts = -1
for choice < 0 || choice > 4 { for choice < 0 || choice > 6 {
fmt.Println("Choose the voting rule amonst") fmt.Println("Choose the voting rule amonst")
fmt.Println("0: Borda") fmt.Println("0: Borda")
fmt.Println("1: Majority") fmt.Println("1: Majority")
fmt.Println("2: Copeland") fmt.Println("2: Copeland")
fmt.Println("3: Approval") fmt.Println("3: Approval")
fmt.Println("4: Scoring (default vector is <20,21,22,23,...>)") fmt.Println("4: Single Transferable Vote")
fmt.Println("5: Randomly choose between all the latters") fmt.Println("5: Scoring (default vector is <20,21,22,23,...>)")
fmt.Println("6: Randomly choose between all the latters")
fmt.Println("Enter a number: ") fmt.Println("Enter a number: ")
fmt.Scanln(&choice) fmt.Scanln(&choice)
...@@ -62,10 +63,14 @@ func main() { ...@@ -62,10 +63,14 @@ func main() {
fmt.Println("Enter an integer number for the threshold : ") fmt.Println("Enter an integer number for the threshold : ")
fmt.Scanln(&ts) fmt.Scanln(&ts)
case 4: case 4:
rule = "scoring" rule = "single transferable vote"
case 5: case 5:
rules := []string{"borda", "approval", "copeland", "majority", "scoring"} rule = "scoring"
case 6:
rules := []string{"borda", "approval", "copeland", "majority"}
rand.Seed(time.Now().UnixNano())
rule = rules[rand.Intn(4)] rule = rules[rand.Intn(4)]
log.Println("MAIN:", rule, "has been taken randomly as the voting rule.")
default: default:
fmt.Println("Incorrect choice...") fmt.Println("Incorrect choice...")
} }
...@@ -109,7 +114,7 @@ func main() { ...@@ -109,7 +114,7 @@ func main() {
go server.Start() go server.Start()
voterAgents := make([]agt2.RestVoterAgent, 0, m) voterAgents := make([]agt2.RestVoterAgent, 0, m)
for i := 0; i < n; i++ { for i := 0; i < m; i++ {
id := i id := i
ballotID := 1 ballotID := 1
regle := rule regle := rule
......