From 0b567e66e3100ec7c2ad2138dedf0c9ef4e37491 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Thu, 31 Dec 2020 16:43:50 +1100 Subject: [PATCH] Rename parcels_by_value to by_value and update documentation --- docs/options.md | 1 + html/index.html | 3 ++- html/index.js | 2 +- pyRCV2/cli/stv.py | 2 +- pyRCV2/method/base_stv.py | 6 +++--- tests/test_aec.py | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/options.md b/docs/options.md index 3ccc50d..c3eaadc 100644 --- a/docs/options.md +++ b/docs/options.md @@ -84,6 +84,7 @@ Other surplus transfer methods, such as non-fractional transfers (e.g. random sa * Exclude in one round (default): When excluding a candidate, transfer all their ballot papers in one round. * Exclude by parcel (by order): When excluding a candidate, transfer their ballot papers one parcel at a time, in their order each was received. Each parcel forms a separate round, i.e. if a transfer allows another candidate to meet the quota criterion, no further papers are transferred to that candidate. +* Exclude by value: When excluding a candidate, transfer their ballot papers in descending order of accumulated transfer value. Each transfer of all ballots of a certain transfer value forms a separate round. ## Ties (-t/--ties) diff --git a/html/index.html b/html/index.html index b459932..0fd635f 100644 --- a/html/index.html +++ b/html/index.html @@ -119,7 +119,8 @@
diff --git a/html/index.js b/html/index.js index 7ae2d45..e119fee 100644 --- a/html/index.js +++ b/html/index.js @@ -63,7 +63,7 @@ function changePreset() { document.getElementById('selSurplus').value = 'order'; document.getElementById('selTransfers').value = 'uig'; document.getElementById('selPapers').value = 'both'; - document.getElementById('selExclusion').value = 'parcels_by_value'; + document.getElementById('selExclusion').value = 'by_value'; document.getElementById('selTies').value = 'backwards_random'; } else if (document.getElementById('selPreset').value === 'wright') { document.getElementById('selQuotaCriterion').value = 'geq'; diff --git a/pyRCV2/cli/stv.py b/pyRCV2/cli/stv.py index 8cac26d..18f8b4d 100644 --- a/pyRCV2/cli/stv.py +++ b/pyRCV2/cli/stv.py @@ -37,7 +37,7 @@ def add_parser(subparsers): parser.add_argument('--surplus-order', '-s', choices=['size', 'order'], default='size', help='whether to distribute surpluses by size or by order of election (default: size)') parser.add_argument('--method', '-m', choices=['wig', 'uig', 'eg', 'wright'], default='wig', help='method of surpluses and exclusions (default: wig - weighted inclusive Gregory)') parser.add_argument('--transferable-only', action='store_true', help='examine only transferable papers during surplus distributions') - parser.add_argument('--exclusion', choices=['one_round', 'parcels_by_order', 'parcels_by_value'], default='one_round', help='whether to perform exclusions in one round or parcel by parcel (default: one_round)') + parser.add_argument('--exclusion', choices=['one_round', 'parcels_by_order', 'by_value'], default='one_round', help='whether to perform exclusions in one round or parcel by parcel (default: one_round)') parser.add_argument('--ties', '-t', action='append', choices=['backwards', 'prompt', 'random'], default=None, help='how to resolve ties (default: backwards then random)') parser.add_argument('--random-seed', default=None, help='arbitrary string used to seed the RNG for random tie breaking') diff --git a/pyRCV2/method/base_stv.py b/pyRCV2/method/base_stv.py index aadb8a0..a1afa23 100644 --- a/pyRCV2/method/base_stv.py +++ b/pyRCV2/method/base_stv.py @@ -43,7 +43,7 @@ class BaseSTVCounter: 'quota_criterion': 'geq', # 'geq' or 'gt' 'surplus_order': 'size', # 'size' or 'order' 'papers': 'both', # 'both' or 'transferable' - 'exclusion': 'one_round', # 'one_round', 'parcels_by_order' or 'parcels_by_value' + 'exclusion': 'one_round', # 'one_round', 'parcels_by_order' or 'by_value' 'ties': [] } @@ -548,8 +548,8 @@ class WIGSTVCounter(BaseSTVCounter): # TODO: Skip this entirely if this is the case parcel = [] count_card.parcels.remove(parcel) - elif self.options['exclusion'] == 'parcels_by_value': - # Sort the parcels by value + elif self.options['exclusion'] == 'by_value': + # Sort the ballots by value ballots = [(b, bv) for p in count_card.parcels for b, bv in p] __pragma__('opov') ballots.sort(key=lambda x: x[1] / x[0].value.to_rational(), reverse=True) diff --git a/tests/test_aec.py b/tests/test_aec.py index 5c4e156..8338936 100644 --- a/tests/test_aec.py +++ b/tests/test_aec.py @@ -42,7 +42,7 @@ def test_aec_tas19(): counter = UIGSTVCounter(election, { 'surplus_order': 'order', - 'exclusion': 'parcels_by_value' + 'exclusion': 'by_value' }) result = counter.reset()