diff --git a/NPoS/simplePhragmén.py b/NPoS/simplePhragmén.py index ff3140e..544f928 100644 --- a/NPoS/simplePhragmén.py +++ b/NPoS/simplePhragmén.py @@ -82,9 +82,12 @@ def seqPhragmén(votelist,numtoelect): candidate.backedstake=0 for nom in nomlist: - for edge in nom.edges: - edge.backingstake = nom.budget * edge.load/nom.load - edge.candidate.backedstake += edge.backingstake + for edge in nom.edges: + if nom.load > 0.0: + edge.backingstake = nom.budget * edge.load/nom.load + edge.candidate.backedstake += edge.backingstake + else: + edge.backingstake = 0 return (nomlist,electedcandidates) def approvalvoting(votelist,numtoelect): @@ -181,6 +184,27 @@ def example1(): print("Sequential Phragmén with post processing gives") 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 class electiontests(unittest.TestCase): def testexample1Phragmén(self):