Algorithmadvanced
Slater's rule
Also called Slater ranking.
Finds the ranking that disagrees with the fewest pairwise majority outcomes, a minimum feedback arc set of the majority tournament.
- Time
- O(n m^2 + 2^m m) worst
- Space
- O(2^m) extra
- Where
- m = the number of candidates; n = the number of voters
- Model
- Word RAM
- Properties
- not comparison baseddeterministiciterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Patrick Slater, 1961
Slater's rule turns the majority relation of an election into a ranking. For each pair of candidates, a majority of voters prefers one to the other, and the rule looks for the ranking that goes against as few of these majorities as possible. When the majority relation has no cycle, the answer is that relation itself. When it has cycles, some majorities must be reversed, and the rule reverses the fewest. In graph terms, it finds a minimum feedback arc set of the majority tournament. The Slater winners are the candidates on top of some optimal ranking. The problem is NP-hard. The algorithm below is a dynamic program over subsets that takes time after the majorities are counted, which is fast enough for about 20 candidates.
In plain words
For every pair of candidates, count which one more voters prefer. Each such result is one fact about the voters. A ranking agrees with some of these facts and goes against others. Slater's rule picks the ranking that goes against the fewest facts, and the top of that ranking wins. Only who won each pair counts, not by how much. The program builds the best ranking one place at a time: for every group of candidates, it remembers the best way to rank that group, and it tries each member of a group as its first.
The problem
There are candidates and a profile of rankings. Let be the margin of over . The majority graph has an arc when ; when is odd it is a tournament, with one arc between each pair. For a ranking , its Slater cost is the number of pairs where puts above although . A Slater ranking has the least cost, and the Slater winners are the candidates on top of some Slater ranking. The code returns the Slater ranking that is first in lexicographic order, and its top as the winner. Pairs with margin 0 cost nothing in either order.
The algorithm
For a set of candidates, let be the least cost of a ranking of alone. If is first, it is above all of , so it goes against the arcs into from , and the rest is ranked as well as possible:
where . Sets are stored as bit masks.
SLATER(P, m)- 1
lose[v] ← {u : g(u, v) > 0} for each v, from the margins of P - 2
cost[∅] ← 0 - 3
for each nonempty S ⊆ A, in increasing order of its bit mask do - 4
cost[S] ← min over v ∈ S of |lose[v] ∩ (S \ {v})| + cost[S \ {v}] - 5
S ← A; r ← empty list - 6
while S ≠ ∅ do - 7
v ← the smallest v ∈ S with |lose[v] ∩ (S \ {v})| + cost[S \ {v}] = cost[S] - 8
append v to r; S ← S \ {v} - 9
return r
The bit mask of is smaller than that of , so line L4 only reads entries that are already filled. Lines L5 to L8 rebuild an optimal ranking from the table. Taking the smallest that is optimal at each step gives the lexicographically first Slater ranking. A candidate is a Slater winner exactly when it passes the test of line L7 for .
Example
Take four candidates (indices 0 to 3) and 13 voters:
| voters | ranking |
|---|---|
| 4 | |
| 6 | |
| 3 |
The majority arcs, with margins, are (7), (7), (7), (5), (1) and (1). They form the cycles and , so there is no Condorcet winner, and all four candidates are in the Smith set. The test of line L7 for gives:
| first | arcs into | best ranking of the rest | total |
|---|---|---|---|
| , : 2 | : 0 | 2 | |
| : 1 | is a cycle: 1 | 2 | |
| , : 2 | is a cycle: 1 | 3 | |
| : 1 | : 0 | 1 |
So , the only Slater ranking is , and wins. It reverses only the arc . Kemeny's rule weighs each reversed arc by its margin. It prefers , which reverses and , of margin 1 each, for a weight of 2 against 5 for the Slater ranking. So the two rules elect different candidates on this profile.
Correctness
The recursion of line L4 is correct because in any ranking of with first element , the pairs that include cost exactly , and the other pairs are a ranking of , which costs at least and can cost exactly that. Lines L5 to L8 follow optimal choices, so the ranking they build has cost . The proof in proofs/correctness.md gives the details and proves the properties below.
Proof: Correctness and properties of the subset program for Slater's rulefull
Let , let be a profile of rankings, and let be the margins. Write when , and . For a ranking of a set , its cost is the number of pairs with and above in . Let be the least cost of a ranking of , with .
Claim 1 (recursion). For nonempty , . More precisely, the least cost of a ranking of with first element is the term for .
Proof. Let be a ranking of with first element , and let be the rest of , a ranking of . The pairs that contain have on top, so exactly those with , , are reversed. The other pairs are the pairs of . So . The least value over is the term for , and the least value over is the right side.
Claim 2 (correctness). After lines L2 to L4, for every . Lines L5 to L8 return the Slater ranking that is first in lexicographic order. A candidate is a Slater winner exactly when it passes the test of line L7 for .
Proof. The first part follows from Claim 1 by induction on the bit mask of , because the mask of is smaller than that of . For the second part, consider the loop with the invariant that the list built so far is a prefix of the lexicographically first ranking of with cost , and that is the set of the candidates not in . A ranking that begins with and continues with can reach cost exactly when passes the test of line L7, by Claim 1 applied to and because the pairs between and are the same for all such rankings. The lexicographically first optimal ranking continues with the smallest such , and line L7 picks it. The third part is Claim 1 for .
Claim 3 (Smith set on top). Let be the Smith set, the smallest nonempty set of candidates each of whom has a positive margin over every candidate outside it. Every Slater ranking puts every member of above every candidate outside .
Proof. Let be a ranking that puts some above some . Let list the members of in their order in , then the others in their order in . Pairs inside and pairs outside keep their order. A pair with and has , so it costs nothing in , and at least one such pair costs 1 in . So , and is not optimal. A Condorcet winner has , so it is on top of every Slater ranking.
Claim 4 (Pareto). If and every voter ranks above , then every Slater ranking puts above .
Proof. For every , a voter who ranks above also ranks above , and a voter who ranks above also ranks above . So implies , and implies . Let put above , and let be with and exchanged. For above both or below both, the two pairs with cost the same in total in and . For between them, has above above and pays , and pays , which is not more by the two implications. The pair has , since , and costs 1 in and 0 in . So .
Claim 5 (monotonicity). Let be a Slater winner of , and let be with moved up one place on one ballot, passing . Then is a Slater winner of .
Proof. Only the margin between and changes, by 2 in favour of . So the only arc that can change is between and : the arc may disappear, and the arc may appear. For a ranking , the cost changes only on the pair . If puts above , the cost goes down by , and if puts above , it does not go down. So every cost goes down by at most , and a Slater ranking of with on top goes down by exactly . So is optimal for , and is a winner.
Claim 6 (anonymity and neutrality). Reordering the voters does not change the result. Renaming the candidates by renames the Slater rankings and the winners by .
Proof. The cost of a ranking depends only on the arcs, which do not depend on the order of the voters, and renaming the candidates renames the arcs.
Claim 7 (time). SLATER runs in time and space on a word RAM with words of at least bits.
Proof. The margins take time, and line L1 takes . Line L4 runs for sets and tries at most candidates, each with one AND, one population count, one lookup and one addition. Lines L5 to L8 run times with at most tries each. The table has entries of bits.
Complexity
Counting the margins takes time. The table has entries, and each entry tries at most candidates with word operations: one AND and one population count on an -bit mask, which fits in a word when is at most the word size of the word RAM. Lines L5 to L8 take time. The total is time and space. Trying all rankings instead would take time.
Finding a Slater ranking, or deciding whether a candidate is a Slater winner, is NP-hard, so no polynomial algorithm is expected. For approximations of feedback arc set in tournaments, see Kemeny rank aggregation, which treats the weighted version, and KwikSort, which gives an expected ratio of 3 for the unweighted version with random pivots.
Properties
The proofs are in proofs/correctness.md, and the tests check each property on all profiles with up to 4 candidates and few voters and on random profiles with up to 6 candidates.
- Smith set on top. Every Slater ranking puts the whole Smith set above all other candidates. So the Slater winners lie in the Smith set, and a Condorcet winner is the only winner.
- Pareto. If every voter ranks above , then every Slater ranking puts above , so does not win.
- Monotone. Moving a winner up on one ballot keeps it a winner.
- Anonymous, and neutral as a correspondence. Only the majority graph is used. The resolute rule is not neutral, because of the tie rule.
- A tournament solution. The result depends only on the majority graph. So two profiles with the same majorities but very different margins have the same Slater rankings, unlike Kemeny's rule.
- Manipulable. The tests find a voter who gains by a false ranking with 3 candidates and 3 voters.
Variants and improvements
- Kemeny's rule. Weigh each reversed arc by its margin. This is the weighted feedback arc set problem on the same graph, and the same subset program solves it with sums of margins in place of counts.
- Integer programs. Exact solvers for larger use the integer program with one variable for each ordered pair and a constraint for each triple that forbids a cycle of length 3.
- Approximation. KwikSort, which sorts by majorities with random pivots, has an expected ratio of 3 for feedback arc set in tournaments.
- Ties in the majority graph. With even, some pairs have margin 0. This page charges nothing for them. Other versions charge one half in either order, which gives the same rankings.
When to use it
Use Slater's rule when only the outcomes of pairwise contests are known or trusted, as in round-robin tournaments in sport or in comparisons by judges. For elections with full ballots, Kemeny's rule uses more of the information. With up to about 20 candidates, the subset program is exact and fast; beyond that, use an integer program solver or an approximation.
Pitfalls
- Ranking by wins. Sorting candidates by their number of majority wins, the Copeland score, is not the Slater ranking, even when it has no ties.
- Counting margins. The cost counts reversed arcs, not their margins. Using margins gives Kemeny's rule, which can elect a different candidate, as in the example.
- The memory of the table. The table has entries. For , that is about a billion entries, too many for most machines.
- Ties. Several rankings can be optimal, and their tops can differ. Return the set of winners, or state the tie rule.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Shared helper of the algorithmic game theory pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Preference profiles, majority relations and brute force axiom checkers.
The candidates are 0, ..., m - 1. A ranking is a tuple of all m candidates, best first:
(2, 0, 1) means that 2 is preferred to 0 and 0 to 1. A profile is a tuple of n rankings,
one per voter. An approval ballot is a frozenset of candidates, and an approval profile is
a tuple of n ballots.
A rule is a function rule(profile, m). A resolute rule returns one candidate (an int); a
correspondence returns a nonempty frozenset of candidates. The checkers accept both: they
turn an int w into frozenset({w}).
Each checker takes the rule, m and n, and by default tries every profile of all_profiles(m,
n). Pass profiles= to check a given list of profiles instead (for example approval profiles,
or a random sample when the full domain is too large). Each checker returns None when the
property holds on every profile it tried, and else a counterexample tuple.
There is no voting rule in this module. Every count is an exact integer.
"""
from itertools import permutations, product
# ---------------------------------------------------------------- rankings and profiles
def all_rankings(m):
"""Return the list of the m! rankings of 0, ..., m - 1, in lexicographic order."""
return list(permutations(range(m)))
def all_profiles(m, n):
"""Yield every profile of n rankings of m candidates: (m!)^n profiles, voters ordered."""
return product(all_rankings(m), repeat=n)
def random_profile(rng, m, n):
"""Return a profile of n rankings drawn uniformly and independently (impartial culture)."""
return tuple(tuple(rng.sample(range(m), m)) for _ in range(n))
def position(r, a):
"""Return the position of candidate a in ranking r: 0 for the top."""
return r.index(a)
def prefers(r, a, b):
"""Return True if ranking r puts a above b."""
return r.index(a) < r.index(b)
def pairwise(profile, m):
"""Return the m by m matrix N with N[a][b] the number of voters who rank a above b."""
N = [[0] * m for _ in range(m)]
for r in profile:
for i, a in enumerate(r):
for b in r[i + 1:]:
N[a][b] += 1
return N
def margins(profile, m):
"""Return the m by m matrix of margins N[a][b] - N[b][a]."""
N = pairwise(profile, m)
return [[N[a][b] - N[b][a] for b in range(m)] for a in range(m)]
def condorcet_winner(profile, m):
"""Return the candidate with a positive margin over every other candidate, or None."""
M = margins(profile, m)
for a in range(m):
if all(M[a][b] > 0 for b in range(m) if b != a):
return a
return None
def weak_condorcet_winners(profile, m):
"""Return the frozenset of candidates whose margin over every other candidate is >= 0."""
M = margins(profile, m)
return frozenset(a for a in range(m) if all(M[a][b] >= 0 for b in range(m) if b != a))
def kendall_tau(r1, r2):
"""Return the number of pairs of candidates that r1 and r2 order differently."""
pos = {a: i for i, a in enumerate(r2)}
seq = [pos[a] for a in r1]
return sum(1 for i in range(len(seq)) for j in range(i + 1, len(seq)) if seq[i] > seq[j])
def is_single_peaked_on(profile, axis):
"""Return True if every ranking of the profile is single-peaked on the axis.
axis is a tuple of all candidates, left to right. A ranking is single-peaked on the axis
exactly when, for each k, its k best candidates form a contiguous block of the axis.
"""
where = {a: i for i, a in enumerate(axis)}
for r in profile:
lo = hi = where[r[0]]
for a in r[1:]:
p = where[a]
if p == lo - 1:
lo = p
elif p == hi + 1:
hi = p
else:
return False
return True
def lex_tiebreak(candidates):
"""Return the candidate with the smallest index: the default tie-breaking rule."""
return min(candidates)
def random_approval_profile(rng, m, n, p):
"""Return n approval ballots; each voter approves each candidate with probability p."""
return tuple(frozenset(a for a in range(m) if rng.random() < p) for _ in range(n))
def permute_profile(profile, pi):
"""Rename the candidates: candidate a becomes pi[a]. Works for rankings and approval ballots."""
out = []
for ballot in profile:
if isinstance(ballot, (set, frozenset)):
out.append(frozenset(pi[a] for a in ballot))
else:
out.append(tuple(pi[a] for a in ballot))
return tuple(out)
# ---------------------------------------------------------------- axiom checkers
def _as_set(result):
if isinstance(result, (set, frozenset)):
return frozenset(result)
return frozenset([result])
def _domain(m, n, profiles):
return all_profiles(m, n) if profiles is None else profiles
def _candidate_generators(m):
"""A transposition and an m-cycle: together they generate every permutation of the candidates."""
gens = []
if m >= 2:
swap = list(range(m))
swap[0], swap[1] = 1, 0
gens.append(tuple(swap))
if m >= 3:
gens.append(tuple((a + 1) % m for a in range(m)))
return gens
def check_anonymity(rule, m, n, profiles=None):
"""Check that permuting the voters does not change the result.
It tries the swap of voters 0 and 1 and the cyclic shift of the voters. These generate all
permutations, so on the full domain this is a complete test. Returns None or
(profile, permuted_profile).
"""
for P in _domain(m, n, profiles):
P = tuple(P)
if len(P) < 2:
continue
base = _as_set(rule(P, m))
others = [(P[1], P[0]) + P[2:], P[1:] + P[:1]]
for Q in others:
if _as_set(rule(Q, m)) != base:
return (P, Q)
return None
def check_neutrality(rule, m, n, profiles=None):
"""Check that renaming the candidates by pi renames the result by pi.
It tries a transposition and an m-cycle of the candidates, which generate all permutations.
A resolute rule with a fixed tie-breaking order usually fails this test; test its
correspondence instead. Returns None or (profile, pi).
"""
gens = _candidate_generators(m)
for P in _domain(m, n, profiles):
P = tuple(P)
base = _as_set(rule(P, m))
for pi in gens:
if _as_set(rule(permute_profile(P, pi), m)) != frozenset(pi[a] for a in base):
return (P, pi)
return None
def check_pareto(rule, m, n, profiles=None):
"""Check that no candidate b wins when every voter ranks some a above b.
Returns None or (profile, a, b).
"""
for P in _domain(m, n, profiles):
P = tuple(P)
W = _as_set(rule(P, m))
N = pairwise(P, m)
for b in W:
for a in range(m):
if a != b and N[a][b] == len(P):
return (P, a, b)
return None
def check_condorcet_consistency(rule, m, n, profiles=None):
"""Check that a Condorcet winner, when one exists, is the unique winner.
Returns None or (profile, condorcet_winner).
"""
for P in _domain(m, n, profiles):
P = tuple(P)
c = condorcet_winner(P, m)
if c is not None and _as_set(rule(P, m)) != frozenset([c]):
return (P, c)
return None
def _raise_once(r, w):
"""Return r with w moved up one place, or None if w is already on top."""
i = r.index(w)
if i == 0:
return None
s = list(r)
s[i - 1], s[i] = s[i], s[i - 1]
return tuple(s)
def check_monotonicity(rule, m, n, profiles=None):
"""Check that a winner stays a winner when one voter moves it up one place.
Every raise of w, with no other change in the relative order of the others, is a chain of
such one-place moves, so on the full domain this is a complete test. For a correspondence
the test is that w stays in the winning set. Returns None or (profile, raised_profile, w).
"""
for P in _domain(m, n, profiles):
P = tuple(P)
for w in _as_set(rule(P, m)):
for i, r in enumerate(P):
s = _raise_once(r, w)
if s is None:
continue
Q = P[:i] + (s,) + P[i + 1:]
if w not in _as_set(rule(Q, m)):
return (P, Q, w)
return None
def find_manipulation(rule, m, n, profiles=None):
"""Search for a voter who gets a strictly better winner by a false ranking.
The rule must be resolute (a correspondence must return one winner on every profile it
is called on). Returns None or (profile, voter, false_ranking): with the false ranking in
place of the voter's true one, the winner is one that the true ranking strictly prefers.
"""
rankings = all_rankings(m)
for P in _domain(m, n, profiles):
P = tuple(P)
w = _single(rule(P, m))
for i, r in enumerate(P):
if r[0] == w:
continue
for s in rankings:
if s == r:
continue
Q = P[:i] + (s,) + P[i + 1:]
if prefers(r, _single(rule(Q, m)), w):
return (P, i, s)
return None
def _single(result):
W = _as_set(result)
if len(W) != 1:
raise ValueError("find_manipulation needs a resolute rule")
return next(iter(W))
slater_rule.py 73 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/slater-rule/. The authors are listed in prov/DWARFM.jsonl.
from typing import Sequence
Ranking = Sequence[int]
def margin_matrix(profile: Sequence[Ranking], m: int) -> list[list[int]]:
"""Return M with M[a][b] = (voters who rank a above b) - (voters who rank b above a)."""
M = [[0] * m for _ in range(m)]
for r in profile:
for i, a in enumerate(r):
for b in r[i + 1:]:
M[a][b] += 1
M[b][a] -= 1
return M
def slater_cost(profile: Sequence[Ranking], m: int, ranking: Ranking) -> int:
"""Return the number of pairs that the ranking puts against a strict majority."""
M = margin_matrix(profile, m)
return sum(1 for i, a in enumerate(ranking) for b in ranking[i + 1:] if M[b][a] > 0)
def _table(profile: Sequence[Ranking], m: int) -> tuple[list[int], list[int]]:
"""Return (lose, cost): lose[v] is the bit set of the u with a positive margin over v, and
cost[S] is the least number of majority disagreements of a ranking of the set S."""
M = margin_matrix(profile, m)
lose = [sum(1 << u for u in range(m) if M[u][v] > 0) for v in range(m)] # @line L1
cost = [0] * (1 << m) # @line L2
for S in range(1, 1 << m): # @line L3
best = None
T = S
while T:
v = (T & -T).bit_length() - 1
T &= T - 1
rest = S & ~(1 << v)
c = (lose[v] & rest).bit_count() + cost[rest] # @line L4
if best is None or c < best:
best = c
cost[S] = best
return lose, cost
def slater_ranking(profile: Sequence[Ranking], m: int) -> tuple[int, ...]:
"""Return the lexicographically smallest ranking with the fewest majority disagreements."""
lose, cost = _table(profile, m)
S = (1 << m) - 1 # @line L5
out = []
while S: # @line L6
for v in range(m):
if S >> v & 1:
rest = S & ~(1 << v)
if (lose[v] & rest).bit_count() + cost[rest] == cost[S]: # @line L7
break
out.append(v) # @line L8
S = rest
return tuple(out) # @line L9
def slater_winners(profile: Sequence[Ranking], m: int) -> frozenset[int]:
"""Return the candidates that are on top of some ranking with the fewest disagreements."""
lose, cost = _table(profile, m)
full = (1 << m) - 1
return frozenset(v for v in range(m)
if (lose[v] & (full & ~(1 << v))).bit_count() + cost[full & ~(1 << v)]
== cost[full])
def slater(profile: Sequence[Ranking], m: int) -> int:
"""Return the Slater winner; a tie goes to the candidate with the smallest index."""
return slater_ranking(profile, m)[0]
test_slater_rule.py 142 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/slater-rule/. The authors are listed in prov/DWARFM.jsonl.
import random
from itertools import combinations, permutations
from agtprefs import (check_anonymity, check_condorcet_consistency, check_monotonicity,
check_neutrality, check_pareto, condorcet_winner, find_manipulation,
kendall_tau, margins, prefers, random_profile)
from slater_rule import margin_matrix, slater, slater_cost, slater_ranking, slater_winners
A, B, C, D = 0, 1, 2, 3
# The worked example of the page: 13 voters in three groups.
EXAMPLE = ((D, B, C, A),) * 4 + ((B, A, D, C),) * 6 + ((C, A, D, B),) * 3
def kemeny_cost(P, r):
return sum(kendall_tau(r, v) for v in P)
def test_example():
M = margin_matrix(EXAMPLE, 4)
assert [M[B][A], M[C][A], M[A][D], M[B][C], M[D][B], M[D][C]] == [7, 1, 5, 7, 1, 7]
assert condorcet_winner(EXAMPLE, 4) is None
assert smith_set(EXAMPLE, 4) == frozenset({A, B, C, D})
best, opt = brute_force(EXAMPLE, 4)
assert best == 1 and opt == [(D, B, C, A)]
assert slater_ranking(EXAMPLE, 4) == (D, B, C, A)
assert slater_winners(EXAMPLE, 4) == frozenset({D})
assert slater(EXAMPLE, 4) == D
first = {v: min(slater_cost(EXAMPLE, 4, r) for r in permutations(range(4)) if r[0] == v)
for v in range(4)}
assert first == {A: 2, B: 2, C: 3, D: 1}
# Kemeny weighs each disagreement by its margin and picks another ranking.
k = {r: kemeny_cost(EXAMPLE, r) for r in permutations(range(4))}
kbest = min(k.values())
assert [r for r in k if k[r] == kbest] == [(B, A, D, C)]
assert slater_cost(EXAMPLE, 4, (B, A, D, C)) == 2
assert k[(D, B, C, A)] - kbest == 3
def brute_force(P, m):
M = margins(P, m)
costs = {r: sum(1 for i in range(m) for j in range(i + 1, m) if M[r[j]][r[i]] > 0)
for r in permutations(range(m))}
best = min(costs.values())
opt = sorted(r for r in costs if costs[r] == best)
return best, opt
def smith_set(P, m):
M = margins(P, m)
for size in range(1, m + 1):
for S in combinations(range(m), size):
if all(M[a][b] > 0 for a in S for b in range(m) if b not in S):
return frozenset(S)
return frozenset()
def test_matches_brute_force():
rng = random.Random(1)
for _ in range(100):
m, n = rng.randint(1, 6), rng.randint(0, 7)
P = random_profile(rng, m, n)
assert margin_matrix(P, m) == margins(P, m)
best, opt = brute_force(P, m)
r = slater_ranking(P, m)
assert r == opt[0]
assert slater_cost(P, m, r) == best
assert slater_winners(P, m) == frozenset(o[0] for o in opt)
assert slater(P, m) == r[0]
def test_edge_cases():
assert slater_ranking((), 1) == (0,)
assert slater_ranking((), 3) == (0, 1, 2)
assert slater_winners((), 3) == frozenset({0, 1, 2})
assert slater_ranking(((2, 0, 1),), 3) == (2, 0, 1)
cycle = ((A, B, C), (B, C, A), (C, A, B))
assert slater_winners(cycle, 3) == frozenset({A, B, C})
assert slater_ranking(cycle, 3) == (A, B, C)
assert slater_cost(cycle, 3, (A, B, C)) == 1
def test_smith_set_on_top():
rng = random.Random(2)
for _ in range(100):
m, n = rng.randint(2, 6), rng.randint(1, 7)
P = random_profile(rng, m, n)
S = smith_set(P, m)
_, opt = brute_force(P, m)
for r in opt:
assert frozenset(r[:len(S)]) == S
def test_axioms_on_full_domains():
for m, n in ((2, 3), (3, 1), (3, 2), (3, 3), (4, 1)):
assert check_anonymity(slater_winners, m, n) is None
assert check_neutrality(slater_winners, m, n) is None
assert check_pareto(slater_winners, m, n) is None
assert check_condorcet_consistency(slater_winners, m, n) is None
assert check_monotonicity(slater_winners, m, n) is None
def test_axioms_on_random_profiles():
for m, n, seed in ((5, 5, 3), (6, 7, 4)):
rng = random.Random(seed)
Ps = [random_profile(rng, m, n) for _ in range(15)]
assert check_anonymity(slater_winners, m, n, Ps) is None
assert check_neutrality(slater_winners, m, n, Ps) is None
assert check_pareto(slater_winners, m, n, Ps) is None
assert check_condorcet_consistency(slater_winners, m, n, Ps) is None
assert check_monotonicity(slater_winners, m, n, Ps) is None
def test_resolute_rule_is_not_neutral():
assert slater(((A, B), (B, A)), 2) == A
assert check_neutrality(slater, 2, 2) is not None
def test_manipulation_exists():
found = find_manipulation(slater, 3, 3)
assert found is not None
P, i, s = found
Q = P[:i] + (s,) + P[i + 1:]
assert prefers(P[i], slater(Q, 3), slater(P, 3))
def test_larger_input():
rng = random.Random(7)
m = 14
P = random_profile(rng, m, 9)
r = slater_ranking(P, m)
assert sorted(r) == list(range(m))
c = slater_cost(P, m, r)
for i in range(m - 1):
s = r[:i] + (r[i + 1], r[i]) + r[i + 2:]
assert slater_cost(P, m, s) >= c
w = condorcet_winner(P, m)
if w is not None:
assert r[0] == w
History
Patrick Slater posed the problem in 1961 for paired comparisons, where a judge compares every pair of items and the comparisons may be inconsistent. He asked for the ranking with the fewest inconsistencies. The rule later became one of the standard tournament solutions in social choice. The minimum feedback arc set problem in tournaments was shown to be NP-hard in the mid-2000s, which settled the complexity of the Slater ranking and of the Slater winner. Work on approximation for the same problem gave KwikSort in 2005.
References
- Patrick Slater, Inconsistencies in a schedule of paired comparisons, Biometrika 48(3-4) (1961), 303-312, the problem of finding the ranking with the fewest inconsistencies with the outcomes of paired comparisons
- Felix Brandt, Vincent Conitzer, Ulle Endriss, Jérôme Lang and Ariel D. Procaccia (eds.), Handbook of Computational Social Choice, Cambridge University Press, 2016, Chapter 3 (Felix Brandt, Markus Brill and Paul Harrenstein, Tournament solutions): the Slater set and Theorem 3.3 on its NP-hardness; the top cycle (Smith set) and Theorem 3.8
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag DWARFM Edit this page History Report an error Markdown