Library prosa.classic.model.schedule.uni.transformation.construction

Require Import prosa.classic.util.all.
Require Import prosa.classic.model.arrival.basic.job prosa.classic.model.arrival.basic.arrival_sequence.
Require Import prosa.classic.model.schedule.uni.schedule.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat fintype bigop seq path finfun.

Module ScheduleConstruction.

  Import Job ArrivalSequence UniprocessorSchedule.

  Section ConstructionFromPrefixes.

    Context {Job: eqType}.

    Variable arr_seq: arrival_sequence Job.

    Variable build_schedule:
      schedule Job time option Job.

    Variable base_sched: schedule Job.

    Definition update_schedule (prev_sched: schedule Job)
                               (t_next: time) : schedule Job :=
      fun t
        if t == t_next then
          build_schedule prev_sched t
        else prev_sched t.

    Fixpoint schedule_prefix (t_max: time) : schedule Job :=
      if t_max is t_prev.+1 then
        update_schedule (schedule_prefix t_prev) t_prev.+1
      else
        update_schedule base_sched 0.

    Definition build_schedule_from_prefixes := fun tschedule_prefix t t.

    Section Lemmas.

      Let sched := build_schedule_from_prefixes.

      Lemma prefix_construction_same_prefix:
         t t_max,
          t t_max
          schedule_prefix t_max t = sched t.

      Section ServiceDependent.

        Hypothesis H_depends_only_on_service:
           sched1 sched2 t,
            ( j, service sched1 j t = service sched2 j t)
            build_schedule sched1 t = build_schedule sched2 t.

        Lemma service_dependent_schedule_construction:
           t,
            sched t = build_schedule sched t.

      End ServiceDependent.

      Section PrefixDependent.

        Hypothesis H_depends_only_on_prefix:
           (sched1 sched2: schedule Job) t,
            ( t0, t0 < t sched1 t0 = sched2 t0)
            build_schedule sched1 t = build_schedule sched2 t.

        Lemma prefix_dependent_schedule_construction:
           t, sched t = build_schedule sched t.

      End PrefixDependent.

      Section ImmediateProperty.

        Variable P: option Job Prop.

        Hypothesis H_immediate_property:
           sched_prefix t, P (build_schedule sched_prefix t).

        Lemma immediate_property_of_schedule_construction:
           t, P (sched t).

      End ImmediateProperty.

    End Lemmas.

  End ConstructionFromPrefixes.

End ScheduleConstruction.