Counting knapsack and 0-1 integer programming solutions
Lax280166.CountingKnapsacks · concepts/Lax280166/CountingKnapsacks.lean · lax-280166
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
The weights are written in binary as in the NP catalog. #Knapsack counts the sets of items whose total weight is exactly the target, and #0-1 Integer Programming counts the - vectors satisfying every constraint of the system with equality.
Concept map
Lean source view on GitHub
| 1 | import Mathlib.Tactic.FinCases |
| 2 | import Mathlib.Order.PiLex |
| 3 | import Mathlib.Data.Prod.Lex |
| 4 | import Mathlib.Data.Fintype.EquivFin |
| 5 | import Mathlib.ModelTheory.Order |
| 6 | import Mathlib.ModelTheory.Semantics |
| 7 | import Mathlib.ModelTheory.Complexity |
| 8 | import Mathlib.Logic.Equiv.Fin.Basic |
| 9 | import Mathlib.Data.Fintype.Lattice |
| 10 | import Mathlib.Data.Finite.Sigma |
| 11 | import Mathlib.Order.Lattice.Nat |
| 12 | import Mathlib.Data.Set.Card |
| 13 | import Mathlib.Data.Fintype.Pigeonhole |
| 14 | import Mathlib.Dynamics.FixedPoints.Basic |
| 15 | import Mathlib.ModelTheory.Syntax |
| 16 | import Mathlib.Algebra.Order.BigOperators.Group.Finset |
| 17 | import Mathlib.Data.Fintype.Card |
| 18 | import Mathlib.SetTheory.Cardinal.Finite |
| 19 | import Mathlib.Algebra.BigOperators.Finprod |
| 20 | import Mathlib.Data.Set.Finite.Lemmas |
| 21 | import Mathlib.Logic.Equiv.Prod |
| 22 | import Lax799700.Knapsack |
| 23 | import Lax799700.ZeroOneIP |
| 24 | import Lax904597.Machines |
| 25 | import Mathlib.SetTheory.Cardinal.Finite |
| 26 | import Lax366625.CountingProblems |
| 27 | |
| 28 | /-! |
| 29 | --- |
| 30 | title: Counting knapsack and 0-1 integer programming solutions |
| 31 | type: definition |
| 32 | --- |
| 33 | The weights are written in binary as in the NP catalog. #Knapsack counts the |
| 34 | sets of items whose total weight is exactly the target, and #0-1 Integer |
| 35 | Programming counts the - vectors satisfying every constraint of the |
| 36 | system with equality. |
| 37 | -/ |
| 38 | |
| 39 | namespace Lax280166.CountingKnapsacks |
| 40 | |
| 41 | open Lax799700.Knapsack Lax799700.ZeroOneIP Lax904597.Machines |
| 42 | |
| 43 | open FirstOrder |
| 44 | |
| 45 | open Language Structure |
| 46 | |
| 47 | section Solutions |
| 48 | |
| 49 | variable (A : Type) [binWeights.Structure A] |
| 50 | |
| 51 | /-- The set `S` of items is a solution: the instance is finite, its order is |
| 52 | linear, and the weights of `S` sum exactly to the target. -/ |
| 53 | def KnapsackSol (S : A → Prop) : Prop := |
| 54 | Finite A ∧ IsLinOrd (BWLe (A := A)) ∧ (∀ i, S i → BWItem i) ∧ |
| 55 | (∑ᶠ i ∈ {i | S i}, BWWeight i) = BWTarget A |
| 56 | |
| 57 | open FirstOrder |
| 58 | |
| 59 | open Language Structure |
| 60 | |
| 61 | variable (A : Type) [zeroOneIP.Structure A] |
| 62 | |
| 63 | /-- The set `x` of columns is a solution: the instance is finite, its order is |
| 64 | linear, and every equation holds. -/ |
| 65 | def ZeroOneSol (x : A → Prop) : Prop := |
| 66 | Finite A ∧ IsLinOrd (IPLe (A := A)) ∧ (∀ j, x j → IPCol j) ∧ |
| 67 | ∀ r, IPRow r → (∑ᶠ j ∈ {j | x j}, IPCoefVal r j) = IPRhsVal r |
| 68 | |
| 69 | end Solutions |
| 70 | |
| 71 | open Lax366625.CountingProblems |
| 72 | |
| 73 | /-- **#Knapsack**, as a counting problem. -/ |
| 74 | noncomputable def SharpKnapsack : CountingProblem Lax799700.Knapsack.binWeights := |
| 75 | CountingProblem.ofFun fun A _ => |
| 76 | Nat.card {S : A → Prop // KnapsackSol A S} |
| 77 | |
| 78 | /-- **#0-1 Integer Programming**, as a counting problem. -/ |
| 79 | noncomputable def SharpZeroOneIP : CountingProblem Lax799700.ZeroOneIP.zeroOneIP := |
| 80 | CountingProblem.ofFun fun A _ => |
| 81 | Nat.card {x : A → Prop // ZeroOneSol A x} |
| 82 | |
| 83 | end Lax280166.CountingKnapsacks |
| 84 |
Used by
Lax280166.CliqueCompleteLax280166.CliquesValuesLax280166.DirHamCircuitCompleteLax280166.DominatingSetCompleteLax280166.DominatingSetsValuesLax280166.ExactCoverCompleteLax280166.FeedbackArcSetCompleteLax280166.FeedbackSetsValuesLax280166.FeedbackVertexSetCompleteLax280166.HamCircuitCompleteLax280166.HamiltonCircuitsValuesLax280166.HittingSetCompleteLax280166.IndependentSetCompleteLax280166.KnapsackCompleteLax280166.KnapsacksValuesLax280166.OneInSATCompleteLax280166.SatVariantsValuesLax280166.SetCoverCompleteLax280166.SetFamiliesValuesLax280166.SetPackingCompleteLax280166.SteinerTreeCompleteLax280166.SteinerTreesValuesLax280166.ThreeSATCompleteLax280166.VertexCoverCompleteLax280166.ZeroOneIPComplete
From Mathlib
Mathlib.Algebra.BigOperators.FinprodMathlib.Algebra.Order.BigOperators.Group.FinsetMathlib.Data.Finite.SigmaMathlib.Data.Fintype.CardMathlib.Data.Fintype.EquivFinMathlib.Data.Fintype.LatticeMathlib.Data.Fintype.PigeonholeMathlib.Data.Prod.LexMathlib.Data.Set.CardMathlib.Data.Set.Finite.LemmasMathlib.Dynamics.FixedPoints.BasicMathlib.Logic.Equiv.Fin.BasicMathlib.Logic.Equiv.ProdMathlib.ModelTheory.ComplexityMathlib.ModelTheory.OrderMathlib.ModelTheory.SemanticsMathlib.ModelTheory.SyntaxMathlib.Order.Lattice.NatMathlib.Order.PiLexMathlib.SetTheory.Cardinal.FiniteMathlib.Tactic.FinCases
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments