introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
2.74 kB
import OAI.Combinatorics.PerfectMatching.Model
namespace OAI
/-! Polynomial-time approximation of weighted matchings with singleton loops. -/
open scoped BigOperators
namespace LoopMatching
structure LoopRecord where
vertex : β„•
multiplicity : β„•
deriving DecidableEq
structure Input where
ordinary : BinaryMatching.Input
loops : List LoopRecord
valid : βˆ€ e ∈ loops, e.vertex < ordinary.n
unique : (loops.map LoopRecord.vertex).Nodup
abbrev Input.n (G : Input) : β„• := G.ordinary.n
def loopMultiplicity (G : Input) (v : Fin G.n) : β„• :=
match G.loops.find? (fun r => r.vertex == v.val) with
| none => 0
| some r => r.multiplicity
def IsPartialMatching (n : β„•) (M : Finset (BinaryMatching.Pair n)) : Prop :=
βˆ€ v : Fin n, βˆ€ e ∈ M, βˆ€ f ∈ M,
(BinaryMatching.completeGraph n).Incident v e β†’
(BinaryMatching.completeGraph n).Incident v f β†’ e = f
abbrev PartialMatching (n : β„•) :=
{ M : Finset (BinaryMatching.Pair n) // IsPartialMatching n M }
noncomputable instance partialMatchingFintype (n : β„•) : Fintype (PartialMatching n) :=
Fintype.ofFinite _
noncomputable def loopVertices {n : β„•} (M : PartialMatching n) : Finset (Fin n) := by
classical
exact Finset.univ.filter (fun v =>
βˆ€ e ∈ M.val, Β¬ (BinaryMatching.completeGraph n).Incident v e)
noncomputable def weight (G : Input) (M : PartialMatching G.n) : β„• :=
(∏ e ∈ M.val, BinaryMatching.multiplicity G.ordinary e) *
∏ v ∈ loopVertices M, loopMultiplicity G v
noncomputable def count (G : Input) : β„• := βˆ‘ M : PartialMatching G.n, weight G M
noncomputable def countWithLoops (G : Input) (j : β„•) : β„• := by
classical
exact βˆ‘ M : PartialMatching G.n,
if (loopVertices M).card = j then weight G M else 0
def encodeLoopRecord (r : LoopRecord) : List Bool :=
BinaryMatching.encodeNat r.vertex ++ BinaryMatching.encodeNat r.multiplicity
def encodeInput (G : Input) : List Bool :=
BinaryMatching.encodeInput G.ordinary ++
BinaryMatching.encodeNat G.loops.length ++ G.loops.flatMap encodeLoopRecord
def encodeOutput (a : β„• Γ— β„•) : List Bool :=
BinaryMatching.encodeNat a.1 ++ BinaryMatching.encodeNat a.2
def outputValue (a : β„• Γ— β„•) : β„š := (a.1 : β„š) / a.2
def FullEndpoint : Prop :=
βˆƒ A : Input β†’ β„• Γ— β„•,
βˆƒ machine : Turing.TM2ComputableInPolyTime encodeInput encodeOutput A,
(βˆ€ k, Finite (machine.tm.Ξ“ k)) ∧
(βˆƒ P : Polynomial β„•, βˆ€ G,
(encodeOutput (A G)).length ≀ P.eval (encodeInput G).length) ∧
βˆ€ G, 0 < (A G).2 ∧
(A G).1 ≀ (A G).2 * count G ∧
(A G).2 * count G ≀ 2 ^ (18 * G.n) * (A G).1 ∧
((A G).1 = 0 ↔ count G = 0)
end LoopMatching
end OAI