The two-phase simplex method #
This module formalizes the two-phase simplex method ([Chv83], Chapter 3) for linear programs
max c ⬝ᵥ x subject to x ≥ 0, A *ᵥ x ≤ b over a linearly ordered field K, with no sign
restriction on b.
Algorithm #
Given A : Matrix (Fin m) (Fin n) K, b : Fin m → K and c : Fin n → K:
- Phase I. Form the auxiliary program
max -x₀subject toA *ᵥ x - x₀ • 1 ≤ b,x ≥ 0,x₀ ≥ 0, whose slack dictionary isauxDictionary A bonFin (n + 1 + m)(withx₀atFin.castAdd m (Fin.last n)). If someb i < 0,phaseOneDict A bperforms the special first pivot enteringx₀and leaving the slack of the smallest row minimizingb i, producing a feasible dictionary. OtherwiseauxDictionary A bis already feasible. - Phase I solve. Run Bland's rule (
Dictionary.simplex) onphaseOneDict A b. Because the auxiliary objective-x₀is bounded above by0, the unbounded and out-of-fuel branches are unreachable.- If the optimal auxiliary value is
< 0, the original program is infeasible, andD.slackDualis a Farkas certificate (0 ≤ y,0 ≤ y ᵥ* A,y ⬝ᵥ b < 0). - Otherwise the optimal auxiliary value is
0. Ifx₀is still basic,forcePivotX₀ Dperforms a degenerate pivot removingx₀from the basis (a nonzero row coefficient always exists becausex₀can vary freely in the affine solution space ofauxDictionary A b). ThendropX₀deletes columnx₀and installs the original objectivec, producing a feasible dictionary equivalent toslackDictionary A b c.
- If the optimal auxiliary value is
- Phase II. Run Bland's rule on the resulting Phase II dictionary. The out-of-fuel branch is
unreachable by
Dictionary.simplex_ne_outOfFuel; an optimal dictionary yields a primal–dual optimal pair(x, y)withc ⬝ᵥ x = y ⬝ᵥ b, and an unbounded dictionary yields a feasible pointxand recession raydwith0 ≤ d,A *ᵥ d ≤ 0,0 < c ⬝ᵥ d.
Main definitions #
Cslib.Algorithms.Lean.Simplex.TwoPhaseResult: the three certified outcomes (infeasible,unbounded,optimal) of the two-phase simplex method.Cslib.Algorithms.Lean.Simplex.auxDictionary: the slack dictionary of the Phase I auxiliary programmax -x₀subject toA *ᵥ x - x₀ • 1 ≤ b,x, x₀ ≥ 0.Cslib.Algorithms.Lean.Simplex.phaseOneDict: the initial feasible Phase I dictionary after the special first pivot when someb i < 0.Cslib.Algorithms.Lean.Simplex.forcePivotX₀: degenerate pivot removingx₀from the basis when Phase I terminates at0withx₀still basic.Cslib.Algorithms.Lean.Simplex.dropX₀: drops columnx₀from a dictionary withx₀ ∉ basisand installs the original objectivec.Cslib.Algorithms.Lean.Simplex.twoPhase: the total, terminating two-phase simplex solver.
Main results #
Cslib.Algorithms.Lean.Simplex.phaseOneDict_feasible,Cslib.Algorithms.Lean.Simplex.phaseOneDict_equivalent:phaseOneDict A bis always feasible and equivalent toauxDictionary A b.Cslib.Algorithms.Lean.Simplex.twoPhase_spec: every output oftwoPhase A b cis a valid infeasibility, unboundedness or primal–dual optimality certificate, with no hypothesis onb.Cslib.Algorithms.Lean.Simplex.feasibleSet_eq_empty_of_twoPhase_eq_infeasible: aninfeasibleoutput certifies that the feasible set is empty.Cslib.Algorithms.Lean.Simplex.not_bddAbove_of_twoPhase_eq_unbounded: anunboundedoutput certifies that the objective is not bounded above on the feasible set.Cslib.Algorithms.Lean.Simplex.isGreatest_isLeast_of_twoPhase_eq_optimal: anoptimaloutput certifies both primalIsGreatestand dualIsLeast.
Limitations #
The method is a pure Lean function over an exact linearly ordered field; no machine-level running time or bit complexity is certified.
References #
The certified outcome of the two-phase simplex method on a linear program with m constraints
and n variables over K.
- infeasible {K : Type u_1} {m n : ℕ} (y : Fin m → K) : TwoPhaseResult K m n
Infeasible, certified by a Farkas vector
ywith0 ≤ y,0 ≤ y ᵥ* A,y ⬝ᵥ b < 0. - unbounded {K : Type u_1} {m n : ℕ} (x d : Fin n → K) : TwoPhaseResult K m n
Unbounded, certified by a feasible point
xand raydwith0 ≤ d,A *ᵥ d ≤ 0,0 < c ⬝ᵥ d. - optimal {K : Type u_1} {m n : ℕ} (x : Fin n → K) (y : Fin m → K) : TwoPhaseResult K m n
Optimal, certified by a primal optimum
xand a dual optimumywithc ⬝ᵥ x = y ⬝ᵥ b.
The slack dictionary of the Phase I auxiliary program max -x₀ subject to
A *ᵥ x - x₀ • 1 ≤ b, x ≥ 0, x₀ ≥ 0 ([Chv83], Chapter 3), with x₀ at
Fin.castAdd m (Fin.last n). Exposed so twoPhase reduces in the kernel.
The initial feasible Phase I dictionary ([Chv83], Chapter 3): if some b i < 0, pivot
x₀ into the basis and the slack of the smallest row minimizing b i out; otherwise
auxDictionary A b is already feasible. Exposed so twoPhase reduces in the kernel.
If the auxiliary variable x₀ is still basic at the end of Phase I, pivot it out using the
smallest nonbasic variable with a nonzero coefficient in its row ([Chv83], Chapter 3).
Exposed so twoPhase reduces in the kernel.
Drop the auxiliary variable x₀ from a Phase I dictionary (with x₀ ∉ D.basis) and install
the original objective c ⬝ᵥ x expressed in terms of the nonbasic variables ([Chv83],
Chapter 3). Exposed so twoPhase reduces in the kernel.
The two-phase simplex method with Bland's rule ([Chv83], Chapter 3; [Bla77])
for max c ⬝ᵥ x subject to x ≥ 0, A *ᵥ x ≤ b with arbitrary b. It is total and
terminating, returning an infeasibility, unboundedness or primal–dual optimality certificate
(twoPhase_spec); the Phase I unbounded and out-of-fuel branches are unreachable.
Phase I invariants #
Phase I initialization is always feasible ([Chv83], Chapter 3): for arbitrary b,
phaseOneDict A b is a feasible dictionary.
phaseOneDict A b is equivalent to auxDictionary A b.
Phase I → Phase II transition #
Phase II unboundedness certificate #
Main specification and corollaries #
Correctness and termination of the two-phase simplex method ([Chv83], Chapter 3):
for arbitrary A, b and c over a linearly ordered field, twoPhase A b c returns a valid
Farkas infeasibility certificate, an unboundedness ray certificate, or an optimal primal–dual
pair with equal objective values.
An infeasible result of twoPhase certifies that the primal feasible set is empty.
An unbounded result of twoPhase certifies that the objective is not bounded above on the
primal feasible set.
An optimal result of twoPhase certifies both that c ⬝ᵥ x is the primal maximum
(IsGreatest) and that y ⬝ᵥ b is the dual minimum (IsLeast).