From 08007019605414a7be47e5aef486f99c16f703cd Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Wed, 4 Aug 2021 13:46:32 +1000 Subject: [PATCH] Implement configurable --sample-per-ballot --- docs/options.md | 27 ++++++++++++++--------- html/index.html | 14 +++++++++--- html/index.js | 38 ++++++++++++++++++-------------- src/main.rs | 5 +++++ src/stv/gregory.rs | 4 ++-- src/stv/mod.rs | 24 ++++++++++++-------- src/stv/{subset.rs => sample.rs} | 8 +++++-- src/stv/wasm.rs | 2 ++ tests/act.rs | 1 + tests/aec.rs | 1 + tests/cambridge.rs | 1 + tests/constraints.rs | 4 ++++ tests/csm.rs | 1 + tests/ers97.rs | 1 + tests/meek.rs | 3 +++ tests/prsa.rs | 1 + tests/scotland.rs | 2 ++ 17 files changed, 94 insertions(+), 43 deletions(-) rename src/stv/{subset.rs => sample.rs} (98%) diff --git a/docs/options.md b/docs/options.md index 02fddd2..5f9be3c 100644 --- a/docs/options.md +++ b/docs/options.md @@ -15,7 +15,7 @@ The preset dropdown allows you to choose from a hardcoded list of preloaded STV | Australian Senate STV | Rules from the [*Commonwealth Electoral Act 1918*](https://www.legislation.gov.au/Details/C2020C00400/Html/Text#_Toc59107700), using the unweighted inclusive Gregory method. | [E2] [E3] [E4] | ✓ | | Western Australia STV | Rules from the [*Electoral Act 1907* (WA)](https://www.legislation.wa.gov.au/legislation/prod/filestore.nsf/FileURL/mrdoc_29498.pdf/$FILE/Electoral%20Act%201907%20-%20[17-a0-06].pdf), using the weighted inclusive Gregory method. | [E2] [E3] | | | Australian Capital Territory STV | Rules from the [*Electoral Act 1992* (ACT)](https://www.legislation.act.gov.au/View/a/1992-71/current/PDF/1992-71.PDF), using the exclusive Gregory method. | | ✓ | -| Cambridge STV | Rules from the former [chapter 54A of the *Massachusetts General Laws*](https://www.cambridgema.gov/-/media/Files/electioncommission/massachusettsgenerallawschapter54a.pdf), as modified and in effect in Cambridge, Massachusetts. See also [here](https://web.archive.org/web/20081118104049/http://www.fairvote.org/media/1993countmanual.pdf). | | ✓ | +| Cambridge STV | Rules in force in Cambridge, Massachusetts. These rules are derived from the [former chapter 54A of the Massachusetts General Laws](https://www.cambridgema.gov/-/media/Files/electioncommission/massachusettsgenerallawschapter54a.pdf), but have by regulation been modified to incorporate the procedures set out in Article IX of the former [1938 Charter of the City of Cincinnati](https://catalog.hathitrust.org/Record/001754258). See also [here](https://web.archive.org/web/20081118104049/http://www.fairvote.org/media/1993countmanual.pdf). | | ✓ | | [Wright STV](https://www.aph.gov.au/Parliamentary_Business/Committees/House_of_Representatives_Committees?url=em/elect07/subs/sub051.1.pdf) | Rules proposed by Anthony van der Craats designed for computer counting, involving reset and re-iteration of the count after each candidate exclusion. | | ✓ | | [PRSA 1977](https://www.prsa.org.au/rule1977.htm) | Simple rules designed for hand counting, using the exclusive Gregory method, with counting performed in thousandths of a vote. | | ✓ | | [ERS97](https://www.electoral-reform.org.uk/latest-news-and-research/publications/how-to-conduct-an-election-by-the-single-transferable-vote-3rd-edition/) | More complex rules designed for hand counting, using the exclusive Gregory method. | | ✓ | @@ -88,21 +88,23 @@ Other Gregory methods are supported, but not recommended: * *Unweighted inclusive Gregory*: During surplus transfers, all applicable ballot papers of the elected candidate are examined. Transfers are not weighted, and each ballot paper has equal value in the calculation. * *Exclusive Gregory (last bundle)*: During surplus transfers, only the ballot papers received in the last transfer (all of one value) are examined. -Random subset methods are also supported, but also not recommended: +Random sample methods are also supported, but also not recommended: -* *Cincinnati (inclusive subset)*: During surplus transfers, a subset of the elected candidate's ballot papers, equal in size to the surplus, is examined. -* *Hare (exclusive subset)*: During surplus transfers, a subset of the ballot papers received in the last transfer, equal in size to the surplus, is examined. +* *Cincinnati (inclusive sample)*: During surplus transfers, a subset of the elected candidate's ballot papers, equal in size to the surplus, is examined. +* *Hare (exclusive sample)*: During surplus transfers, a subset of the ballot papers received in the last transfer, equal in size to the surplus, is examined. -The use of a random subset method requires *Normalise ballots* to be enabled, and requires the *Quota criterion* to be set to *>=*. When a random subset method is used, surplus transfers and exclusions are performed one ballot paper at a time, and candidates are declared elected immediately on reaching the quota. Consequential surpluses therefore do not arise, and surpluses only occur during the count of first preferences. +The use of a random sample method requires *Normalise ballots* to be enabled, and requires the *Quota criterion* to be set to *>=*. -In both random subset methods, the subset is selected using the deterministic method used in [Cambridge, Massachusetts](https://web.archive.org/web/20081118104049/http://www.fairvote.org/media/1993countmanual.pdf) (derived from Article IX of the former 1938 Cincinnati *Code of Ordinances*). This depends on the order of ballot papers in the BLT file, and is independent of the *Random seed* option. +In both random sample methods, the subset is selected using the deterministic method used in [Cambridge, Massachusetts](https://web.archive.org/web/20081118104049/http://www.fairvote.org/media/1993countmanual.pdf) (derived from Article IX of the former 1938 Cincinnati *Code of Ordinances*). This depends on the order of ballot papers in the BLT file, and is independent of the *Random seed* option. -### Papers to examine in surplus transfer (--transferable-only) +### Papers to examine in surplus transfer (--t ransferable-only) * *Include non-transferable papers* (default): When this option is selected, all ballot papers of the transferring candidate are examined. Non-transferable papers are always exhausted at the relevant surplus fractions. * *Use transferable papers only* (CLI: --transferable-only): When this option is selected, only transferable papers of the transferring candidate are examined. Non-transferable papers are exhausted only if the value of the transferable papers is less than the surplus. -### Exclusion method (--exclusion) +### (Gregory) Exclusion method (--exclusion) + +When *Surplus method* is set to a Gregory method, this option controls how candidates are excluded: * *Single stage* (default): When excluding candidate(s), transfer all their ballot papers in one stage. * *By value*: When excluding candidate(s), transfer their ballot papers in descending order of accumulated transfer value. Each transfer of all ballots of a certain transfer value forms a separate stage, i.e. if a transfer allows another candidate to meet the quota criterion, no further papers are transferred to that candidate. @@ -110,8 +112,6 @@ In both random subset methods, the subset is selected using the deterministic me * *By parcel (by order)*: When excluding a candidate, transfer their ballot papers one parcel at a time, in the order each was received. Each parcel forms a separate stage. This option cannot be combined with bulk exclusion. * *Wright method (re-iterate)*: When excluding candidate(s), reset the count from the distribution of first preferences, disregarding the excluded candidates. -When *Surplus method* is set to *Meek method*, this setting is ignored, and the Meek method is instead applied. - ### (Meek) NZ-style exclusion (--meek-nz-exclusion) When *Surplus method* is set to *Meek method*, this option controls how candidate keep values are updated when candidates are excluded: @@ -119,6 +119,13 @@ When *Surplus method* is set to *Meek method*, this option controls how candidat * When NZ-style exclusion is disabled (default), the excluded candidate's keep value is immediately reduced to 0. This is the method specified in the 1987 and 2006 Meek rules. * When NZ-style exclusion is enabled, all elected candidates' keep values are first updated by one further iteration; only then is the excluded candidate's keep value reduced to 0. This is the method specified in the New Zealand *Local Electoral Regulations 2001*. +### (Sample) Transfer ballot-by-ballot (--sample-per-ballot) + +When *Surplus method* is set to a random sample method, this option controls when candidates are declared elected: + +* When ballot-by-ballot transfer is disabled (default), candidates are declared elected only at the end of a stage, as usual. +* When ballot-by-ballot transfer is enabled, candidates are declared elected immediately on meeting the quota after the transfer of any single ballot paper. Consequential surpluses therefore do not arise, and surpluses only occur during the count of first preferences. + ### Ties (-t/--ties) This dropdown allows you to select how ties (in surplus transfer or exclusion) are broken. The options are: diff --git a/html/index.html b/html/index.html index 7547b1e..6ecbd52 100644 --- a/html/index.html +++ b/html/index.html @@ -106,13 +106,13 @@