IterableStrategyOrdinal

class poisson_approval.IterableStrategyOrdinal(profile=None, voting_rule=None, d_ranking_fixed_strategy=None, test=None)[source]

Iterate over ordinal strategies (StrategyOrdinal).

Parameters
  • profile (Profile, optional) – The attached profile.

  • voting_rule (str, optional) – The voting rule. Possible values are APPROVAL, PLURALITY and ANTI_PLURALITY. Default: the same voting rule as profile if a profile is specified, APPROVAL otherwise.

  • d_ranking_fixed_strategy (dict) – Key: ranking. Value: fixed strategy. Cf. examples below.

  • test (callable) – A function StrategyOrdinal -> bool. Only strategies meeting this test are given.

Examples

Basic usage:

>>> for strategy in IterableStrategyOrdinal():  
...     print(strategy)
<abc: a, acb: a, bac: b, bca: b, cab: c, cba: c>
<abc: a, acb: a, bac: b, bca: b, cab: c, cba: bc>
...
<abc: ab, acb: ac, bac: ab, bca: bc, cab: ac, cba: bc>

Specify a profile:

>>> from poisson_approval import ProfileOrdinal
>>> profile = ProfileOrdinal({'abc': 0.75, 'bac': 0.25})
>>> for strategy in IterableStrategyOrdinal(profile=profile):
...     print(strategy)
<abc: a, bac: b> ==> a
<abc: a, bac: ab> ==> a
<abc: ab, bac: b> ==> b
<abc: ab, bac: ab> ==> a, b

Specify some fixed strategies:

>>> iterable = IterableStrategyOrdinal(
...     d_ranking_fixed_strategy={'abc': 'a', 'acb': 'a', 'bac': 'b', 'bca': 'b'})
>>> for strategy in iterable:
...     print(strategy)
<abc: a, acb: a, bac: b, bca: b, cab: c, cba: c>
<abc: a, acb: a, bac: b, bca: b, cab: c, cba: bc>
<abc: a, acb: a, bac: b, bca: b, cab: ac, cba: c>
<abc: a, acb: a, bac: b, bca: b, cab: ac, cba: bc>

Use a condition with the parameter test:

>>> profile = ProfileOrdinal({'abc': 0.75, 'bac': 0.25})
>>> def test_a_wins(strategy):
...     return strategy.winners == {'a'}
>>> for strategy in IterableStrategyOrdinal(profile=profile, test=test_a_wins):
...     print(strategy)
<abc: a, bac: b> ==> a
<abc: a, bac: ab> ==> a