Add approval+runoff and blanket primary variants (issue #17)#44
Open
endolith wants to merge 10 commits into
Open
Add approval+runoff and blanket primary variants (issue #17)#44endolith wants to merge 10 commits into
endolith wants to merge 10 commits into
Conversation
PR Summary
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #44 +/- ##
==========================================
+ Coverage 96.37% 97.18% +0.81%
==========================================
Files 17 18 +1
Lines 496 640 +144
==========================================
+ Hits 478 622 +144
Misses 18 18
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Implement top-n plurality primaries with IRV, contingent runoff, or Condorcet generals (Final Four/Five and table variants), IRV-to-slate primaries with IRV or runoff generals, and approval primary with ranked pairwise general (unified primary). Export from elsim.methods and extend tests. Co-authored-by: endolith <endolith@gmail.com>
Add unit tests for primary ties, Condorcet cycles, runoff/IRV None paths, approval runoff edges, and IRV-to-slate primaries. Drop unreachable approval validation and IRV primary inner break; duplicate checks lived only in approval_runoff. Co-authored-by: endolith <endolith@gmail.com>
Use Find-the-winner openings, borda-style ballot descriptions, full tiebreaker and Returns wording, and explicit Wikipedia hyperlinks in RST (including section fragments) instead of :wikipedia: roles where anchors apply. Add Examples to irv_primary_top_n_* wrappers; expand module docstring. Co-authored-by: endolith <endolith@gmail.com>
Cite IJCAI approval-with-runoff (DOI), Alaska Division of Elections RCV page, FairVote Top Four PDF, St. Louis sample ballot PDF, Gehl & Porter HBS report, Condorcet 1785 (BnF Gallica), Hare 1859 (Internet Archive), and Electoral Reform Society supplementary vote page. Expand module docstring and wrapper references to match. Co-authored-by: endolith <endolith@gmail.com>
Remove prose about how references are organized; tighten Condorcet and Final Five narrative lines. Co-authored-by: endolith <endolith@gmail.com>
Fold sequential IRV slate selection into irv as a keyword-only parameter. Remove irv_eliminate_to_n and irv_primary_top_n_irv (same outcome as irv). Clarify top_n_runoff versus runoff on the full field; fix doc references and remove St. Louis / mismatched Alaska prose. Co-authored-by: endolith <endolith@gmail.com>
…ases Rename irv(..., n_survivors=) to n_winners. Capitalize reform names in docs, spell out contingent vote, add Unified Primary synonym to approval_runoff. Remove top_four_* and top_five_* wrappers; use top_n_* with n=4 or 5. Replace supplementary-vote ref with contingent vote for top_n_runoff. Co-authored-by: endolith <endolith@gmail.com>
c1023db to
094a181
Compare
_irv_eliminate_until_n_winners_remain passed a set to _inc_rank_idx, which expects a 1D boolean ndarray (same as the main irv path). This caused TypeError on all Python versions when blanket-primary tests exercised irv(..., n_winners=k). Co-authored-by: endolith <endolith@gmail.com>
Add Tennessee checks for top_n_condorcet and n=5 variants, regression tests showing primary narrowing can change contingent-vote outcomes vs plain runoff, direct helper tests, docstring examples, and hypothesis property tests for remaining ranked blanket methods. Co-authored-by: endolith <endolith@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #17.
Summary
Adds
elsim.methods.blanket_primarywith two-round reform methods:approval_runofftop_n_irvnfirst preferences (sntv)top_n_runoffnfirst preferencestop_n_condorcetnfirst preferencesirv_primary_top_n_runoffirv(..., n_winners=n)Also extends
irvwithn_winners=...for ranked primaries that eliminate to a slate without majority short-circuit.API uses
top_n_*withn=4(Top Four) orn=5(Final Five) rather than separatetop_four_*/top_five_*wrappers. Docstrings use Unified Primary, Top Four, and Final Five naming and describe the general election as a contingent vote where applicable.Tests
n=5), semantic regressions showing primary narrowing can change outcomes vs plainrunoff, helper unit tests, docstring examples, and hypothesis property tests fortop_n_runoff,top_n_condorcet, andirv_primary_top_n_runoff.Human review checklist
API & naming
elsim.methods.__init__match intended surface (approval_runoff,top_n_irv,top_n_runoff,top_n_condorcet,irv_primary_top_n_runoff).top_n_*+n=4/n=5naming is clear enough vs Alaska Top Four / Final Five reform packages.irv(..., n_winners=k)keyword-only API and return type (intvssetvsNone) read correctly in docs.Electoral semantics
approval_runoff): top-two by approval tallies, then pairwise majority on ranked ballots (contingent vote).nplurality primary (top_n_irv,top_n_runoff,top_n_condorcet): samesntvrule as existingsntv; ballots restricted to finalists before the general.top_n_runoff≠runoff: general counts first preferences among finalists only (see Tennesseen=3test: Knoxville vs Nashville).irv_primary_top_n_runoff: primary is IRV elimination tonsurvivors (no majority stop); general is contingent vote on restricted ballots.top_n_condorcetgeneral: no tiebreaker in Condorcet stage (matchescondorcet); returnsNoneon cycles.Tie-breaking
order/random/Noneconsistently withsntvandirv.approval_runoffbreaks primary and general ties via the sametiebreakerargument.None(not an arbitrary winner).Docs & references
Edge cases
test_methodsunanimity / single-candidate).n >= n_candidatesadvances everyone without error.max > 1) and row-count mismatch raiseValueError.n_winners < 1raisesValueError.Code quality
_restrict_ballotsremaps candidate IDs correctly when finalists are a non-contiguous subset.runoff/irv/condorcetinternals.__init__.py) matches project preference.