Nonmetric k-median
Abbreviationk-median instances#✓fully proved
A k-median instance is a triple \((d, K, B)\) of a cost matrix \(d\), given as a list of rows of natural numbers (one row per client, one entry per location; the rows need not have equal length), a natural number \(K\) bounding the number of open locations, and a natural-number budget \(B\).
Used by 3
DefinitionWell-formed k-median instances#✓fully proved
A k-median instance \((d, K, B)\) is well formed when all rows of its cost matrix \(d\) have the same length.
def WellFormed (i : KMedianInstance) : Prop :=
∀ row ∈ i.1, ∀ row' ∈ i.1, row.length = row'.length
abbrev KMedianInstance := List (List ℕ) × ℕ × ℕ
WantedExt/Complexity/NPComplete/KMedianWanted.lean:52
Uses 1 · Used by 1
DefinitionFeasible k-median instances#✓fully proved
Let \((d, K, B)\) be a k-median instance whose cost matrix \(d\) has rows \(d_0, \dots, d_{n-1}\), one per client, and let \(m\) be the length of \(d_0\), or \(m = 0\) when \(n = 0\). The instance is feasible when there are a set \(S \subseteq \{0, \dots, m-1\}\) of at most \(K\) locations and a choice of \(a(c) \in S\) for each client \(c < n\) such that \(\sum_{c < n} d_c(a(c)) \le B\), where \(d_c(j)\) is the entry of \(d_c\) at index \(j\) (counting from \(0\)), read as \(0\) when \(d_c\) has fewer than \(j + 1\) entries.
def KMedianFeasible
(i : KMedianInstance) : Prop :=
∃ facilities : List ℕ, facilities.Nodup ∧ facilities.length ≤ i.2.1 ∧
(∀ f ∈ facilities, f < (i.1.getD 0 []).length) ∧
∃ assign : List ℕ, assign.length = i.1.length ∧
(∀ c < i.1.length, assign.getD c 0 ∈ facilities) ∧
(Finset.range i.1.length).sum
(fun c => (i.1.getD c []).getD (assign.getD c 0) 0) ≤ i.2.2
abbrev KMedianInstance := List (List ℕ) × ℕ × ℕ
WantedExt/Complexity/NPComplete/KMedianWanted.lean:52
Uses 1 · Used by 1
DefinitionThe k-MEDIAN decision problem#✓fully proved
The k-MEDIAN decision problem. k-MEDIAN (generalized, nonmetric) is the decision problem that accepts a bitstring \(x\) exactly when \(x\) decodes, under the canonical bitstring encoding, to a k-median instance \((d, K, B)\) that is well formed and feasible. That is, \(d\) has rows \(d_0, \dots, d_{n-1}\) (the clients) of a common length \(m\) (the locations), and there are a set \(S \subseteq \{0, \dots, m-1\}\) of at most \(K\) locations and a choice of \(a(c) \in S\) for each client \(c < n\) with \(\sum_{c < n} d_{c, a(c)} \le B\). Bitstrings that do not decode are rejected.
noncomputable def kMedianDec :
MetaMathlibExt.ComplexityTheory.DecisionProblem := fun x =>
match MetaMathlibExt.BitstringEncoding.bitDecode
(α := KMedianInstance) x with
| some i => decide (WellFormed i ∧ KMedianFeasible i)
| none => false
abbrev DecisionProblem := List Bool → Bool
MathlibExt/Computability/Complexity.lean:170
def bitDecode [BitstringEncoding α] (l : List Bool) : Option α := toEncoding.decode l
MathlibExt/Computability/Complexity.lean:58
abbrev KMedianInstance := List (List ℕ) × ℕ × ℕ
WantedExt/Complexity/NPComplete/KMedianWanted.lean:52
def WellFormed (i : KMedianInstance) : Prop :=
∀ row ∈ i.1, ∀ row' ∈ i.1, row.length = row'.length
WantedExt/Complexity/NPComplete/KMedianWanted.lean:55
def KMedianFeasible
(i : KMedianInstance) : Prop :=
∃ facilities : List ℕ, facilities.Nodup ∧ facilities.length ≤ i.2.1 ∧
(∀ f ∈ facilities, f < (i.1.getD 0 []).length) ∧
∃ assign : List ℕ, assign.length = i.1.length ∧
(∀ c < i.1.length, assign.getD c 0 ∈ facilities) ∧
(Finset.range i.1.length).sum
(fun c => (i.1.getD c []).getD (assign.getD c 0) 0) ≤ i.2.2
WantedExt/Complexity/NPComplete/KMedianWanted.lean:59
Uses 12 · Used by 1
Theoremk-MEDIAN (GENERALIZED, NONMETRIC) is NP-complete#●ready to prove
The k-MEDIAN decision problem is in NP, and every decision problem in NP has a polynomial-time many-one reduction to it.
public theorem_wanted kMedian_npComplete :
kMedianDec ∈ MetaMathlibExt.ComplexityTheory.NP ∧
∀ L : MetaMathlibExt.ComplexityTheory.DecisionProblem,
L ∈ MetaMathlibExt.ComplexityTheory.NP →
Cslib.CookLevin.PolyManyOneRed L kMedianDec
noncomputable def kMedianDec :
MetaMathlibExt.ComplexityTheory.DecisionProblem := fun x =>
match MetaMathlibExt.BitstringEncoding.bitDecode
(α := KMedianInstance) x with
| some i => decide (WellFormed i ∧ KMedianFeasible i)
| none => false
WantedExt/Complexity/NPComplete/KMedianWanted.lean:70
def NP : DecisionComplexityClass :=
{ L | ∃ (p : Polynomial ℕ), ∃ R : (List Bool × List Bool) → Bool,
IsPolyTime R ∧
∀ x, L x ↔ ∃ w : List Bool, w.length ≤ p.eval x.length ∧ R (x, w) }
MathlibExt/Computability/Complexity.lean:200
abbrev DecisionProblem := List Bool → Bool
MathlibExt/Computability/Complexity.lean:170
def PolyManyOneRed (L₁ L₂ : MetaMathlibExt.ComplexityTheory.DecisionProblem) : Prop :=
∃ reduce : List Bool → List Bool,
MetaMathlibExt.ComplexityTheory.IsPolyTime reduce ∧ ∀ x, L₁ x = L₂ (reduce x)
CSLibExt/Computability/CookLevin.lean:396
Sources
- O. Kariv and S. L. Hakimi, "An algorithmic approach to network location problems. II: The p-medians", SIAM Journal on Applied Mathematics 37 (1979), 539-560.
Uses 5
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.