diff --git a/agt/ballotagent/new_ballot.go b/agt/ballotagent/new_ballot.go index 7cd1756b66677f417bb03430af44be9e3c52449e..c2325d6da888b0c225abe86d56811a143b38101e 100644 --- a/agt/ballotagent/new_ballot.go +++ b/agt/ballotagent/new_ballot.go @@ -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