jontingvold / pyrankvote

PyRankVote is a python library for different ranked-choice voting systems, like IRV, STV and PBV. Created in June 2019.
MIT License
53 stars 16 forks source link

Non-transferable votes not handled correctly #1

Closed David1one closed 4 years ago

David1one commented 4 years ago

Instead of discarding votes that are not transferable, the single_transferable_vote function appears to randomly reallocate votes that do not have further preferences specified.

See test data: In Milo's elimination round, two ballots specify only Milo as a preference. But instead of these two ballots being discarded, they are randomly redistributed to Rua and Maeve.

STV bug report - input.txt STV bug report - output.txt

jontingvold commented 4 years ago

Are you using the the latest pypi/pip package version or master branch version?

David1one commented 4 years ago

I'm using the pip version, 1.0.9.

jontingvold commented 4 years ago

I have actually fixed this in the master branch already.

I have now released it as a new version in PyPI, so if you upgrade the package it should probably work.

pip install -U pyrankvote

The change should have been pushed till PyPI for some time ago. I initially thought it would make more sense to pick a candidate at random if ballots where exhausted, but I later changed it because it is not a very common practice among STV-systems.

I also did some other changes at the same time, like electing and rejecting more than one candidate per round if possible, so the results are now more compact. The hope was also to be able to clean up the code a bit before releasing it as version 2, but I never got around to it.

—Jon

David1one commented 4 years ago

As you say Jon, this now provides the correct output.

Thank you very much for updating the package!

-David

STV bug solution - output.txt

jontingvold commented 4 years ago

Thanks for reporting this issue by the way. It is nice to get some feedback on unexpected behaviour even if it's not strictly a bug.

And thanks for descriptive titles, splitting up the issues and providing example code. It makes it a lot quicker to investigate.

David1one commented 4 years ago

No worries! Thanks for packaging the updated version into pip.