Documentation

CslibFrontier.Algorithms.Lean.Simplex.Dictionary

Simplex dictionaries and pivoting #

This module sets up the dictionaries of the simplex method ([Chv83], Chapters 2 and 3) over an arbitrary field, with the order-dependent statements over a linearly ordered field (ℚ, ℝ, …), and proves that pivoting preserves the solution set, the objective, and feasibility, together with the two stopping certificates: optimality and unboundedness.

Model #

The variables are indexed by a finite linearly ordered type ι. A Dictionary ι K consists of a set basis of basic variables, and for each basic i a row expressing it through the nonbasic variables, x i = rhs i + ∑ j ∉ basis, coeff i j * x j, together with an objective row objConst + ∑ j ∉ basis, objCoeff j * x j. Entries of rhs, coeff and objCoeff outside these index ranges are ignored. IsSolution D x says that x : ι → K satisfies every row (no sign condition), and D.value x is the objective at x. The linear program described by D is to maximize D.value x over D.feasibleSet = {x | D.IsSolution x ∧ 0 ≤ x}. Two dictionaries are Equivalent when they have the same solutions and agree on the objective there.

The basic solution D.basicSolution sets the nonbasic variables to 0; D is Feasible when it is nonnegative, that is 0 ≤ rhs i for every basic i.

Source mapping #

[Chv83], Chapter 2, writes a dictionary as x_i = b_i - ∑ a_ij x_j, z = v + ∑ c_j x_j; here the sign of the coefficients is absorbed into coeff, so coeff i j = -a_ij. Pivoting on a basic r (leaving) and a nonbasic s (entering) with coeff r s ≠ 0 solves row r for x s and substitutes into the other rows and the objective (pivot); pivot sets the entries outside the new index ranges to 0. The entering variable increases along the edge D.basicSolution + t • D.ray s; the ratio test bounds t by D.ratio s r = rhs r / -coeff r s for the rows with coeff r s < 0.

Main definitions #

Main results #

References #

structure Cslib.Algorithms.Lean.Simplex.Dictionary (ι : Type u_1) (K : Type u_2) :
Type (max u_1 u_2)

A simplex dictionary ([Chv83], Chapter 2) on the variables ι: each basic variable i ∈ basis is expressed as x i = rhs i + ∑ j ∉ basis, coeff i j * x j, and the objective as objConst + ∑ j ∉ basis, objCoeff j * x j. Entries outside these index ranges are ignored.

  • basis : Finset ι

    The basic variables.

  • rhs : ι → K

    The constant term of the row of each basic variable.

  • coeff : ι → ι → K

    coeff i j is the coefficient of the nonbasic x j in the row of the basic x i.

  • objConst : K

    The constant term of the objective row: the objective value of the basic solution.

  • objCoeff : ι → K

    The reduced costs: objCoeff j is the coefficient of the nonbasic x j in the objective row.

Instances For
    theorem Cslib.Algorithms.Lean.Simplex.Dictionary.ext {ι : Type u_1} {K : Type u_2} {x y : Dictionary ι K} (basis : x.basis = y.basis) (rhs : x.rhs = y.rhs) (coeff : x.coeff = y.coeff) (objConst : x.objConst = y.objConst) (objCoeff : x.objCoeff = y.objCoeff) :
    x = y
    def Cslib.Algorithms.Lean.Simplex.Dictionary.IsSolution {ι : Type u_1} {K : Type u_2} [Field K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) (x : ι → K) :

    x satisfies every row of D. No sign condition is imposed.

    Instances For
      def Cslib.Algorithms.Lean.Simplex.Dictionary.value {ι : Type u_1} {K : Type u_2} [Field K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) (x : ι → K) :
      K

      The objective of D at x.

      Instances For
        def Cslib.Algorithms.Lean.Simplex.Dictionary.basicSolution {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) (i : ι) :
        K

        The basic solution of D: the nonbasic variables are 0, so each basic x i is rhs i.

        Instances For
          structure Cslib.Algorithms.Lean.Simplex.Dictionary.Equivalent {ι : Type u_1} {K : Type u_2} [Field K] [Fintype ι] [DecidableEq ι] (D D' : Dictionary ι K) :

          D and D' describe the same linear program: they have the same solutions, and their objectives agree on them.

          Instances For
            def Cslib.Algorithms.Lean.Simplex.Dictionary.pivot {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) (r s : ι) :

            The pivot of D on the leaving basic variable r and the entering nonbasic variable s ([Chv83], Chapter 2): row r is solved for x s, which is substituted into the other rows and into the objective. The new basis is insert s (D.basis.erase r). Entries outside the new index ranges are set to 0. The result is meaningful when r ∈ D.basis, s ∉ D.basis and D.coeff r s ≠ 0.

            Instances For
              def Cslib.Algorithms.Lean.Simplex.Dictionary.ray {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) (s i : ι) :
              K

              The edge direction of the nonbasic variable s: increasing x s by t while keeping the other nonbasic variables at 0 changes each basic x i by t * coeff i s.

              Instances For
                def Cslib.Algorithms.Lean.Simplex.Dictionary.ratio {ι : Type u_1} {K : Type u_2} [Field K] (D : Dictionary ι K) (s i : ι) :
                K

                The ratio test: when coeff i s < 0, row i stays nonnegative along the edge of s for step lengths up to rhs i / -coeff i s.

                Instances For
                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.Equivalent.symm {ι : Type u_1} {K : Type u_2} [Field K] [Fintype ι] [DecidableEq ι] {D D' : Dictionary ι K} (h : D.Equivalent D') :
                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.Equivalent.trans {ι : Type u_1} {K : Type u_2} [Field K] [Fintype ι] [DecidableEq ι] {D D' D'' : Dictionary ι K} (h : D.Equivalent D') (h' : D'.Equivalent D'') :
                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.basicSolution_of_mem {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) {i : ι} (hi : i ∈ D.basis) :
                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.basicSolution_of_notMem {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) {i : ι} (hi : i ∉ D.basis) :
                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.eq_basicSolution_of_isSolution {ι : Type u_1} {K : Type u_2} [Field K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) {x : ι → K} (hx : D.IsSolution x) (h0 : ∀ j ∉ D.basis, x j = 0) :

                  A solution vanishing off the basis is the basic solution.

                  Pivoting #

                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.pivot_basis {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) (r s : ι) :
                  (D.pivot r s).basis = insert s (D.basis.erase r)
                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.mem_pivot_basis {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) {r s i : ι} :
                  i ∈ (D.pivot r s).basis ↔ i = s ∨ i ∈ D.basis ∧ i ≠ r
                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.card_pivot_basis {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) {r s : ι} (hr : r ∈ D.basis) (hs : s ∉ D.basis) :
                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.isSolution_pivot_iff {ι : Type u_1} {K : Type u_2} [Field K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) {r s : ι} (hr : r ∈ D.basis) (hs : s ∉ D.basis) (ha : D.coeff r s ≠ 0) {x : ι → K} :

                  A pivot on a nonzero coefficient preserves the solutions.

                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.value_pivot {ι : Type u_1} {K : Type u_2} [Field K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) {r s : ι} (hr : r ∈ D.basis) (hs : s ∉ D.basis) (ha : D.coeff r s ≠ 0) {x : ι → K} (hx : D.IsSolution x) :
                  (D.pivot r s).value x = D.value x

                  A pivot on a nonzero coefficient preserves the objective on solutions.

                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.equivalent_pivot {ι : Type u_1} {K : Type u_2} [Field K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) {r s : ι} (hr : r ∈ D.basis) (hs : s ∉ D.basis) (ha : D.coeff r s ≠ 0) :
                  D.Equivalent (D.pivot r s)

                  Pivoting yields an equivalent dictionary ([Chv83], Chapter 2): a pivot on a basic r, a nonbasic s and a nonzero coefficient D.coeff r s preserves the solutions and the objective.

                  The edge direction of an entering variable #

                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.ray_self {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) (s : ι) :
                  D.ray s s = 1
                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.ray_of_mem {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) {s i : ι} (hi : i ∈ D.basis) (hs : s ∉ D.basis) :
                  D.ray s i = D.coeff i s
                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.ray_of_notMem {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) {s i : ι} (hi : i ∉ D.basis) (his : i ≠ s) :
                  D.ray s i = 0
                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.isSolution_add_smul_ray {ι : Type u_1} {K : Type u_2} [Field K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) {s : ι} (hs : s ∉ D.basis) {x : ι → K} (hx : D.IsSolution x) (t : K) :
                  D.IsSolution (x + t • D.ray s)

                  Moving a solution along the edge of a nonbasic variable keeps it a solution.

                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.value_add_smul_ray {ι : Type u_1} {K : Type u_2} [Field K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) {s : ι} (hs : s ∉ D.basis) (x : ι → K) (t : K) :
                  D.value (x + t • D.ray s) = D.value x + t * D.objCoeff s

                  Along the edge of a nonbasic s the objective changes at rate objCoeff s.

                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.basicSolution_pivot {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) [Finite ι] {r s : ι} (hr : r ∈ D.basis) (hs : s ∉ D.basis) (ha : D.coeff r s ≠ 0) :

                  The pivot on r and s moves the basic solution along the edge of s by the ratio of row r.

                  theorem Cslib.Algorithms.Lean.Simplex.Dictionary.objConst_pivot {ι : Type u_1} {K : Type u_2} [Field K] [DecidableEq ι] (D : Dictionary ι K) (r s : ι) :
                  (D.pivot r s).objConst = D.objConst + D.objCoeff s * D.ratio s r

                  The pivot on r and s changes the objective value of the basic solution by objCoeff s * ratio s r.

                  D is feasible when its basic solution is nonnegative ([Chv83], Chapter 2).

                  Instances For
                    def Cslib.Algorithms.Lean.Simplex.Dictionary.feasibleSet {ι : Type u_1} {K : Type u_2} [Field K] [LinearOrder K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) :
                    Set (ι → K)

                    The feasible set of the linear program described by D.

                    Instances For
                      theorem Cslib.Algorithms.Lean.Simplex.Dictionary.mem_feasibleSet {ι : Type u_1} {K : Type u_2} [Field K] [LinearOrder K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) {x : ι → K} :
                      theorem Cslib.Algorithms.Lean.Simplex.Dictionary.ratio_nonneg {ι : Type u_1} {K : Type u_2} [Field K] [LinearOrder K] [IsStrictOrderedRing K] (D : Dictionary ι K) (hD : D.Feasible) {s r : ι} (hr : r ∈ D.basis) (har : D.coeff r s < 0) :
                      0 ≤ D.ratio s r
                      theorem Cslib.Algorithms.Lean.Simplex.Dictionary.feasible_pivot {ι : Type u_1} {K : Type u_2} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [DecidableEq ι] (D : Dictionary ι K) [Finite ι] (hD : D.Feasible) {r s : ι} (hr : r ∈ D.basis) (hs : s ∉ D.basis) (har : D.coeff r s < 0) (hmin : ∀ i ∈ D.basis, D.coeff i s < 0 → D.ratio s r ≤ D.ratio s i) :
                      (D.pivot r s).Feasible

                      The ratio test preserves feasibility ([Chv83], Chapter 2): pivoting a feasible dictionary on a row r with coeff r s < 0 of minimal ratio yields a feasible dictionary.

                      theorem Cslib.Algorithms.Lean.Simplex.Dictionary.objConst_le_pivot {ι : Type u_1} {K : Type u_2} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [DecidableEq ι] (D : Dictionary ι K) (hD : D.Feasible) {r s : ι} (hr : r ∈ D.basis) (har : D.coeff r s < 0) (hc : 0 ≤ D.objCoeff s) :

                      A pivot on a row r with coeff r s < 0 of a feasible dictionary, entering a variable with nonnegative reduced cost, does not decrease the objective value of the basic solution.

                      theorem Cslib.Algorithms.Lean.Simplex.Dictionary.value_le_objConst {ι : Type u_1} {K : Type u_2} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) (h : ∀ j ∉ D.basis, D.objCoeff j ≤ 0) {x : ι → K} (hx : 0 ≤ x) :

                      Optimality certificate ([Chv83], Chapter 2): if no reduced cost of a feasible dictionary is positive, its basic solution is optimal, with value objConst.

                      theorem Cslib.Algorithms.Lean.Simplex.Dictionary.ray_nonneg {ι : Type u_1} {K : Type u_2} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [DecidableEq ι] (D : Dictionary ι K) {s : ι} (hs : s ∉ D.basis) (h : ∀ i ∈ D.basis, 0 ≤ D.coeff i s) :
                      0 ≤ D.ray s
                      theorem Cslib.Algorithms.Lean.Simplex.Dictionary.not_bddAbove_value {ι : Type u_1} {K : Type u_2} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [Fintype ι] [DecidableEq ι] (D : Dictionary ι K) (hD : D.Feasible) {s : ι} (hs : s ∉ D.basis) (hc : 0 < D.objCoeff s) (h : ∀ i ∈ D.basis, 0 ≤ D.coeff i s) :

                      Unboundedness certificate ([Chv83], Chapters 2–3): if a nonbasic variable of a feasible dictionary has a positive reduced cost and no row bounds its increase, the objective is unbounded on the feasible set.

                      Equivalent dictionaries describe the same linear program.