python-vote-core icon indicating copy to clipboard operation
python-vote-core copied to clipboard

Floating point errors may break ties that should not be broken

Open andersk opened this issue 9 years ago • 0 comments

The following Schulze STV election should have two tied winner sets ABC and ABD. However, small floating point errors in the vote management strength computation result in only ABC being shown as winning. Specifically, the strength of ABE against C is computed as 2.571428571, while the strengths of ABF against D and AEF against D are computed as 2.571428572; the correct result is exactly 18/7 for all three.

(I am working on an independent implementation of Schulze STV in Rust using exact big-rational arithmetic, which is one way to get around this problem. Adding tolerance to the floating point comparisons may also work. I found this example after many hours of random testing against my implementation, so fortunately this condition seems to be extremely rare.)

SchulzeSTV([
    {'ballot': [['A', 'B', 'C', 'D']]},
    {'ballot': [['A', 'B', 'E'], ['D']]},
    {'ballot': [['A', 'C', 'D'], ['B']]},
    {'ballot': [['A', 'C', 'F'], ['B']]},
    {'ballot': [['A', 'D'], ['E']]},
    {'ballot': [['A'], ['D', 'E', 'F']]},
    {'ballot': [['B'], ['E'], ['D']]},
    {'ballot': [['C', 'E']]},
    {'ballot': [['F'], ['D']]},
], required_winners=3, ballot_notation=SchulzeSTV.BALLOT_NOTATION_GROUPING)

andersk avatar Dec 19 '16 23:12 andersk