Fair allocation of seats
Fair allocation of seats
General condition
There are 200 students in the three departments (100 in Department A, 60 in Department B, 40 in Department C), and a total of 20 representative meetings are allocated proportionally. The three departments have 10, 6, and 4 seats respectively:
A | B | C | |
---|---|---|---|
200 in total | 100 | 60 | 40 |
proportion | 50% | 30% | 20% |
20 seat | 10 | 6 | 4 |
Customary allocation / Maximum surplus
When the number of people in the three lines becomes 103,63,34:
A | B | C | |
---|---|---|---|
200 in total | 103 | 63 | 34 |
proportion | 51.3% | 31.5% | 17% |
20 seat | 10.3 | 6.3 | 3.4 |
actual distribution | 10 | 6 | 3+1 |
When the number of seats is increased to 21:
21 seat | 10.815 | 6.615 | 3.57 |
---|---|---|---|
actual distribution | 10+1 | 6+1 | 3 |
In this way, seats are awarded to the person who has more seats, and the person who increases the least is (possibly) stripped of his or her seat. This is unfair, because there are more seats, and C gets fewer seats.
Fair allocation
Defining index
Symbolic assumption
A | B | |
---|---|---|
people | ||
seat | ||
people per seat |
Absolute unfair value
Relative unfair value
Our target is to minimize
Definite allocation scheme
Transform one-time seat allocation into dynamic seat allocation.
Let A and B have
Assume that at the beginning of allocation:
it's not fair to A.
if:
That is, even if one more seat is given to A, the scene is still unfair to A, then this seat should go to A.
if:
It's A little more complicated in this case, if the seat is given to A, it's unfair to B. It's a time to weigh who's best for the bigger picture.
if:
At this point the seat should be given to A. Because it makes the relative unfair value smaller.
Q-value method
Formula
If there are only two groups of people:
If there are m groups of people:
At the end of the day, whoever has the highest Q value is allocated to whoever.
Apply
A | B | C | |
---|---|---|---|
200 in total | 103 | 63 | 34 |
Each department is assigned a seat:
The next 18 seats are determined using Q values.
Idealized criterion
Suppose that the number of people in m departments is
If all
If not all
The second formula means that when the total number of seats increases, no one
The general method satisfies i but does not satisfy ii, and the Q-value distribution method satisfies ii but does not satisfy i.
Particular case
First here are the python code to simulate Q value assignment:
def q_value(p, n):
lst = [] # seats
for i in p:
lst.append(1) # initial seats are all 1
lst_ = lst[:] # Q value
for i in range(n - len(p)):
for i in range(len(p)):
lst_[i] = p[i] * p[i] / (lst[i] + 1) / lst[i]
max_index = lst_.index(max(lst_))
lst[max_index] += 1
print(lst)
if __name__ == '__main__':
p = [103, 63, 34]
n = 21
q_value(p, n)
Then use the following code violence to solve, you can get a special case. In fact, there are many such exceptions, and I will only ask for the first one here:
def q_value(p, n):
lst_rate = [] # seats
sum_ = sum(p) # people
for i in p:
lst_rate.append(i / sum_ * n)
# lst_rate存的是比例分配的小数值
lst = [] # seats
for i in p:
lst.append(1) # initial seats are all 1
lst_ = lst[:] # Q value
for i in range(n - len(p)):
for i in range(len(p)):
lst_[i] = p[i] * p[i] / (lst[i] + 1) / lst[i]
max_index = lst_.index(max(lst_))
lst[max_index] += 1
for i in range(len(lst)):
if abs(lst[i] - lst_rate[i]) > 1:
# 如果Q值算出来和小数值差1以上就不满足条件1,返回
print(p, n, lst, lst_rate)
exit(0)
if __name__ == '__main__':
for i_1 in range(200, 1000):
for i_2 in range(200, 1000):
for i_3 in range(200, 1000):
for i_4 in range(200, 1000):
for i_5 in range(200, 1000):
p = [i_1, i_2, i_3, i_4, i_5]
n = 243
q_value(p, n)
[200, 200, 200, 200, 488]
243
[38, 38, 38, 38, 91]
[37.732919254658384, 37.732919254658384, 37.732919254658384, 37.732919254658384, 92.06832298136646]