copeland

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 4 Imported by: 0

README

copeland

Copeland's preferential voting method implementation. Outputs Copeland's score and ranking for each candidate.

Usage

Create ballot files

Just create plain text files with list of preferences for each voter. One candidate name per line.

Example:

a1.txt

Bob
Charlie
Alice
Donald

a2.txt

Donald
Alice
Charlie
Bob

a3.txt

Alice
Charlie
Bob
Donald
Run the program
copeland a1.txt a2.txt a3.txt

Example output:

Registered names:
	ALICE
	BOB
	CHARLIE
	DONALD

Scores:
	Rank 1:
		3	ALICE
	Rank 2:
		2	CHARLIE
	Rank 3:
		1	BOB
	Rank 4:
		0	DONALD

Note: candidate which scored against every other candidate (having score N-1 with default scoring settings, where N is number of candidates), also happens to be a Condorcet winner.

Synopsis

$ copeland -h
Usage:

copeland [OPTION]... [BALLOT FILE OR DIRECTORY]...

  Process files with preference lists and output Copeland's ranking.

Options:
  -names string
    	filename of list of names in the voting. If not specified names inferred from first ballot
  -normalize-case
    	normalize case (default true)
  -score-loss float
    	score for tie against opponent
  -score-tie float
    	score for tie against opponent (default 0.5)
  -score-win float
    	score for win against opponent (default 1)
  -skip-errors
    	skip ballot errors, but still report them
  -version
    	show program version and exit

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultScoring = &Scoring{
	Win:  1,
	Tie:  .5,
	Loss: 0,
}
View Source
var ErrIncorrectLength = errors.New("incorrect number of items in ballot list")

Functions

func CmpScoreEntry

func CmpScoreEntry(a, b ScoreEntry) int

func RankScore

func RankScore(scores []ScoreEntry) [][]ScoreEntry

Types

type Copeland

type Copeland struct {
	// contains filtered or unexported fields
}

func New

func New(names []string) (*Copeland, error)

func (*Copeland) Score

func (c *Copeland) Score(scoring *Scoring) []ScoreEntry

func (*Copeland) Update

func (c *Copeland) Update(ballot []string) error

type DuplicateNameError added in v1.1.0

type DuplicateNameError struct {
	// contains filtered or unexported fields
}

func (DuplicateNameError) Count added in v1.1.0

func (e DuplicateNameError) Count() int

func (DuplicateNameError) Error added in v1.1.0

func (e DuplicateNameError) Error() string

func (DuplicateNameError) Name added in v1.1.0

func (e DuplicateNameError) Name() string

type Matrix

type Matrix struct {
	// contains filtered or unexported fields
}

func NewMatrix

func NewMatrix(size int) *Matrix

func (*Matrix) Add

func (m *Matrix) Add(o *Matrix) *Matrix

func (*Matrix) Get

func (m *Matrix) Get(i, j int) int64

func (*Matrix) Inc

func (m *Matrix) Inc(i, j int)

func (*Matrix) Row

func (m *Matrix) Row(i int) []int64

func (*Matrix) Set

func (m *Matrix) Set(i, j int, value int64)

func (*Matrix) Size

func (m *Matrix) Size() int

type MissingNameError added in v1.1.0

type MissingNameError string

func (MissingNameError) Error added in v1.1.0

func (e MissingNameError) Error() string

func (MissingNameError) Name added in v1.1.0

func (e MissingNameError) Name() string

type ScoreEntry

type ScoreEntry struct {
	Name  string
	Score float64
}

type Scoring

type Scoring struct {
	Win  float64
	Tie  float64
	Loss float64
}

type UnknownNameError added in v1.1.0

type UnknownNameError string

func (UnknownNameError) Error added in v1.1.0

func (e UnknownNameError) Error() string

func (UnknownNameError) Name added in v1.1.0

func (e UnknownNameError) Name() string

Directories

Path Synopsis
cmd
copeland command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL