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

fix: vote with options

parent 84ca5451
No related branches found
No related tags found
1 merge request!7Partie serveur
......@@ -12,7 +12,7 @@ import (
type BallotInfo struct {
profile cs.Profile
options []int
options [][]int
votersId []string
nbAlts int
isOpen bool
......@@ -59,7 +59,7 @@ func (rsa *BallotServerAgent) createBallot(w http.ResponseWriter, r *http.Reques
resp.BallotID = fmt.Sprintf("scrutin%d", len(rsa.ballots)+1)
rsa.ballots[resp] = BallotInfo{
profile: make(cs.Profile, 0),
options: make([]int, 0),
options: make([][]int, 0),
votersId: req.VotersID,
nbAlts: req.NbAlts,
isOpen: true,
......@@ -75,8 +75,8 @@ func (rsa *BallotServerAgent) createBallot(w http.ResponseWriter, r *http.Reques
go rsa.handleBallot(resp, cs.MajoritySWF, cs.MajoritySCF, tb, deadline)
case "borda":
go rsa.handleBallot(resp, cs.BordaSWF, cs.BordaSCF, tb, deadline)
//case "approval":
// go rsa.handleBallot(resp, cs.ApprovalSWF, cs.ApprovalSCF, tb, deadline)
case "approval":
go rsa.handleBallotWithSingleOption(resp, cs.ApprovalSWF, cs.ApprovalSCF, tb, deadline)
default:
w.WriteHeader(http.StatusNotImplemented)
msg := fmt.Sprintf("Unkonwn rule '%s'", req.Rule)
......@@ -126,7 +126,7 @@ func (rsa *BallotServerAgent) handleBallot(
fmt.Println(targetBallot)
}
func (rsa *BallotServerAgent) handleBallotWithOptions(
func (rsa *BallotServerAgent) handleBallotWithSingleOption(
ballot rad.Ballot,
swf func(cs.Profile, []int) (cs.Count, error),
scf func(cs.Profile, []int) ([]cs.Alternative, error),
......@@ -147,11 +147,17 @@ func (rsa *BallotServerAgent) handleBallotWithOptions(
return
}
// Only the fist element of the agents' options is filled/matters
singleOptions := make([]int, len(options))
for i, option := range options {
singleOptions[i] = option[0]
}
tb := cs.TieBreakFactory(orderedTBAlts)
ballotSWF := cs.SWFFactoryWithOptions(swf, tb)
ballotSCF := cs.SCFFactoryWithOptions(scf, tb)
ranking, _ := ballotSWF(profile, options)
winner, err := ballotSCF(profile, options)
ranking, _ := ballotSWF(profile, singleOptions)
winner, err := ballotSCF(profile, singleOptions)
if err != nil {
fmt.Println(err)
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