Documentation

CslibFrontier.Algorithms.Lean.Simplex.LinearProgram

The simplex method for linear programs in matrix form #

This module connects the simplex method on dictionaries (CslibFrontier.Algorithms.Lean.Simplex.Bland) with linear programs given by matrices over a linearly ordered field, and reads off an optimal dual solution from the final dictionary.

Model #

A dictionary D on variables ι represents the program max c ⬝ᵥ x subject to x ≥ 0, A *ᵥ x = b (the equational form of [MG07]) when the solutions of D are the solutions of A *ᵥ x = b and its objective agrees with c ⬝ᵥ x on them (Represents). Representation is invariant under equivalence of dictionaries, hence under pivoting.

For the program max c ⬝ᵥ x subject to x ≥ 0, A *ᵥ x ≤ b with A : Matrix (Fin m) (Fin n) K, the slack dictionary (slackDictionary, [Chv83], Chapter 2) has the variables Fin (n + m): the original variables Fin.castAdd m j and one slack variable Fin.natAdd n i per row, initially basic with x (natAdd n i) = b i - ∑ j, A i j * x (castAdd m j). It represents the equational form with the matrix [A | 1] (slackMatrix), and it is feasible when b ≥ 0. The feasible sets are written {x | 0 ≤ x ∧ A *ᵥ x ≤ b} and {y | 0 ≤ y ∧ c ≤ y ᵥ* A}, as in Matrix.exists_isGreatest_isLeast_dotProduct_of_nonneg.

Main definitions #

Main results #

Limitations #

Only programs with a feasible starting dictionary are covered: for A *ᵥ x ≤ b, x ≥ 0 this is the hypothesis b ≥ 0. Phase I is not formalized. Strong duality itself is already in CslibFrontier.Foundations.LinearAlgebra.Matrix.LinearProgramming, whose weak duality is used here; the dual solution slackDual is the explicit by-product of the simplex method.

References #

structure Cslib.Algorithms.Lean.Simplex.Dictionary.Represents {ι : Type u_1} {K : Type u_2} [Fintype ι] [DecidableEq ι] [Field K] {m : Type u_3} [Fintype m] (D : Dictionary ι K) (A : Matrix m ι K) (b : m → K) (c : ι → K) :

The dictionary D represents the linear program max c ⬝ᵥ x subject to x ≥ 0, A *ᵥ x = b: its solutions are exactly the solutions of A *ᵥ x = b, and its objective agrees with c ⬝ᵥ x on them.

Instances For
    theorem Cslib.Algorithms.Lean.Simplex.Dictionary.Represents.of_equivalent {ι : Type u_1} {K : Type u_2} [Fintype ι] [DecidableEq ι] [Field K] {m : Type u_3} [Fintype m] {D D' : Dictionary ι K} {A : Matrix m ι K} {b : m → K} {c : ι → K} (h : D.Represents A b c) (hD : D.Equivalent D') :
    D'.Represents A b c
    theorem Cslib.Algorithms.Lean.Simplex.Dictionary.Represents.mulVec_basicSolution {ι : Type u_1} {K : Type u_2} [Fintype ι] [DecidableEq ι] [Field K] {m : Type u_3} [Fintype m] {D : Dictionary ι K} {A : Matrix m ι K} {b : m → K} {c : ι → K} (h : D.Represents A b c) :
    theorem Cslib.Algorithms.Lean.Simplex.Dictionary.Represents.eq_zero_of_mulVec_eq_zero {ι : Type u_1} {K : Type u_2} [Fintype ι] [DecidableEq ι] [Field K] {m : Type u_3} [Fintype m] {D : Dictionary ι K} {A : Matrix m ι K} {b : m → K} {c : ι → K} (h : D.Represents A b c) {w : ι → K} (hw : ∀ j ∉ D.basis, w j = 0) (hAw : A.mulVec w = 0) :
    w = 0

    The basic columns of A are linearly independent: no nonzero vector of the kernel of A is supported on the basis of a representing dictionary, so the basic solution of the dictionary is a basic solution of A *ᵥ x = b.

    theorem Cslib.Algorithms.Lean.Simplex.Dictionary.Represents.feasibleSet_eq {ι : Type u_1} {K : Type u_2} [Fintype ι] [DecidableEq ι] [Field K] {m : Type u_3} [Fintype m] {D : Dictionary ι K} {A : Matrix m ι K} {b : m → K} {c : ι → K} [LinearOrder K] (h : D.Represents A b c) :
    D.feasibleSet = {x : ι → K | 0 ≤ x ∧ A.mulVec x = b}
    theorem Cslib.Algorithms.Lean.Simplex.Dictionary.Represents.image_value_feasibleSet {ι : Type u_1} {K : Type u_2} [Fintype ι] [DecidableEq ι] [Field K] {m : Type u_3} [Fintype m] {D : Dictionary ι K} {A : Matrix m ι K} {b : m → K} {c : ι → K} [LinearOrder K] (h : D.Represents A b c) :
    D.value '' D.feasibleSet = (fun (x : ι → K) => c ⬝ᵥ x) '' {x : ι → K | 0 ≤ x ∧ A.mulVec x = b}
    theorem Cslib.Algorithms.Lean.Simplex.Dictionary.simplex_spec_of_represents {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] [IsStrictOrderedRing K] {m : Type u_3} [Fintype m] {D : Dictionary ι K} {A : Matrix m ι K} {b : m → K} {c : ι → K} (h : D.Represents A b c) (hD : D.Feasible) :
    (∃ (D' : Dictionary ι K), D.simplex = Outcome.optimal D' ∧ D'.Represents A b c ∧ D'.Feasible ∧ A.mulVec D'.basicSolution = b ∧ 0 ≤ D'.basicSolution ∧ IsGreatest ((fun (x : ι → K) => c ⬝ᵥ x) '' {x : ι → K | 0 ≤ x ∧ A.mulVec x = b}) (c ⬝ᵥ D'.basicSolution)) ∨ (∃ (D' : Dictionary ι K) (s : ι), D.simplex = Outcome.unbounded D' s) ∧ ¬BddAbove ((fun (x : ι → K) => c ⬝ᵥ x) '' {x : ι → K | 0 ≤ x ∧ A.mulVec x = b})

    The simplex method with Bland's rule for max c ⬝ᵥ x subject to x ≥ 0, A *ᵥ x = b, started from a feasible dictionary D representing the program: it returns a dictionary D' representing the same program whose basic solution is an optimal basic feasible solution, or it proves the objective unbounded on the feasible set.

    The slack dictionary of max c ⬝ᵥ x subject to x ≥ 0, A *ᵥ x ≤ b #

    def Cslib.Algorithms.Lean.Simplex.slackDictionary {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) :
    Dictionary (Fin (n + m)) K

    The slack dictionary of max c ⬝ᵥ x subject to x ≥ 0, A *ᵥ x ≤ b ([Chv83], Chapter 2): the variables are Fin (n + m), with the original variable j at Fin.castAdd m j and the slack variable of row i at Fin.natAdd n i; the slack variables are basic, with x (natAdd n i) = b i - ∑ j, A i j * x (castAdd m j), and the objective is ∑ j, c j * x (castAdd m j).

    Instances For
      def Cslib.Algorithms.Lean.Simplex.slackMatrix {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) :
      Matrix (Fin m) (Fin (n + m)) K

      The constraint matrix [A | 1] of the equational form of A *ᵥ x ≤ b.

      Instances For
        def Cslib.Algorithms.Lean.Simplex.withSlack {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (x : Fin n → K) :
        Fin (n + m) → K

        The point x extended by its slacks b - A *ᵥ x.

        Instances For
          theorem Cslib.Algorithms.Lean.Simplex.mem_slackDictionary_basis {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) {i : Fin (n + m)} :
          i ∈ (slackDictionary A b c).basis ↔ n ≤ ↑i
          theorem Cslib.Algorithms.Lean.Simplex.castAdd_notMem_slackDictionary_basis {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) (j : Fin n) :
          theorem Cslib.Algorithms.Lean.Simplex.natAdd_mem_slackDictionary_basis {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) (i : Fin m) :
          theorem Cslib.Algorithms.Lean.Simplex.isSolution_slackDictionary_iff {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) {x : Fin (n + m) → K} :
          (slackDictionary A b c).IsSolution x ↔ ∀ (i : Fin m), x (Fin.natAdd n i) = b i - ∑ j : Fin n, A i j * x (Fin.castAdd m j)
          theorem Cslib.Algorithms.Lean.Simplex.slackMatrix_mulVec {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (x : Fin (n + m) → K) (i : Fin m) :
          (slackMatrix A).mulVec x i = ∑ j : Fin n, A i j * x (Fin.castAdd m j) + x (Fin.natAdd n i)
          theorem Cslib.Algorithms.Lean.Simplex.slackDictionary_represents {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) :

          The slack dictionary represents the equational form [A | 1] *ᵥ z = b, z ≥ 0 of A *ᵥ x ≤ b, x ≥ 0, with the objective c extended by zeros.

          theorem Cslib.Algorithms.Lean.Simplex.feasible_slackDictionary_iff {K : Type u_1} [Field K] [LinearOrder K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) :

          The slack dictionary is feasible exactly when b ≥ 0.

          theorem Cslib.Algorithms.Lean.Simplex.withSlack_castAdd {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (x : Fin n → K) (j : Fin n) :
          withSlack A b x (Fin.castAdd m j) = x j
          theorem Cslib.Algorithms.Lean.Simplex.withSlack_natAdd {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (x : Fin n → K) (i : Fin m) :
          withSlack A b x (Fin.natAdd n i) = b i - A.mulVec x i
          theorem Cslib.Algorithms.Lean.Simplex.isSolution_withSlack {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c x : Fin n → K) :
          theorem Cslib.Algorithms.Lean.Simplex.eq_withSlack_of_isSolution {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) {z : Fin (n + m) → K} (hz : (slackDictionary A b c).IsSolution z) :
          z = withSlack A b fun (j : Fin n) => z (Fin.castAdd m j)

          Every solution of the slack dictionary is a point extended by its slacks.

          theorem Cslib.Algorithms.Lean.Simplex.withSlack_mem_feasibleSet_iff {K : Type u_1} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c x : Fin n → K) :
          theorem Cslib.Algorithms.Lean.Simplex.value_withSlack {K : Type u_1} [Field K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c x : Fin n → K) :
          (slackDictionary A b c).value (withSlack A b x) = c ⬝ᵥ x
          theorem Cslib.Algorithms.Lean.Simplex.image_value_slackDictionary {K : Type u_1} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) :
          (slackDictionary A b c).value '' (slackDictionary A b c).feasibleSet = (fun (x : Fin n → K) => c ⬝ᵥ x) '' {x : Fin n → K | 0 ≤ x ∧ A.mulVec x ≤ b}

          The slack dictionary describes the program max c ⬝ᵥ x subject to x ≥ 0, A *ᵥ x ≤ b.

          theorem Cslib.Algorithms.Lean.Simplex.simplex_slackDictionary_spec {K : Type u_1} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) (hb : 0 ≤ b) :
          (∃ (D : Dictionary (Fin (n + m)) K), (slackDictionary A b c).simplex = Outcome.optimal D ∧ IsGreatest ((fun (x : Fin n → K) => c ⬝ᵥ x) '' {x : Fin n → K | 0 ≤ x ∧ A.mulVec x ≤ b}) D.objConst ∧ (0 ≤ fun (j : Fin n) => D.basicSolution (Fin.castAdd m j)) ∧ (A.mulVec fun (j : Fin n) => D.basicSolution (Fin.castAdd m j)) ≤ b ∧ (c ⬝ᵥ fun (j : Fin n) => D.basicSolution (Fin.castAdd m j)) = D.objConst) ∨ (∃ (D : Dictionary (Fin (n + m)) K) (s : Fin (n + m)), (slackDictionary A b c).simplex = Outcome.unbounded D s) ∧ ¬BddAbove ((fun (x : Fin n → K) => c ⬝ᵥ x) '' {x : Fin n → K | 0 ≤ x ∧ A.mulVec x ≤ b})

          The simplex method with Bland's rule for max c ⬝ᵥ x subject to x ≥ 0, A *ᵥ x ≤ b with b ≥ 0, started from the slack dictionary: it finds an optimal solution, read off the first n coordinates of the final basic solution, or proves the objective unbounded.

          def Cslib.Algorithms.Lean.Simplex.Dictionary.slackDual {K : Type u_1} [Field K] {m n : ℕ} (D : Dictionary (Fin (n + m)) K) (i : Fin m) :
          K

          The dual solution read off a dictionary on the variables of a slack dictionary: the negated reduced cost of the slack variable of each row, and 0 when that slack variable is basic. For the final dictionary of the simplex method on slackDictionary A b c this is an optimal solution of the dual program (isLeast_dotProduct_slackDual).

          Instances For
            theorem Cslib.Algorithms.Lean.Simplex.slackDual_nonneg {K : Type u_1} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) (hb : 0 ≤ b) {D : Dictionary (Fin (n + m)) K} (h : (slackDictionary A b c).simplex = Outcome.optimal D) :

            The dual solution read off the final dictionary is nonnegative ([Chv83], Chapter 5): the reduced costs of the final dictionary are nonpositive.

            theorem Cslib.Algorithms.Lean.Simplex.le_slackDual_vecMul {K : Type u_1} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) (hb : 0 ≤ b) {D : Dictionary (Fin (n + m)) K} (h : (slackDictionary A b c).simplex = Outcome.optimal D) :

            The dual solution read off the final dictionary satisfies the dual constraints c ≤ y ᵥ* A ([Chv83], Chapter 5).

            theorem Cslib.Algorithms.Lean.Simplex.slackDual_dotProduct {K : Type u_1} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) (hb : 0 ≤ b) {D : Dictionary (Fin (n + m)) K} (h : (slackDictionary A b c).simplex = Outcome.optimal D) :

            The dual solution read off the final dictionary has value D.objConst, the primal optimum ([Chv83], Chapter 5).

            theorem Cslib.Algorithms.Lean.Simplex.isLeast_dotProduct_slackDual {K : Type u_1} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {m n : ℕ} (A : Matrix (Fin m) (Fin n) K) (b : Fin m → K) (c : Fin n → K) (hb : 0 ≤ b) {D : Dictionary (Fin (n + m)) K} (h : (slackDictionary A b c).simplex = Outcome.optimal D) :
            D.slackDual ∈ {y : Fin m → K | 0 ≤ y ∧ c ≤ Matrix.vecMul y A} ∧ IsLeast ((fun (x : Fin m → K) => x ⬝ᵥ b) '' {y : Fin m → K | 0 ≤ y ∧ c ≤ Matrix.vecMul y A}) D.objConst

            The final dictionary certifies dual optimality ([Chv83], Chapter 5). When the simplex method on the slack dictionary stops at an optimal dictionary D, D.slackDual is a feasible solution of the dual program min y ⬝ᵥ b subject to y ≥ 0, c ≤ y ᵥ* A, and D.objConst is the least dual value: by weak duality (Matrix.dotProduct_le_dotProduct_of_nonneg_of_mulVec_le) no dual solution is below the primal optimum D.objConst, which D.slackDual attains.