Library prosa.classic.analysis.uni.susp.sustainability.allcosts.reduction_properties

Require Import prosa.classic.util.all.
Require Import prosa.classic.model.priority prosa.classic.model.suspension.
Require Import prosa.classic.model.arrival.basic.arrival_sequence.
Require Import prosa.classic.model.schedule.uni.response_time.
Require Import prosa.classic.model.schedule.uni.susp.suspension_intervals
               prosa.classic.model.schedule.uni.susp.schedule
               prosa.classic.model.schedule.uni.susp.valid_schedule
               prosa.classic.model.schedule.uni.susp.build_suspension_table
               prosa.classic.model.schedule.uni.susp.platform.
Require Import prosa.classic.analysis.uni.susp.sustainability.allcosts.reduction.
Require Import prosa.classic.model.schedule.uni.transformation.construction.

From mathcomp Require Import ssreflect ssrbool eqtype ssrnat seq fintype bigop.

Module SustainabilityAllCostsProperties.

  Import ScheduleWithSuspensions Suspension Priority SuspensionIntervals
         PlatformWithSuspensions ResponseTime ScheduleConstruction
         SuspensionTableConstruction ValidSuspensionAwareSchedule.

  Module reduction := SustainabilityAllCosts.

  Section ReductionProperties.

    Context {Job: eqType}.
    Variable job_arrival: Job time.
    Variable job_cost: Job time.

Basic Setup & Setting
Reduction Setup

    Variable j: Job.
    Let arr_j := job_arrival j.

    Variable R: time.

    Variable inflated_job_cost: Job time.

    Hypothesis H_job_costs_do_not_decrease:
       any_j, inflated_job_cost any_j job_cost any_j.

    Let sched_new := reduction.sched_new job_arrival job_cost arr_seq higher_eq_priority
                                         sched_susp inflated_job_cost j R.

    Let suspended_in_sched_new :=
      reduction.suspended_in_sched_new job_arrival job_cost arr_seq higher_eq_priority
                                 sched_susp job_suspension_duration inflated_job_cost j R.

    Let reduced_suspension_duration :=
      reduction.reduced_suspension_duration job_arrival job_cost arr_seq higher_eq_priority
                                   sched_susp job_suspension_duration inflated_job_cost j R.

    Let job_response_time_in_sched_susp_bounded_by :=
      is_response_time_bound_of_job job_arrival job_cost sched_susp.
    Let job_response_time_in_sched_new_bounded_by :=
      is_response_time_bound_of_job job_arrival inflated_job_cost sched_new.
    Let suspended_in_sched_susp :=
      suspended_at job_arrival job_cost job_suspension_duration sched_susp.
    Let job_is_late := reduction.job_is_late job_cost sched_susp inflated_job_cost sched_new.
    Let build_schedule := reduction.build_schedule job_arrival job_cost arr_seq higher_eq_priority
                                                   sched_susp inflated_job_cost j R.
    Let late_or_sched_jobs := reduction.jobs_that_are_late_or_scheduled_in_sched_susp
                                job_arrival job_cost arr_seq sched_susp inflated_job_cost sched_new.
    Let hp_job := reduction.highest_priority_job job_arrival arr_seq higher_eq_priority
                                                 inflated_job_cost sched_new.
    Let hp_late_job := reduction.highest_priority_late_job job_arrival job_cost arr_seq
                                       higher_eq_priority sched_susp inflated_job_cost sched_new.
    Let completed_in_sched_susp := completed_by job_cost sched_susp.
    Let completed_in_sched_new := completed_by inflated_job_cost sched_new.

Properties of the Schedule Construction

    Section PropertiesOfScheduleConstruction.

      Lemma sched_new_depends_only_on_service:
         sched1 sched2 t,
          ( j, service sched1 j t = service sched2 j t)
          build_schedule sched1 t = build_schedule sched2 t.

      Corollary sched_new_uses_construction_function:
         t,
          sched_new t = build_schedule sched_new t.

    End PropertiesOfScheduleConstruction.

Basic Properties of the Generated Schedule
Service Invariants

    Section ServiceInvariant.

      Variable t: time.
      Hypothesis H_before_R: t arr_j + R.

      Lemma sched_new_service_invariant:
         any_j,
          service sched_new any_j t
             service sched_susp any_j t + (inflated_job_cost any_j - job_cost any_j).

      Corollary sched_new_jobs_complete_later:
         any_j,
          completed_by inflated_job_cost sched_new any_j t
          completed_by job_cost sched_susp any_j t.

    End ServiceInvariant.

Properties of the Suspension Predicate

    Section SuspensionPredicate.

      Variable any_j: Job.

      Lemma suspended_in_sched_new_implies_arrived:
         t,
          suspended_in_sched_new any_j t has_arrived job_arrival any_j t.

      Lemma suspended_in_sched_new_implies_not_completed:
         t,
          suspended_in_sched_new any_j t ~~ completed_in_sched_new any_j t.

      Lemma executes_before_suspension_in_sched_new:
         t,
          t < arr_j + R
          has_arrived job_arrival any_j t
          ~~ suspended_in_sched_new any_j t
          suspended_in_sched_new any_j t.+1
          scheduled_at sched_new any_j t.

      Let suspension_start := time_after_last_execution job_arrival.

      Lemma suspended_in_sched_new_no_service_since_execution:
         t t_mid,
          suspended_in_sched_new any_j t
          suspension_start sched_new any_j t t_mid < t
          service sched_new any_j t service sched_new any_j t_mid.

      Lemma suspended_in_sched_new_suspension_starts_no_earlier:
         t,
          has_arrived job_arrival any_j t
          suspended_in_sched_new any_j t
          suspension_start sched_susp any_j t suspension_start sched_new any_j t.

      Lemma suspended_in_sched_new_is_continuous:
         t t_mid,
          suspended_in_sched_new any_j t
          suspension_start sched_new any_j t t_mid < t
          suspended_in_sched_new any_j t_mid.

    End SuspensionPredicate.

Properties of the Suspension Table

    Section SuspensionTable.

      Lemma suspended_in_sched_new_only_inside_window:
         any_j t,
          arr_j + R t
          ~~ suspended_at job_arrival inflated_job_cost reduced_suspension_duration
                          sched_new any_j t.

      Lemma sched_new_suspension_matches:
         any_j t,
          t < arr_j + R
          suspended_in_sched_new any_j t =
          suspended_at job_arrival inflated_job_cost reduced_suspension_duration sched_new any_j t.

      Let cumulative_suspension_in_sched_susp :=
        cumulative_suspension job_arrival job_cost job_suspension_duration sched_susp.
      Let cumulative_suspension_in_sched_new :=
        cumulative_suspension job_arrival inflated_job_cost reduced_suspension_duration sched_new.

      Lemma sched_new_has_shorter_suspension:
         any_j t,
          cumulative_suspension_in_sched_new any_j t
           cumulative_suspension_in_sched_susp any_j t.

      Corollary sched_new_has_shorter_total_suspension:
         any_j,
          total_suspension inflated_job_cost reduced_suspension_duration any_j
          total_suspension job_cost job_suspension_duration any_j.

    End SuspensionTable.

Suspension-Related Schedule Properties
Final Remarks