File size: 2,736 Bytes
4a56cd6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 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
|