Documentation ¶
Index ¶
- Constants
- type Ballot
- type Candidate
- type CandidateResult
- type CandidateStatus
- type CandidateVoteCount
- type CompareMethod
- type ElectionManager
- func (em *ElectionManager) Candidate1HasMostSecondChoices(c1vc, c2vc *CandidateVoteCount, x int) bool
- func (em *ElectionManager) ElectCandidate(candidate *Candidate) error
- func (em *ElectionManager) GetBallotCandidateNrXInRaceOrNone(ballot *Ballot, x int) *Candidate
- func (em *ElectionManager) GetCandidateWithLeastVotesInRace() (*Candidate, error)
- func (em *ElectionManager) GetCandidatesInRace() []*Candidate
- func (em *ElectionManager) GetCandidatesWithMoreThanXVotes(x int) []*Candidate
- func (em *ElectionManager) GetNumberOfCandidatesInRace() int
- func (em *ElectionManager) GetNumberOfElectedCandidates() int
- func (em *ElectionManager) GetNumberOfNonExhaustedBallots() float64
- func (em *ElectionManager) GetNumberOfNonExhaustedVotes() float64
- func (em *ElectionManager) GetNumberOfVotes(candidate *Candidate) (float64, error)
- func (em *ElectionManager) GetResults() *RoundResult
- func (em *ElectionManager) IsValidCandidate(candidate *Candidate) bool
- func (em *ElectionManager) RejectCandidate(candidate *Candidate) error
- func (em *ElectionManager) SortCandidatesInRace()
- func (em *ElectionManager) TransferVotes(candidate *Candidate, numberOfTransferVotes float64) error
- type ElectionManagerOptions
- type ElectionResults
- type RoundResult
- type SingleTransferableVoteOptions
Constants ¶
View Source
const ( Elected = "Elected" Hopeful = "Hopeful" Rejected = "Rejected" )
View Source
const ( CompareMethodMostSecondChoice = "MostSecondChoice" CompareMethodRandom = "Random" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CandidateResult ¶
type CandidateResult struct { Candidate *Candidate NumberOfVotes float64 Status CandidateStatus }
type CandidateStatus ¶
type CandidateStatus string
type CandidateVoteCount ¶
type CandidateVoteCount struct { Candidate *Candidate Status CandidateStatus NumberOfVotes float64 Votes []*Ballot }
func NewCandidateVoteCount ¶
func NewCandidateVoteCount(candidate *Candidate) *CandidateVoteCount
func (*CandidateVoteCount) GetCandidateResult ¶
func (cvc *CandidateVoteCount) GetCandidateResult() *CandidateResult
func (*CandidateVoteCount) IsInRace ¶
func (cvc *CandidateVoteCount) IsInRace() bool
func (*CandidateVoteCount) String ¶
func (cvc *CandidateVoteCount) String() string
type CompareMethod ¶
type CompareMethod string
type ElectionManager ¶
type ElectionManager struct { Candidates []*Candidate Ballots []*Ballot ElectionManagerOptions CandidateVoteCounts map[*Candidate]*CandidateVoteCount CandidatesInRace []*CandidateVoteCount CandidatesElected []*CandidateVoteCount CandidatesRejected []*CandidateVoteCount ExhaustedBallots []*Ballot NumberOfBlankVotes float64 NumberOfCandidates int }
func NewElectionManager ¶
func NewElectionManager(candidates []*Candidate, ballots []*Ballot, options ElectionManagerOptions) *ElectionManager
func (*ElectionManager) Candidate1HasMostSecondChoices ¶
func (em *ElectionManager) Candidate1HasMostSecondChoices(c1vc, c2vc *CandidateVoteCount, x int) bool
func (*ElectionManager) ElectCandidate ¶
func (em *ElectionManager) ElectCandidate(candidate *Candidate) error
func (*ElectionManager) GetBallotCandidateNrXInRaceOrNone ¶
func (em *ElectionManager) GetBallotCandidateNrXInRaceOrNone(ballot *Ballot, x int) *Candidate
func (*ElectionManager) GetCandidateWithLeastVotesInRace ¶
func (em *ElectionManager) GetCandidateWithLeastVotesInRace() (*Candidate, error)
func (*ElectionManager) GetCandidatesInRace ¶
func (em *ElectionManager) GetCandidatesInRace() []*Candidate
func (*ElectionManager) GetCandidatesWithMoreThanXVotes ¶
func (em *ElectionManager) GetCandidatesWithMoreThanXVotes(x int) []*Candidate
func (*ElectionManager) GetNumberOfCandidatesInRace ¶
func (em *ElectionManager) GetNumberOfCandidatesInRace() int
func (*ElectionManager) GetNumberOfElectedCandidates ¶
func (em *ElectionManager) GetNumberOfElectedCandidates() int
func (*ElectionManager) GetNumberOfNonExhaustedBallots ¶
func (em *ElectionManager) GetNumberOfNonExhaustedBallots() float64
func (*ElectionManager) GetNumberOfNonExhaustedVotes ¶
func (em *ElectionManager) GetNumberOfNonExhaustedVotes() float64
func (*ElectionManager) GetNumberOfVotes ¶
func (em *ElectionManager) GetNumberOfVotes(candidate *Candidate) (float64, error)
func (*ElectionManager) GetResults ¶
func (em *ElectionManager) GetResults() *RoundResult
func (*ElectionManager) IsValidCandidate ¶
func (em *ElectionManager) IsValidCandidate(candidate *Candidate) bool
func (*ElectionManager) RejectCandidate ¶
func (em *ElectionManager) RejectCandidate(candidate *Candidate) error
func (*ElectionManager) SortCandidatesInRace ¶
func (em *ElectionManager) SortCandidatesInRace()
func (*ElectionManager) TransferVotes ¶
func (em *ElectionManager) TransferVotes(candidate *Candidate, numberOfTransferVotes float64) error
type ElectionManagerOptions ¶
type ElectionManagerOptions struct { NumberOfVotesPerVoter int CompareMethodIfEqual CompareMethod PickRandomIfBlank bool }
func DefaultElectionManagerOptions ¶
func DefaultElectionManagerOptions() ElectionManagerOptions
type ElectionResults ¶
type ElectionResults struct {
Rounds []*RoundResult
}
func NewElectionResults ¶
func NewElectionResults() *ElectionResults
func SingleTransferableVote ¶
func SingleTransferableVote(candidates []*Candidate, ballots []*Ballot, numberOfSeats int, options SingleTransferableVoteOptions) (*ElectionResults, error)
func (*ElectionResults) GetWinners ¶
func (er *ElectionResults) GetWinners() []*Candidate
func (*ElectionResults) RegisterResults ¶
func (er *ElectionResults) RegisterResults(round *RoundResult)
type RoundResult ¶
type RoundResult struct { CandidateResults []*CandidateResult NumberOfBlankVotes float64 }
func NewRoundResult ¶
func NewRoundResult(candidateResults []*CandidateResult, nbBlankVotes float64) *RoundResult
func (*RoundResult) String ¶
func (rr *RoundResult) String() string
type SingleTransferableVoteOptions ¶
type SingleTransferableVoteOptions struct { CompareMethodIfEquals CompareMethod PickRandomIfBlank bool }
func DefaultSingleTransferableVoteOptions ¶
func DefaultSingleTransferableVoteOptions() SingleTransferableVoteOptions
Click to show internal directories.
Click to hide internal directories.