The reservation loop #
reservation reservationBudget runs reservationBudget iterations. Without a job, it pops the
fullest chunk and starts its
split, or stops when the queue is empty; with a job, it runs one job step.
theorem
OrderMaintenance.Proof.loop_bind
{β : Type}
{F : ℕ → β → Model.CM (ForInStep β)}
{K : β → Model.CM Unit}
{s : Model.Core}
{k : ℕ}
{b0 : β}
(I : ℕ → Model.Core → Prop)
(Q : Model.Core → Prop)
(h0 : I 0 s)
(hF :
∀ (x j : ℕ) (b : β) (t : Model.Core),
I j t →
j < k →
∃ (c : β) (t' : Model.Core),
EStateM.run (F x b) t = EStateM.Result.ok (ForInStep.yield c) t' ∧ I (j + 1) t' ∨ EStateM.run (F x b) t = EStateM.Result.ok (ForInStep.done c) t' ∧ Q t')
(hK : ∀ (a : β) (t : Model.Core), EStateM.run (K a) t = EStateM.Result.ok () t)
:
∃ (t' : Model.Core), EStateM.run (forIn (List.range k) b0 F >>= K) s = EStateM.Result.ok () t' ∧ (I k t' ∨ Q t')
A bounded loop followed by a continuation that does nothing.
theorem
OrderMaintenance.Proof.reservation_ok
{s : Model.Core}
{k : ℕ}
(I : ℕ → Model.Core → Prop)
(Q : Model.Core → Prop)
(h0 : I 0 s)
(hstep :
∀ (j : ℕ) (t : Model.Core),
I j t →
j < k →
(t.resJob = none →
t.pqHi = 0 ∧ Q t ∨ t.pqHi ≠ 0 ∧ ∃ (c : ℕ) (t1 : Model.Core) (t2 : Model.Core),
EStateM.run Model.pqPopMax t = EStateM.Result.ok c t1 ∧ EStateM.run (Model.splitChunkStart c) t1 = EStateM.Result.ok () t2 ∧ I (j + 1) t2) ∧ ∀ (job : Model.Job),
t.resJob = some job →
∃ (r : Option Model.Job) (t1 : Model.Core),
EStateM.run (Model.jobStep job) t = EStateM.Result.ok r t1 ∧ I (j + 1)
{ P := t1.P, E := t1.E, Gs := t1.Gs, C := t1.C, freeG := t1.freeG, count := t1.count,
head := t1.head, tail := t1.tail, firstGroup := t1.firstGroup, firstChunk := t1.firstChunk,
ready := t1.ready, prep := t1.prep, resJob := r, fallbacks := t1.fallbacks, pqHead := t1.pqHead,
pqNext := t1.pqNext, pqPrev := t1.pqPrev, pqWhere := t1.pqWhere, nbNext := t1.nbNext,
nbPrev := t1.nbPrev, pqHi := t1.pqHi, pqLo := t1.pqLo, nodes := t1.nodes, path := t1.path,
cin := t1.cin, lpar := t1.lpar })
:
∃ (t' : Model.Core), EStateM.run (Model.reservation k) s = EStateM.Result.ok () t' ∧ (I k t' ∨ Q t')
The reservation loop, given what each iteration does. I j holds after j iterations;
Q holds when the loop stopped at an empty queue.