Documentation

CslibFrontier.Algorithms.Lean.HousingMarket.TopTradingCycles

Gale's top trading cycles #

This module implements Gale's top trading cycles algorithm (TTC) for the Shapley–Scarf housing market ([SS74], where it is credited to David Gale) as a total, decide-evaluable Lean function, and proves that its allocation is the unique allocation in the strict core ([RP77]; [SV07], Theorem 10.6, whose core is defined by weak blocking) and the unique competitive allocation.

[Rou13], Lecture 9, Theorem 3.2, states that TTC is the unique core allocation for a core defined by strict blocking (Instance.InCore). Only the existence half holds for that notion (inCore_ttc): the test module CslibFrontierTests.HousingMarket exhibits a three-agent market with a second allocation in the core, so uniqueness is stated for the strict core only.

While agents remain, every remaining agent points to the owner of its favourite remaining house, topChoice R i. Each agent has one outgoing pointer, so the pointer graph has a cycle; the agents on its cycles (cycleAgents R, the periodic points of topChoice R) receive the houses they point to and leave with their houses. ttcRounds k R runs at most k such rounds starting from the remaining agents R; every round removes at least one agent (card_sdiff_cycleAgents_lt), so n rounds suffice and ttc is ttcRounds n univ. All cycles of a round are removed together, as in [SV07], Definition 10.5; removing them one at a time yields the same allocation, which is not stated here.

ttcPrice h is the number of agents present in the round in which house h leaves. These prices decrease from round to round, every agent receives a house of the same price as its own, and at these prices TTC is a competitive allocation (isCompetitive_ttc).

Main definitions #

Main results #

Cost model #

No running time is certified: ttcRounds recomputes cycles from scratch each round and is meant for specification and kernel evaluation on small instances, not as an efficient implementation.

References #

Pointers and cycles #

Agent i's favourite house among the houses R (agent i itself when R is empty).

The agents of R on a cycle of the pointer map topChoice R: those that return to themselves after following at most n pointers.

At most k rounds of top trading cycles on the remaining agents R: each agent on a cycle of the pointer map receives the house it points to, and the rest continue with the remaining houses. Agents outside R keep their own houses.

The number of remaining agents in the round, among at most k rounds started from R, in which house h leaves (0 if it does not leave).

The TTC price of house h: the number of agents present in the round in which h leaves.

theorem Cslib.Algorithms.Lean.HousingMarket.Instance.rank_topChoice_le {n : ℕ} {I : Instance n} {R : Finset (Fin n)} {h : Fin n} (hh : h ∈ R) (i : Fin n) :
I.rank i (I.topChoice R i) ≤ I.rank i h

An agent weakly prefers its favourite house in R to every house in R.

theorem Cslib.Algorithms.Lean.HousingMarket.Instance.topChoice_eq_of_forall {n : ℕ} {I : Instance n} {R : Finset (Fin n)} {i h : Fin n} (hh : h ∈ R) (hmin : ∀ h' ∈ R, I.rank i h ≤ I.rank i h') :
I.topChoice R i = h
theorem Cslib.Algorithms.Lean.HousingMarket.Instance.topChoice_of_subset {n : ℕ} {I : Instance n} {R R' : Finset (Fin n)} (hRR' : R' ⊆ R) {i : Fin n} (hi : I.topChoice R i ∈ R') :
I.topChoice R' i = I.topChoice R i

Removing houses other than an agent's favourite does not change its favourite.

The agents removed in a round are exactly the periodic points of the pointer map.

An agent on a cycle points to an agent on a cycle.

No two agents on cycles point to the same house.

Every round removes some agent.

Rounds #

theorem Cslib.Algorithms.Lean.HousingMarket.Instance.ttcRounds_succ_of_mem {n : ℕ} {I : Instance n} {k : ℕ} {R : Finset (Fin n)} {i : Fin n} (hi : i ∈ I.cycleAgents R) :
I.ttcRounds (k + 1) R i = I.topChoice R i
theorem Cslib.Algorithms.Lean.HousingMarket.Instance.ttcRounds_succ_of_notMem {n : ℕ} {I : Instance n} {k : ℕ} {R : Finset (Fin n)} {i : Fin n} (hi : i ∉ I.cycleAgents R) :
I.ttcRounds (k + 1) R i = I.ttcRounds k (R \ I.cycleAgents R) i
theorem Cslib.Algorithms.Lean.HousingMarket.Instance.ttcRounds_of_notMem {n : ℕ} {I : Instance n} {k : ℕ} {R : Finset (Fin n)} {i : Fin n} (hi : i ∉ R) :
I.ttcRounds k R i = i

Agents that are no longer present keep their own houses.

theorem Cslib.Algorithms.Lean.HousingMarket.Instance.ttcRounds_mem {n : ℕ} {I : Instance n} {k : ℕ} {R : Finset (Fin n)} (hk : R.card ≤ k) {i : Fin n} (hi : i ∈ R) :
I.ttcRounds k R i ∈ R

The top trading cycles allocation: n rounds of TTC starting from all agents.

The strict core #

theorem Cslib.Algorithms.Lean.HousingMarket.Instance.mem_of_apply_mem {n : ℕ} {C : Finset (Fin n)} (ν : Allocation n) (hC : ∀ b ∈ C, ν b ∈ C) {a : Fin n} (ha : ν a ∈ C) :
a ∈ C

An allocation that maps a finite set C into itself maps it onto itself, so it sends no agent outside C into C.

The TTC allocation is in the strict core: no coalition weakly blocks it ([RP77]; [SV07], Theorem 10.6).

The TTC allocation is in the core ([SS74]; the existence half of [Rou13], Lecture 9, Theorem 3.2). That theorem also claims uniqueness for this strict-blocking core, which fails: see CslibFrontierTests.HousingMarket.

The TTC allocation is Pareto efficient.

The TTC allocation is the only allocation in the strict core ([RP77]; [SV07], Theorem 10.6).

The strict core consists of the TTC allocation alone. Uniqueness needs weak blocking: the core, defined by strict blocking, can contain other allocations (see the test module CslibFrontierTests.HousingMarket).

Following pointers #

theorem Cslib.Algorithms.Lean.HousingMarket.Instance.rank_ttcRounds_le_of_iterate {n : ℕ} {I : Instance n} {k : ℕ} {R : Finset (Fin n)} (hk : R.card ≤ k) {i h : Fin n} (hh : h ∈ R) {m : ℕ} (hm : (I.topChoice R)^[m] h = i) :
I.rank i (I.ttcRounds k R i) ≤ I.rank i h

An agent i reached from house h ∈ R by following pointers in R receives a house it weakly prefers to h. In particular (m = 0) TTC is individually rational on every submarket.

Competitive prices #

theorem Cslib.Algorithms.Lean.HousingMarket.Instance.ttcPriceRounds_ttcRounds {n : ℕ} {I : Instance n} {k : ℕ} {R : Finset (Fin n)} (hk : R.card ≤ k) {i : Fin n} (hi : i ∈ R) :
I.ttcPriceRounds k R (I.ttcRounds k R i) = I.ttcPriceRounds k R i

Every agent receives its house in the round in which its own house leaves.

theorem Cslib.Algorithms.Lean.HousingMarket.Instance.rank_ttcRounds_le_of_ttcPriceRounds_le {n : ℕ} {I : Instance n} {k : ℕ} {R : Finset (Fin n)} (hk : R.card ≤ k) {i h : Fin n} (hi : i ∈ R) (hh : h ∈ R) (hp : I.ttcPriceRounds k R h ≤ I.ttcPriceRounds k R i) :
I.rank i (I.ttcRounds k R i) ≤ I.rank i h

A house leaving no earlier than agent i is still available to i when i receives its house.

The TTC allocation is competitive at the TTC prices: every agent's house costs as much as its own, and it is the agent's favourite among the houses it can afford ([SS74]).

theorem Cslib.Algorithms.Lean.HousingMarket.Instance.IsCompetitive.eq_ttc {n : ℕ} {I : Instance n} {α : Type u_1} [LinearOrder α] {μ : Allocation n} {p : Fin n → α} (h : I.IsCompetitive μ p) :
μ = I.ttc

An allocation that is competitive at some prices, in any linear order, is the TTC allocation: competitive allocations are unique ([RP77]).

An allocation is competitive at some natural-number prices iff it is the TTC allocation.