This is a Parliamentary Allocation method, also known as the Largest Remainder method with the Hare Quota.
The task is:
So $s_i$ should be either $\lfloor q_i \rfloor$ or $\lfloor q_i \rfloor + 1$
Rule:
Formally,
$S = 10$
$p_i$ | $q_i$ | $\lfloor q_i \rfloor$ | $s_i$ | |
---|---|---|---|---|
$P_1$ | 6373 | 6.373 | 6 | 6 |
$P_2$ | 2505 | 2.505 | 2 | 2 |
$P_3$ | 602 | 0.602 | 0 | 0 |
$P_4$ | 520 | 0.520 | 0 | 0 |
There remain 2 places to allocate: $\sum_i s_i = 8, S = 10$
$p_i$ | $q_i$ | $\lfloor q_i \rfloor$ | $s_i$ | |
---|---|---|---|---|
$P_1$ | 6373 | 6.373 | 6 | 6 |
$P_2$ | 2505 | 2.505 | 2 | 2 |
$P_3$ | 602 | 0.602 | 0 | 1 |
$P_4$ | 520 | 0.520 | 0 | 1 |
It's not always possible to split the seats
$p_i$ | $q_i$ | $\lfloor q_i \rfloor$ | $s_i$ | |
---|---|---|---|---|
$P_1$ | 6373 | 6.373 | 6 | 6 |
$P_2$ | 2512 | 2.512 | 2 | ? |
$P_3$ | 603 | 0.603 | 0 | 1 |
$P_4$ | 512 | 0.513 | 0 | ? |
We have a tie
def hamilton_allocation(ratios, k): frac, results = np.modf(k * ratios) remainder = int(k - results.sum()) indices = np.argsort(frac)[::-1] results[indices[0:remainder]] += 1 return results.astype(int)
ratios here sum up to 1, and k is the total number of seats
At first we have only 7 positions to allocate: $S = 7$
$p_i$ | $q_i$ | $\lfloor q_i \rfloor$ | $s_i$ | |
---|---|---|---|---|
$P_1$ | 20 | 1.373 | 1 | 2 |
$P_2$ | 34 | 2.333 | 2 | 2 |
$P_3$ | 48 | 3.294 | 3 | 3 |
$\sum$ | 102 | 6 | 7 |
But suddenly we have an additional seat: $S = 8$
$p_i$ | $q_i$ | $\lfloor q_i \rfloor$ | $s_i$ | |
---|---|---|---|---|
$P_1$ | 20 | 1.569 | 1 | ${\color{red}{\fbox{1}}}$ |
$P_2$ | 34 | 2.667 | 2 | 3 |
$P_3$ | 48 | 3.765 | 3 | 4 |
$\sum$ | 102 | 6 | 7 |
$P_1$ loses one seat!
$p_i$ | $q_i$ | $\lfloor q_i \rfloor$ | $s_i$ | |
---|---|---|---|---|
$P_1$ | 21 | 1.631 | 1 | 1 |
$P_2$ | 34 | 2.641 | 2 | 3 |
$P_3$ | 48 | 3.728 | 3 | 4 |
$\sum$ | 103 | 6 | 7 |
This is called the Alabama paradox: increasing in the number of seats causes a party to lose a sit
$S=20$
$p_i$ | $q_i$ | $\lfloor q_i \rfloor$ | $s_i$ | |
---|---|---|---|---|
$P_1$ | 1786 | 9.654 | 9 | 10 |
$P_2$ | 1246 | 6.719 | 6 | 7 |
$P_3$ | 671 | 3.627 | 3 | 3 |
$\sum$ | 3700 | 18 | 20 |
But assume that we have forgotten about additional 65 votes:
$p_i$ | $q_i$ | $\lfloor q_i \rfloor$ | $s_i$ | |
---|---|---|---|---|
$P_1$ | 1805 | 9.588 | 9 | 9 |
$P_2$ | 1283 | 6.815 | 6 | 7 |
$P_3$ | 677 | 3.596 | 3 | 4 |
$\sum$ | 3700 | 18 | 20 |
Even though $P_1$ was winning and received more additional votes than $P_3$, $P_3$ takes one seat from $P_1$
So the outcome is not robust and it is possible to manipulate the result.
Shows that Independence to Third Alternatives is not satisfies
$S = 5$
$p_i$ | $q_i$ | $\lfloor q_i \rfloor$ | $s_i$ | |
---|---|---|---|---|
$P_1$ | 14 | 2.593 | 2 | 3 |
$P_2$ | 10 | 1.667 | 1 | 2 |
$P_3$ | 3 | 0.556 | 0 | 0 |
$\sum$ | 27 | 3 | 5 |
Suppose $P_2$ lost one vote, and $P_3$ received this vote:
$p_i$ | $q_i$ | $\lfloor q_i \rfloor$ | s_i | |
---|---|---|---|---|
$P_1$ | 14 | 2.593 | 2 | 2 |
$P_2$ | 9 | 1.667 | 1 | 2 |
$P_3$ | 3 | 0.741 | 0 | 1 |
$\sum$ | 27 | 3 | 5 |
$P_1$ loses one seat, even though its position remained unchanged