Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Define linear programs #7386

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8352c37
LP defined
madvorak Sep 26, 2023
09eb773
for the linter
madvorak Sep 26, 2023
0832139
minimum solution
madvorak Sep 26, 2023
cc01f1a
revert change in manifest
madvorak Sep 26, 2023
f23e30e
generalizations
madvorak Sep 26, 2023
bfffc93
bugfix
madvorak Sep 26, 2023
e927639
linear function instead of a matrix
madvorak Sep 26, 2023
8ad85e1
more definitions of LP
madvorak Sep 28, 2023
3734234
visibility fixed
madvorak Sep 28, 2023
02ee2bd
docstrings on the correct place
madvorak Sep 28, 2023
04fb906
removed empty spaces
madvorak Sep 28, 2023
311abd9
CanonicalLP back to matrix form
madvorak Sep 28, 2023
ed5ca5e
generalization
madvorak Sep 28, 2023
85c2a02
partial fix
madvorak Sep 28, 2023
f6b53ac
more partial fix
madvorak Sep 28, 2023
e5944c5
the type arguments can be inferred from P
madvorak Sep 28, 2023
155d63c
bugfix
madvorak Sep 28, 2023
c3a4529
docstring
madvorak Sep 28, 2023
af45efb
by Eric Wieser
madvorak Sep 28, 2023
f7c80bc
major cleanup
madvorak Sep 28, 2023
fc1e7c5
LP definition finished
madvorak Oct 5, 2023
00da03e
actually it was not the standard form
madvorak Oct 5, 2023
25d9446
Update Mathlib/LinearAlgebra/Matrix/LinearProgramming.lean
madvorak Oct 9, 2023
247b7d4
as per PR
madvorak Oct 10, 2023
7e18396
move LP out of Matrix
madvorak Oct 10, 2023
b3b95a0
path changed
madvorak Oct 10, 2023
d6b731b
proof fix
madvorak Oct 10, 2023
5a04ae0
two trivial results
madvorak Oct 15, 2023
a6bb9fe
names fix
madvorak Oct 16, 2023
432c597
trivial lemma
madvorak Nov 10, 2023
5d2eba8
Update Mathlib/LinearAlgebra/LinearProgramming.lean
madvorak Nov 10, 2023
da8146f
Update Mathlib/LinearAlgebra/LinearProgramming.lean
madvorak Nov 10, 2023
0500287
fix
madvorak Nov 10, 2023
72a8028
refactoring a ∈ equalities → a x = 0
madvorak Nov 10, 2023
acb1869
Update Mathlib/LinearAlgebra/LinearProgramming.lean
madvorak Nov 13, 2023
8d9feeb
Update Mathlib/LinearAlgebra/LinearProgramming.lean
madvorak Nov 13, 2023
ca6899c
fix and refactor
madvorak Nov 13, 2023
3f08fde
refactor the proof of LinearProgram.feasibles_mkOfEqs
madvorak Nov 13, 2023
5560272
golf a long proof
eric-wieser Nov 13, 2023
0f8071d
LinearOrderedRing is enough
madvorak Nov 18, 2023
0b5163b
LP refactoring
madvorak Nov 24, 2023
45bbb4b
LP chore
madvorak Nov 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Mathlib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,7 @@ import Mathlib.LinearAlgebra.Matrix.Hermitian
import Mathlib.LinearAlgebra.Matrix.InvariantBasisNumber
import Mathlib.LinearAlgebra.Matrix.IsDiag
import Mathlib.LinearAlgebra.Matrix.LDL
import Mathlib.LinearAlgebra.Matrix.LinearProgramming
import Mathlib.LinearAlgebra.Matrix.MvPolynomial
import Mathlib.LinearAlgebra.Matrix.Nondegenerate
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
Expand Down
81 changes: 81 additions & 0 deletions Mathlib/LinearAlgebra/Matrix/LinearProgramming.lean
madvorak marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/-
Copyright (c) 2023 Martin Dvorak. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Martin Dvorak
-/
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.LinearAlgebra.AffineSpace.AffineMap

/-! # Linear programming

TODO

## Main definitions

* `CanonicalLP` defines a linear program in the canonical form.
* `CanonicalLP.Admits` tells if given vector is an admissible solution to given canonical LP.
* `StandardLP` defines a linear program in the standard form.
* `StandardLP.Permits` tells if given vector is an admissible solution to given standard LP.

-/

section canonical

open Matrix

/-- Linear program in the canonical form. -/
structure CanonicalLP (m n K : Type _) [Fintype m] [Fintype n] [LinearOrderedField K] where
A : (n → K) →ₗ[K] (m → K) /- (possibly not a) matrix of coefficients -/
b : m → K /- right-hand side -/
c : n → K /- objective function coefficients -/
madvorak marked this conversation as resolved.
Show resolved Hide resolved

variable {m n K : Type _} [Fintype m] [Fintype n] [LinearOrderedField K]

def CanonicalLP.Admits (P : CanonicalLP m n K) (x : n → K) : Prop :=
P.A x = P.b ∧ 0 ≤ x

def CanonicalLP.HasMinAt (P : CanonicalLP m n K) (x : n → K) : Prop :=
P.Admits x ∧ (∀ y, P.Admits y → P.c ⬝ᵥ x ≤ P.c ⬝ᵥ y)

def CanonicalLP.HasMin (P : CanonicalLP m n K) : Prop :=
∃ x : n → K, P.HasMinAt x

def CanonicalLP.Minimum (P : CanonicalLP m n K) (d : K) : Prop :=
∃ x : n → K, P.HasMinAt x ∧ d = P.c ⬝ᵥ x
-- Or should it be `CanonicalLP.Minimum (P) : Option K` instead?
-- Or `CanonicalLP.Minimum (P) : P.HasMin → K` something?

example : (@CanonicalLP.mk (Fin 2) (Fin 3) ℚ _ _ _
(Matrix.toLin' !![1, 2, 0; 1, -1, 4]) ![5, 3] 0
).Admits ![1, 2, 1] := by
constructor
· ext i : 1
match i with
| 0 =>
rfl
| 1 =>
rfl
· simp [LE.le]

end canonical


/-- Linear program in the standard form. -/
structure StandardLP (K V : Type) [LinearOrderedField K] [AddCommGroup V] [Module K V] where
constr : Finset (AffineMap K V K)
obj : AffineMap K V K

def StandardLP.Permits {K V : Type} [LinearOrderedField K] [AddCommGroup V] [Module K V]
(P : StandardLP K V) (x : V) : Prop :=
∀ c ∈ P.constr, 0 ≤ c x


/-- Linear program in a more versatile form. -/
structure SomeLP (K V : Type) [LinearOrderedField K] [AddCommGroup V] [Module K V] where
eq : Finset (AffineMap K V K)
le : Finset (AffineMap K V K)
obj : AffineMap K V K
madvorak marked this conversation as resolved.
Show resolved Hide resolved

def SomeLP.Solutions {K V : Type} [LinearOrderedField K] [AddCommGroup V] [Module K V]
(P : SomeLP K V) : Set V :=
{ x : V | (∀ e ∈ P.eq, e x = 0) ∧ (∀ i ∈ P.le, 0 ≤ i x) }
madvorak marked this conversation as resolved.
Show resolved Hide resolved
Loading