Documentation

CslibFrontier.Algorithms.Lean.Simplex.Bland

The simplex method with Bland's rule #

This module formalizes Bland's smallest-subscript pivoting rule ([Bla77]; [Chv83], Chapter 3) for the simplex method on the dictionaries of CslibFrontier.Algorithms.Lean.Simplex.Dictionary, proves that it never cycles, and derives termination and correctness of the simplex method started from a feasible dictionary.

Algorithm #

In a dictionary D (blandStep):

runWith step D fuel iterates at most fuel pivots of a pivoting rule step. Its soundness (runWith_eq_optimal, runWith_eq_unbounded) is proved once, from what the rule promises when it stops and when it pivots. run D fuel is runWith with Bland's rule, and simplex D runs with fuel (Fintype.card ι).choose #D.basis - 1.

Source mapping #

The rule is Bland's smallest-subscript rule ([Bla77]; [Chv83], Chapter 3), with variables ordered by the linear order on ι. basis_ne_of_blandPivot is the theorem that the rule does not cycle: along any sequence of Bland pivots from a feasible dictionary, no basis repeats. The proof is the standard argument: in a cycle every pivot is degenerate, so all dictionaries of the cycle share one basic solution and one objective value; let t be the largest variable that is basic in some dictionary of the cycle and nonbasic in another, E p a dictionary where t leaves with s entering, and E q one where t enters. Evaluating the objective rows of E p and E q along the edge of s in E p, where they agree because the two dictionaries are equivalent, produces a variable v < t that ties with t in the ratio test of E p, contradicting the choice of t as the leaving variable. Since pivots preserve the number of basic variables, at most N.choose m bases occur, where N = Fintype.card ι and m = #D.basis (add_one_le_choose_of_blandPivot).

Main definitions #

Main results #

Limitations #

A feasible starting dictionary is assumed; Phase I (finding one, or detecting infeasibility) is not formalized. The method is a pure Lean function over an exact field; no machine-level running time or bit complexity is certified.

References #

The smallest element of a finite set, if any. This is Mathlib's Finset.min with the result in Option ι rather than WithTop ι; the simplex step matches on it directly, and the worked examples evaluate it with decide +kernel.

Instances For
    theorem Cslib.Algorithms.Lean.Simplex.minOpt_eq_some_iff {ι : Type u_1} [LinearOrder ι] {s : Finset ι} {a : ι} :
    minOpt s = some a ↔ a ∈ s ∧ ∀ b ∈ s, a ≤ b
    inductive Cslib.Algorithms.Lean.Simplex.Step (ι : Type u_1) :
    Type u_1

    The decision of one simplex step: stop at an optimal dictionary, stop because the entering variable s has no leaving row, or pivot on the leaving r and the entering s.

    Instances For
      inductive Cslib.Algorithms.Lean.Simplex.Outcome (ι : Type u_1) (K : Type u_2) :
      Type (max u_1 u_2)

      The result of a run of the simplex method: an optimal dictionary, a dictionary with an unbounded entering variable s, or the dictionary reached when the fuel ran out.

      Instances For

        The simplex method with a pivoting rule #

        def Cslib.Algorithms.Lean.Simplex.Dictionary.runWith {ι : Type u_1} {K : Type u_2} [LinearOrder ι] [Field K] (step : Dictionary ι K → Step ι) :
        Dictionary ι K → ℕ → Outcome ι K

        The simplex method with the pivoting rule step and at most fuel pivots: stop when step says so, otherwise pivot as it says.

        Instances For
          theorem Cslib.Algorithms.Lean.Simplex.Dictionary.exists_pivot_of_runWith_eq_outOfFuel {ι : Type u_1} {K : Type u_2} [LinearOrder ι] [Field K] (D : Dictionary ι K) {step : Dictionary ι K → Step ι} {fuel : ℕ} {D' : Dictionary ι K} (h : runWith step D fuel = Outcome.outOfFuel D') :
          ∃ (E : ℕ → Dictionary ι K), E 0 = D ∧ ∀ k < fuel + 1, ∃ (r : ι) (s : ι), step (E k) = Step.pivot r s ∧ E (k + 1) = (E k).pivot r s

          A run that runs out of fuel fuel makes fuel + 1 pivots of its rule.

          theorem Cslib.Algorithms.Lean.Simplex.Dictionary.runWith_eq_optimal {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] (D : Dictionary ι K) {step : Dictionary ι K → Step ι} (hopt : ∀ (D : Dictionary ι K), step D = Step.optimal → ∀ j ∉ D.basis, D.objCoeff j ≤ 0) (hpivot : ∀ (D : Dictionary ι K) {r s : ι}, D.Feasible → step D = Step.pivot r s → D.Equivalent (D.pivot r s) ∧ (D.pivot r s).Feasible ∧ D.objConst ≤ (D.pivot r s).objConst) {fuel : ℕ} {D' : Dictionary ι K} (hD : D.Feasible) (h : runWith step D fuel = Outcome.optimal D') :
          D.Equivalent D' ∧ D'.Feasible ∧ D.objConst ≤ D'.objConst ∧ ∀ j ∉ D'.basis, D'.objCoeff j ≤ 0

          Soundness of a pivoting rule, optimal case. If the rule stops only at dictionaries with no positive reduced cost, and its pivots from a feasible dictionary give an equivalent feasible dictionary with no smaller objective value, then a run that stops at an optimal dictionary D' returns an equivalent feasible dictionary with no positive reduced cost and an objective value at least that of D.

          theorem Cslib.Algorithms.Lean.Simplex.Dictionary.runWith_eq_unbounded {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] (D : Dictionary ι K) {step : Dictionary ι K → Step ι} (hunb : ∀ (D : Dictionary ι K) {s : ι}, step D = Step.unbounded s → s ∉ D.basis ∧ 0 < D.objCoeff s ∧ ∀ i ∈ D.basis, 0 ≤ D.coeff i s) (hpivot : ∀ (D : Dictionary ι K) {r s : ι}, D.Feasible → step D = Step.pivot r s → D.Equivalent (D.pivot r s) ∧ (D.pivot r s).Feasible) {fuel : ℕ} {D' : Dictionary ι K} {s : ι} (hD : D.Feasible) (h : runWith step D fuel = Outcome.unbounded D' s) :
          D.Equivalent D' ∧ D'.Feasible ∧ s ∉ D'.basis ∧ 0 < D'.objCoeff s ∧ ∀ i ∈ D'.basis, 0 ≤ D'.coeff i s

          Soundness of a pivoting rule, unbounded case. If the rule reports an unbounded entering variable s only when s is nonbasic with a positive reduced cost and no row bounds its increase, and its pivots from a feasible dictionary give an equivalent feasible dictionary, then a run that stops with an unbounded entering variable s returns an equivalent feasible dictionary in which this holds.

          Bland's rule #

          The nonbasic variables with a positive reduced cost.

          Instances For

            The basic variables whose rows decrease along the edge of s.

            Instances For

              The leaving candidates of minimal ratio.

              Instances For

                Bland's entering rule ([Bla77]): the smallest nonbasic variable with a positive reduced cost.

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

                  Bland's leaving rule ([Bla77]): among the rows passing the ratio test for the entering variable s, the smallest basic variable.

                  Instances For

                    One step of the simplex method with Bland's rule.

                    Instances For
                      theorem Cslib.Algorithms.Lean.Simplex.Dictionary.blandEntering_eq_some_iff {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] (D : Dictionary ι K) {s : ι} :
                      D.blandEntering = some s ↔ s ∉ D.basis ∧ 0 < D.objCoeff s ∧ ∀ j ∉ D.basis, 0 < D.objCoeff j → s ≤ j
                      theorem Cslib.Algorithms.Lean.Simplex.Dictionary.blandLeaving_eq_none_iff {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] (D : Dictionary ι K) {s : ι} :
                      D.blandLeaving s = none ↔ ∀ i ∈ D.basis, 0 ≤ D.coeff i s
                      theorem Cslib.Algorithms.Lean.Simplex.Dictionary.blandLeaving_eq_some_iff {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] (D : Dictionary ι K) {s r : ι} :
                      D.blandLeaving s = some r ↔ r ∈ D.basis ∧ D.coeff r s < 0 ∧ (∀ i ∈ D.basis, D.coeff i s < 0 → D.ratio s r ≤ D.ratio s i) ∧ ∀ i ∈ D.basis, D.coeff i s < 0 → D.ratio s i = D.ratio s r → r ≤ i

                      D' arises from D by one pivot of Bland's rule.

                      Instances For
                        theorem Cslib.Algorithms.Lean.Simplex.Dictionary.basis_ne_of_blandPivot {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] [IsStrictOrderedRing K] {E : ℕ → Dictionary ι K} {n : ℕ} (hE0 : (E 0).Feasible) (hE : ∀ k < n, (E k).BlandPivot (E (k + 1))) {i j : ℕ} (hij : i < j) (hjn : j ≤ n) :
                        (E i).basis ≠ (E j).basis

                        Bland's rule does not cycle ([Bla77]; [Chv83], Chapter 3): along any sequence of Bland pivots from a feasible dictionary, no basis repeats.

                        theorem Cslib.Algorithms.Lean.Simplex.Dictionary.add_one_le_choose_of_blandPivot {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] [IsStrictOrderedRing K] {E : ℕ → Dictionary ι K} {n : ℕ} (hE0 : (E 0).Feasible) (hE : ∀ k < n, (E k).BlandPivot (E (k + 1))) :

                        At most N.choose m - 1 Bland pivots: along a sequence of n Bland pivots from a feasible dictionary with m basic variables among N variables, n + 1 ≤ N.choose m.

                        The simplex method with Bland's rule #

                        def Cslib.Algorithms.Lean.Simplex.Dictionary.run {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] :
                        Dictionary ι K → ℕ → Outcome ι K

                        The simplex method with Bland's rule and at most fuel pivots.

                        Instances For

                          The simplex method with Bland's rule ([Bla77]; [Chv83], Chapter 3), with the fuel N.choose m - 1 that suffices from a feasible dictionary (simplex_ne_outOfFuel).

                          Instances For
                            theorem Cslib.Algorithms.Lean.Simplex.Dictionary.exists_blandPivot_of_run_eq_outOfFuel {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] (D : Dictionary ι K) {fuel : ℕ} {D' : Dictionary ι K} (h : D.run fuel = Outcome.outOfFuel D') :
                            ∃ (E : ℕ → Dictionary ι K), E 0 = D ∧ ∀ k < fuel + 1, (E k).BlandPivot (E (k + 1))
                            theorem Cslib.Algorithms.Lean.Simplex.Dictionary.run_ne_outOfFuel {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] [IsStrictOrderedRing K] (D : Dictionary ι K) (hD : D.Feasible) {fuel : ℕ} (hfuel : (Fintype.card ι).choose D.basis.card ≤ fuel + 1) (D' : Dictionary ι K) :

                            Termination of Bland's rule: from a feasible dictionary, N.choose m - 1 pivots of fuel suffice.

                            A pivot of Bland's rule preserves feasibility, equivalence and does not decrease the objective.

                            theorem Cslib.Algorithms.Lean.Simplex.Dictionary.blandStep_eq_unbounded_spec {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] (D : Dictionary ι K) {s : ι} (h : D.blandStep = Step.unbounded s) :
                            s ∉ D.basis ∧ 0 < D.objCoeff s ∧ ∀ i ∈ D.basis, 0 ≤ D.coeff i s

                            Bland's rule reports an unbounded entering variable s only when s is nonbasic with a positive reduced cost and no row bounds its increase.

                            theorem Cslib.Algorithms.Lean.Simplex.Dictionary.run_eq_optimal {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] [IsStrictOrderedRing K] (D : Dictionary ι K) {fuel : ℕ} {D' : Dictionary ι K} (hD : D.Feasible) (h : D.run fuel = Outcome.optimal D') :
                            D.Equivalent D' ∧ D'.Feasible ∧ D.objConst ≤ D'.objConst ∧ ∀ j ∉ D'.basis, D'.objCoeff j ≤ 0

                            A run that stops at an optimal dictionary D' returns an equivalent feasible dictionary with no positive reduced cost and an objective value at least that of D.

                            theorem Cslib.Algorithms.Lean.Simplex.Dictionary.run_eq_unbounded {ι : Type u_1} {K : Type u_2} [Fintype ι] [LinearOrder ι] [Field K] [LinearOrder K] [IsStrictOrderedRing K] (D : Dictionary ι K) {fuel : ℕ} {D' : Dictionary ι K} {s : ι} (hD : D.Feasible) (h : D.run fuel = Outcome.unbounded D' s) :
                            D.Equivalent D' ∧ D'.Feasible ∧ s ∉ D'.basis ∧ 0 < D'.objCoeff s ∧ ∀ i ∈ D'.basis, 0 ≤ D'.coeff i s

                            A run that stops with an unbounded entering variable s returns an equivalent feasible dictionary in which s is nonbasic with a positive reduced cost and no row bounds its increase.

                            Correctness of the simplex method with Bland's rule ([Chv83], Chapter 3): from a feasible dictionary D it either stops at an equivalent feasible dictionary whose basic solution attains the maximum D'.objConst of the objective over the feasible set, or detects that the objective is unbounded above on the feasible set.