Documentation

CslibFrontier.Algorithms.Lean.Assignment.Auction

Bertsekas's auction algorithm for the assignment problem #

This module implements the Gauss–Seidel auction algorithm of [Ber79] and [Ber88] for the square, complete assignment problem with integer costs c : Fin n × Fin n → ℤ, and proves its correctness: ε-complementary slackness is invariant, the algorithm terminates within an explicit pseudo-polynomial number of bids, its output is within n * ε of optimal, and it is exactly optimal when the costs are scaled by n + 1 and ε = 1.

Algorithm #

The state (AuctionState) records the owner of each object, integer object prices, a stack of unassigned persons and a bid counter. Starting from the empty assignment and zero prices (auctionInit), each step (bidStep) lets the unassigned person i on top of the stack bid:

This is the cost form (c = -a) of [Ber98], §7.1.1, (7.2)–(7.5), with bidding set I a single unassigned person (the Gauss–Seidel version). Bertsekas sets w = -∞ (in benefit form) when the bidder has a single object; we raise the price by ε instead, which also preserves ε-complementary slackness. The loop (auctionLoop) runs until the stack is empty, with fuel bidBound n (costSpread c) ε computed from the data (auction).

Cost model and limitations #

Main definitions #

Main results #

References #

The auction algorithm #

State of the Gauss–Seidel auction: the current owner of each object (if any), object prices, the stack of unassigned persons (the next bidder first), and the number of bids so far.

  • owner : Fin n → Option (Fin n)

    owner j is the person currently assigned object j, if any.

  • price : Fin n → ℤ

    price j is the current price of object j.

  • free : List (Fin n)

    The unassigned persons; the head bids next.

  • bids : ℕ

    The number of bids made so far.

def Cslib.Algorithms.Lean.Assignment.redCost {n : ℕ} (c : Fin n × Fin n → ℤ) (p : Fin n → ℤ) (i j : Fin n) :

Reduced cost c (i, j) + p j of object j for person i at prices p.

def Cslib.Algorithms.Lean.Assignment.bestObject {n : ℕ} (c : Fin n × Fin n → ℤ) (p : Fin n → ℤ) (i : Fin n) :

A best object for person i: the first object of least reduced cost.

def Cslib.Algorithms.Lean.Assignment.secondBest {n : ℕ} (c : Fin n × Fin n → ℤ) (p : Fin n → ℤ) (i j : Fin n) :

The least reduced cost for person i among objects other than j (none if n = 1).

def Cslib.Algorithms.Lean.Assignment.bidPrice {n : ℕ} (c : Fin n × Fin n → ℤ) (ε : ℤ) (p : Fin n → ℤ) (i j : Fin n) :

The bid of person i for its best object j: the price w - c (i, j) + ε at which j's reduced cost becomes ε more than the second least reduced cost w, i.e. p j + (w - v) + ε where v is the least reduced cost ([Ber98], (7.4)); p j + ε if j is the only object.

One bid: the first unassigned person i bids for its best object j, raising its price to bidPrice; j is assigned to i and its previous owner (if any) becomes unassigned. A state with no unassigned person is fixed.

The initial state: nothing assigned, all prices 0.

Run at most fuel bids, stopping as soon as every person is assigned.

The bid bound n (C + ε) / ε + 1 for a row cost range C.

A computable bound on the row cost ranges: 2 ∑ᵢ ∑ⱼ |c (i, j)| bounds every c (i, k) - c (i, j) (sub_le_costSpread).

The auction algorithm with bidding increment ε, run for bidBound n (costSpread c) ε bids, which suffices for termination when 0 < ε (auction_free).

The object of person i in a state (i itself if i is unassigned).

The owner of object j in a state (j itself if j is unassigned).

The invariant #

structure Cslib.Algorithms.Lean.Assignment.AuctionInv {n : ℕ} (c : Fin n × Fin n → ℤ) (ε : ℤ) (s : AuctionState n) :

Invariant of the auction ([Ber98], §7.1.1): the owner table is a partial matching, the stack of unassigned persons is exact and duplicate-free, unassigned objects keep price 0, and every assigned pair satisfies ε-complementary slackness (7.1).

The initial state satisfies the invariant.

theorem Cslib.Algorithms.Lean.Assignment.le_bidPrice {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {p : Fin n → ℤ} {i j : Fin n} (hj : ∀ (k : Fin n), redCost c p i j ≤ redCost c p i k) :
p j + ε ≤ bidPrice c ε p i j

A bid raises the price of a best object by at least ε.

theorem Cslib.Algorithms.Lean.Assignment.bidPrice_epsCS {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {p : Fin n → ℤ} {i j : Fin n} (k : Fin n) (hk : k ≠ j) :
c (i, j) + bidPrice c ε p i j ≤ c (i, k) + p k + ε

After the bid, the object bid for is within ε of every other object.

theorem Cslib.Algorithms.Lean.Assignment.bidStep_nil {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} (hs : s.free = []) :
bidStep c ε s = s

A state with no unassigned person is fixed by bidStep.

theorem Cslib.Algorithms.Lean.Assignment.bidStep_cons {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} {i : Fin n} {rest : List (Fin n)} (hs : s.free = i :: rest) :
∃ (j : Fin n), (∀ (k : Fin n), redCost c s.price i j ≤ redCost c s.price i k) ∧ bidStep c ε s = { owner := Function.update s.owner j (some i), price := Function.update s.price j (bidPrice c ε s.price i j), free := (s.owner j).toList ++ rest, bids := s.bids + 1 }

Unfolding one bid of the person i on top of the stack: it bids for a best object j.

theorem Cslib.Algorithms.Lean.Assignment.AuctionInv.bidStep {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} (hε : 0 ≤ ε) (h : AuctionInv c ε s) :

A bid preserves the invariant; in particular it preserves ε-complementary slackness ([Ber98], Prop. 7.1).

theorem Cslib.Algorithms.Lean.Assignment.sum_price_bidStep {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} {i : Fin n} {rest : List (Fin n)} (hs : s.free = i :: rest) :
∑ j : Fin n, s.price j + ε ≤ ∑ j : Fin n, (bidStep c ε s).price j

A bid raises the total price by at least ε: the termination measure.

theorem Cslib.Algorithms.Lean.Assignment.bids_bidStep {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} {i : Fin n} {rest : List (Fin n)} (hs : s.free = i :: rest) :
(bidStep c ε s).bids = s.bids + 1

A bid by an unassigned person increments the bid counter.

theorem Cslib.Algorithms.Lean.Assignment.AuctionInv.exists_owner_eq_none {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} (h : AuctionInv c ε s) (hs : s.free ≠ []) :
∃ (k : Fin n), s.owner k = none

While some person is unassigned, some object is unassigned.

theorem Cslib.Algorithms.Lean.Assignment.AuctionInv.price_le {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} (h : AuctionInv c ε s) (hs : s.free ≠ []) {C : ℤ} (hC : ∀ (i j k : Fin n), c (i, k) - c (i, j) ≤ C) (hε : 0 ≤ ε) (j : Fin n) :
s.price j ≤ C + ε

While some person is unassigned, every price is at most C + ε, where C bounds the row cost ranges: the owner of an object prefers it, up to ε, to an unassigned object of price 0 (cf. [Ber98], §7.1.1, observation (a)).

theorem Cslib.Algorithms.Lean.Assignment.auctionLoop_spec {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} (hε : 0 < ε) {C : ℤ} (hC : ∀ (i j k : Fin n), c (i, k) - c (i, j) ≤ C) (fuel : ℕ) (s : AuctionState n) :
AuctionInv c ε s → ↑n * (C + ε) - ∑ j : Fin n, s.price j < ↑fuel * ε → AuctionInv c ε (auctionLoop c ε fuel s) ∧ (auctionLoop c ε fuel s).free = []

Termination by the measure n (C + ε) - ∑ j, p j, which every bid lowers by at least ε and which is nonnegative while some person is unassigned: if the measure is below fuel * ε, then fuel bids complete the assignment.

theorem Cslib.Algorithms.Lean.Assignment.auctionLoop_add {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} {fuel : ℕ} (h : (auctionLoop c ε fuel s).free = []) (m : ℕ) :
auctionLoop c ε (fuel + m) s = auctionLoop c ε fuel s

Extra fuel does not change a completed run.

theorem Cslib.Algorithms.Lean.Assignment.bids_auctionLoop_le {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} (fuel : ℕ) (s : AuctionState n) :
(auctionLoop c ε fuel s).bids ≤ s.bids + fuel

A run with fuel makes at most fuel bids.

theorem Cslib.Algorithms.Lean.Assignment.lt_bidBound_mul {n : ℕ} {ε : ℤ} (hε : 0 < ε) (C : ℤ) :
↑n * (C + ε) < ↑(bidBound n C ε) * ε

The fuel bidBound n C ε exceeds the initial measure n (C + ε) divided by ε.

theorem Cslib.Algorithms.Lean.Assignment.sub_le_costSpread {n : ℕ} {c : Fin n × Fin n → ℤ} (i j k : Fin n) :
c (i, k) - c (i, j) ≤ costSpread c

costSpread c bounds every row cost range.

theorem Cslib.Algorithms.Lean.Assignment.auctionLoop_bidBound {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} (hε : 0 < ε) {C : ℤ} (hC : ∀ (i j k : Fin n), c (i, k) - c (i, j) ≤ C) :
AuctionInv c ε (auctionLoop c ε (bidBound n C ε) (auctionInit n)) ∧ (auctionLoop c ε (bidBound n C ε) (auctionInit n)).free = []

With fuel bidBound n C ε for any bound C on the row cost ranges, the auction completes the assignment and maintains the invariant.

theorem Cslib.Algorithms.Lean.Assignment.auctionInv_auction {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} (hε : 0 < ε) :
AuctionInv c ε (auction c ε)

The final state of the auction satisfies the invariant.

theorem Cslib.Algorithms.Lean.Assignment.auction_free {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} (hε : 0 < ε) :
(auction c ε).free = []

Termination ([Ber98], Prop. 7.2): the auction ends with every person assigned.

theorem Cslib.Algorithms.Lean.Assignment.bids_auction_le {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} (hε : 0 < ε) {C : ℤ} (hC : ∀ (i j k : Fin n), c (i, k) - c (i, j) ≤ C) :
(auction c ε).bids ≤ bidBound n C ε

Bid bound: if c (i, k) - c (i, j) ≤ C for all i, j, k, the auction makes at most n (C + ε) / ε + 1 bids. This is pseudo-polynomial: it is linear in C / ε.

The output permutation #

theorem Cslib.Algorithms.Lean.Assignment.AuctionInv.owner_objectOf {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} (h : AuctionInv c ε s) (hs : s.free = []) (i : Fin n) :
s.owner (s.objectOf i) = some i

In a complete state, person i owns s.objectOf i.

theorem Cslib.Algorithms.Lean.Assignment.AuctionInv.personOf_objectOf {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} (h : AuctionInv c ε s) (hs : s.free = []) (i : Fin n) :
s.personOf (s.objectOf i) = i

In a complete state, personOf is a left inverse of objectOf.

theorem Cslib.Algorithms.Lean.Assignment.AuctionInv.objectOf_personOf {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} (h : AuctionInv c ε s) (hs : s.free = []) (j : Fin n) :
s.objectOf (s.personOf j) = j

In a complete state, personOf is a right inverse of objectOf.

def Cslib.Algorithms.Lean.Assignment.auctionPerm {n : ℕ} (c : Fin n × Fin n → ℤ) {ε : ℤ} (hε : 0 < ε) :

The assignment computed by the auction with increment ε > 0: person i is assigned object auctionPerm c hε i.

theorem Cslib.Algorithms.Lean.Assignment.isEpsCompSlack_auctionPerm {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} (hε : 0 < ε) :

The output and the final prices satisfy ε-complementary slackness.

theorem Cslib.Algorithms.Lean.Assignment.sum_auctionPerm_le {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} (hε : 0 < ε) (τ : Equiv.Perm (Fin n)) :
∑ i : Fin n, c (i, (auctionPerm c hε) i) ≤ ∑ i : Fin n, c (i, τ i) + ↑n * ε

nε-optimality of the auction ([Ber98], Prop. 7.2): the computed assignment costs at most n * ε more than every assignment.

theorem Cslib.Algorithms.Lean.Assignment.sum_auctionPerm_le_rowPotential {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} (hε : 0 < ε) :
∑ i : Fin n, c (i, (auctionPerm c hε) i) ≤ ∑ i : Fin n, rowPotential c (auction c ε).price i + ∑ j : Fin n, -(auction c ε).price j + ↑n * ε

Dual certificate: the final prices p give feasible dual potentials (rowPotential c p, -p) (rowPotential_add_neg_le) whose total is within n * ε of the cost of the computed assignment.

The exact auction: the auction on the costs scaled by n + 1, with ε = 1.

The assignment computed by the exact auction scaledAuction.

scaledAuctionPerm c reads the assignment off the final state scaledAuction c.

theorem Cslib.Algorithms.Lean.Assignment.sum_scaledAuctionPerm_le {n : ℕ} {c : Fin n × Fin n → ℤ} (τ : Equiv.Perm (Fin n)) :
∑ i : Fin n, c (i, (scaledAuctionPerm c) i) ≤ ∑ i : Fin n, c (i, τ i)

Exact optimality for integer costs ([Ber98], Prop. 7.2 with integer data and ε < 1 / n; scaling by n + 1 as in [Ber88], §3): on the costs scaled by n + 1 and with ε = 1, the auction returns a minimum-cost assignment.

theorem Cslib.Algorithms.Lean.Assignment.bids_scaledAuction_le {n : ℕ} {c : Fin n × Fin n → ℤ} {C : ℤ} (hC : ∀ (i j k : Fin n), c (i, k) - c (i, j) ≤ C) :
(scaledAuction c).bids ≤ n * ((↑n + 1) * C + 1).toNat + 1

Bid bound for the exact algorithm: if every row cost range is at most C, the exact auction scaledAuction makes at most n ((n + 1) C + 1) + 1 bids.

Price nonnegativity and shift invariance #

theorem Cslib.Algorithms.Lean.Assignment.price_nonneg_bidStep {n : ℕ} {c : Fin n × Fin n → ℤ} {ε : ℤ} {s : AuctionState n} (hε : 0 ≤ ε) (hp : ∀ (j : Fin n), 0 ≤ s.price j) (j : Fin n) :
0 ≤ (bidStep c ε s).price j

Nonnegativity of object prices is preserved by bidStep when 0 ≤ ε.

theorem Cslib.Algorithms.Lean.Assignment.bidStep_add_const {n : ℕ} (c : Fin n × Fin n → ℤ) (d ε : ℤ) (s : AuctionState n) :
bidStep (fun (e : Fin n × Fin n) => c e + d) ε s = bidStep c ε s

Shifting every cost by a constant d leaves bidStep unchanged.

theorem Cslib.Algorithms.Lean.Assignment.auctionLoop_add_const {n : ℕ} (c : Fin n × Fin n → ℤ) (d ε : ℤ) (fuel : ℕ) (s : AuctionState n) :
auctionLoop (fun (e : Fin n × Fin n) => c e + d) ε fuel s = auctionLoop c ε fuel s

Shifting every cost by a constant d leaves auctionLoop unchanged.

theorem Cslib.Algorithms.Lean.Assignment.auction_add_const {n : ℕ} (c : Fin n × Fin n → ℤ) (d : ℤ) {ε : ℤ} (hε : 0 < ε) :
auction (fun (e : Fin n × Fin n) => c e + d) ε = auction c ε

Shifting every cost by a constant d leaves the completed state auction unchanged.

theorem Cslib.Algorithms.Lean.Assignment.auctionPerm_add_const {n : ℕ} (c : Fin n × Fin n → ℤ) (d : ℤ) {ε : ℤ} (hε : 0 < ε) :
auctionPerm (fun (e : Fin n × Fin n) => c e + d) hε = auctionPerm c hε

Shifting every cost by a constant d leaves auctionPerm unchanged.