UtilBallots Module

poisson_approval.utils.UtilBallots.allowed_ballots(voting_rule='Approval')[source]

Allowed ballots in a voting rule.

Parameters:voting_rule (str) – The voting rule. Possible values are APPROVAL, PLURALITY and ANTI_PLURALITY.
Returns:The list of all allowed ballots.
Return type:list

Examples

>>> allowed_ballots(APPROVAL)
['a', 'ab', 'ac', 'b', 'bc', 'c']
>>> allowed_ballots(PLURALITY)
['a', 'b', 'c']
>>> allowed_ballots(ANTI_PLURALITY)
['ab', 'ac', 'bc']
poisson_approval.utils.UtilBallots.ballot_high_u(ranking, voting_rule)[source]

Ballot chosen by the voters who have a high utility for their middle candidate.

Parameters:
  • ranking (str) – A ranking.
  • voting_rule (str) – The voting rule. Possible values are APPROVAL, PLURALITY and ANTI_PLURALITY.
Returns:

The ballot chosen by the voters with this ranking and a high utility for their middle candidate, in case the response is utility-dependent.

Return type:

str

Examples

>>> ballot_high_u('abc', APPROVAL)
'ab'
>>> ballot_high_u('abc', PLURALITY)
'b'
>>> ballot_high_u('abc', ANTI_PLURALITY)
'ab'
poisson_approval.utils.UtilBallots.ballot_low_u(ranking, voting_rule)[source]

Ballot chosen by the voters who have a low utility for their middle candidate.

Parameters:
  • ranking (str) – A ranking.
  • voting_rule (str) – The voting rule. Possible values are APPROVAL, PLURALITY and ANTI_PLURALITY.
Returns:

The ballot chosen by the voters with this ranking and a low utility for their middle candidate, in case the response is utility-dependent.

Return type:

str

Examples

>>> ballot_low_u('abc', APPROVAL)
'a'
>>> ballot_low_u('abc', PLURALITY)
'a'
>>> ballot_low_u('abc', ANTI_PLURALITY)
'ac'
poisson_approval.utils.UtilBallots.ballot_one(ranking)[source]

Ballot for the voter’s preferred candidate.

Parameters:ranking (str) – A ranking.
Returns:The first candidate.
Return type:str

Examples

>>> ballot_one('abc')
'a'
poisson_approval.utils.UtilBallots.ballot_one_three(ranking)[source]

Ballot for the voter’s first and third candidates.

Parameters:ranking (str) – A ranking.
Returns:The ballot with the first and third candidates.
Return type:str

Examples

>>> ballot_one_three('abc')
'ac'
>>> ballot_one_three('cba')
'ac'
poisson_approval.utils.UtilBallots.ballot_one_two(ranking)[source]

Ballot for the voter’s two preferred candidates.

Parameters:ranking (str) – A ranking.
Returns:The ballot with the two first candidates.
Return type:str

Examples

>>> ballot_one_two('abc')
'ab'
>>> ballot_one_two('bac')
'ab'
poisson_approval.utils.UtilBallots.ballot_two(ranking)[source]

Ballot for the voter’s second most-liked candidate.

Parameters:ranking (str) – A ranking.
Returns:The second candidate.
Return type:str

Examples

>>> ballot_two('abc')
'b'
poisson_approval.utils.UtilBallots.sort_ballot(ballot)[source]

Put a ballot in alphabetical order.

Parameters:ballot (str) – A ballot, e.g. 'a', 'ab', 'ba', etc.
Returns:The same ballot in alphabetical order.
Return type:str

Examples

>>> sort_ballot('a')
'a'
>>> sort_ballot('ab')
'ab'
>>> sort_ballot('ba')
'ab'