Sulprobil
Search…
sbDHondt
If you want distribute a given number of parliament seats to parties in a fair relation with regards to the votes they got, you can use the D'Hondt method.
Please read my Disclaimer.
1
Function sbDHondt(lSeats As Long, vVotes As Variant) As Variant
2
'Implements the D'Hondt method for allocating seats in
3
'party-list proportional representation political election
4
'systems
5
'Reverse("moc.LiborPlus.www") V0.10 PB 01-Dec-2009
6
Dim i As Long, k As Long, n As Long
7
Dim vA As Variant, vB As Variant, vR As Variant
8
Dim dMax As Double
9
10
With Application.WorksheetFunction
11
vA = .Transpose(.Transpose(vVotes))
12
vB = vA
13
n = UBound(vA, 1)
14
ReDim vR(1 To n, 1 To 1) As Variant
15
ReDim lDenom(1 To n) As Long
16
17
Do While i < lSeats
18
'identify max
19
dMax = .Max(vB)
20
k = .Match(dMax, vB, 0)
21
lDenom(k) = lDenom(k) + 1
22
vB(k, 1) = vA(k, 1) / (lDenom(k) + 1#)
23
vR(k, 1) = vR(k, 1) + 1
24
i = i + 1
25
Loop
26
sbDHondt = vR
27
End With
28
End Function
Copied!
Other, but similar methods are shown at sbRoundToSum and sbExactRandHistogrm.
Last modified 1yr ago
Copy link