mirror of
https://github.com/pezkuwichain/consensus.git
synced 2026-06-19 08:51:08 +00:00
Fixed division by zero in sequential Phragmén
This commit is contained in:
+27
-3
@@ -82,9 +82,12 @@ def seqPhragmén(votelist,numtoelect):
|
|||||||
candidate.backedstake=0
|
candidate.backedstake=0
|
||||||
|
|
||||||
for nom in nomlist:
|
for nom in nomlist:
|
||||||
for edge in nom.edges:
|
for edge in nom.edges:
|
||||||
edge.backingstake = nom.budget * edge.load/nom.load
|
if nom.load > 0.0:
|
||||||
edge.candidate.backedstake += edge.backingstake
|
edge.backingstake = nom.budget * edge.load/nom.load
|
||||||
|
edge.candidate.backedstake += edge.backingstake
|
||||||
|
else:
|
||||||
|
edge.backingstake = 0
|
||||||
return (nomlist,electedcandidates)
|
return (nomlist,electedcandidates)
|
||||||
|
|
||||||
def approvalvoting(votelist,numtoelect):
|
def approvalvoting(votelist,numtoelect):
|
||||||
@@ -181,6 +184,27 @@ def example1():
|
|||||||
print("Sequential Phragmén with post processing gives")
|
print("Sequential Phragmén with post processing gives")
|
||||||
printresult(nomlist, electedcandidates)
|
printresult(nomlist, electedcandidates)
|
||||||
|
|
||||||
|
def example2():
|
||||||
|
votelist = [
|
||||||
|
("10", 1000, ["10"]),
|
||||||
|
("20", 1000, ["20"]),
|
||||||
|
("30", 1000, ["30"]),
|
||||||
|
("40", 1000, ["40"]),
|
||||||
|
('2', 500, ['10', '20', '30']),
|
||||||
|
('4', 500, ['10', '20', '40'])
|
||||||
|
]
|
||||||
|
print("Votes ",votelist)
|
||||||
|
nomlist, electedcandidates = seqPhragmén(votelist,2)
|
||||||
|
print("Sequential Phragmén gives")
|
||||||
|
printresult(nomlist, electedcandidates)
|
||||||
|
nomlist, electedcandidates = approvalvoting(votelist,2)
|
||||||
|
print()
|
||||||
|
print("Approval voting gives")
|
||||||
|
printresult(nomlist, electedcandidates)
|
||||||
|
nomlist, electedcandidates = seqPhragménwithpostprocessing(votelist,2)
|
||||||
|
print("Sequential Phragmén with post processing gives")
|
||||||
|
printresult(nomlist, electedcandidates)
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
class electiontests(unittest.TestCase):
|
class electiontests(unittest.TestCase):
|
||||||
def testexample1Phragmén(self):
|
def testexample1Phragmén(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user