From f182ca02bd328f018ec49843185f5924c63eec0d Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Tue, 3 Aug 2021 18:38:45 +1000 Subject: [PATCH] Implement Cambridge STV - Cincinnati/Hare methods of surpluses --- docs/options.md | 21 ++- html/index.html | 3 + html/index.js | 17 +++ src/main.rs | 2 +- src/numbers/fixed.rs | 13 ++ src/numbers/gfixed.rs | 13 ++ src/numbers/mod.rs | 4 +- src/numbers/native.rs | 5 + src/numbers/rational_num.rs | 14 ++ src/numbers/rational_rug.rs | 14 ++ src/stv/gregory.rs | 20 ++- src/stv/mod.rs | 73 +++++---- src/stv/subset.rs | 286 ++++++++++++++++++++++++++++++++++++ 13 files changed, 443 insertions(+), 42 deletions(-) create mode 100644 src/stv/subset.rs diff --git a/docs/options.md b/docs/options.md index fb1b9b2..da1f455 100644 --- a/docs/options.md +++ b/docs/options.md @@ -79,15 +79,22 @@ Some STV counting rules provide, for example, that ‘no surplus shall be transf This dropdown allows you to select how ballots are transferred during surplus transfers. The recommended methods are: -* *Weighted inclusive Gregory* (default): During surplus transfers, all applicable ballot papers of the transferring candidate are examined. Transfers are weighted according to the weights of the ballot papers. +* *Weighted inclusive Gregory* (default): During surplus transfers, all applicable ballot papers of the elected candidate are examined. Transfers are weighted according to the values of the ballot papers. * *Meek method*: Transfers are computed as described at . -Other methods are supported, but not recommended: +Other Gregory methods are supported, but not recommended: -* *Unweighted inclusive Gregory*: During surplus transfers, all applicable ballot papers of the transferring 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 are examined. Transfers are not weighted. +* *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. -Other surplus transfer methods, such as non-fractional transfers (e.g. random sample) are not supported at this time. +Random subset 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. + +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. + +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. ### Papers to examine in surplus transfer (--transferable-only) @@ -223,13 +230,13 @@ When *Surplus method* is set to *Meek method*: ### (Gregory) Sum surplus transfers (--sum-surplus-transfers) -This option allows you to specify how the numbers of votes credited to candidates in a surplus transfer is calculated. In each case, votes are grouped according to the next available preference for a continuing candidate. Subsequently: +When *Surplus method* is set to a Gregory method, this option allows you to specify how the numbers of votes credited to candidates in a surplus transfer is calculated. In each case, votes are grouped according to the next available preference for a continuing candidate. Subsequently: * *Single step*: The total value of all votes expressing a next available preference for that candidate is multiplied by the surplus fraction. The product is credited to that candidate. * *By value*: The votes expressing a next available preference for that candidate are further divided according to value. For each group of votes at a particular value, the total value of all such votes is multiplied by the surplus fraction. The product is credited to that candidate. This is distinct to *Single step* only for weighted inclusive Gregory. * *Per ballot*: For each individual vote expressing a next available preference for that candidate, the value of the vote is multiplied by the surplus fraction. The product is credited to that candidate. -This option affects the result only insofar as rounding (due to use of fixed-precision arithmetic, or due to an explicit rounding option) is concerned. +This option affects the result only as far as rounding (due to use of fixed-precision/floating-point arithmetic, or an explicit rounding option) is concerned. ### (Meek) Surplus tolerance (--meek-surplus-tolerance) diff --git a/html/index.html b/html/index.html index 0d98d06..f922e6c 100644 --- a/html/index.html +++ b/html/index.html @@ -45,6 +45,7 @@ + @@ -110,6 +111,8 @@ + +