50483

Код модифицированной программы: distribution.adb

Лабораторная работа

Информатика, кибернетика и программирование

В ходе выполнения лабораторной работы были выполнены следующие действия: Замена распределения случайных величин в соответствии с Пуассоновским распределением (описано в distribution.adb)В ходе выполнения программы процесс выполнения комментируется в окне сообщений. Ниже представлен пример рабочего процесса с/без использования мониторов.

Русский

2014-01-24

99.5 KB

1 чел.

Лабораторная работа №4

«Планирование производства на фабрике»

бригады №1

Выполнили:

Кузьменко Сергей

Сербин Виталий

Буренок Денис

Описание программы:

Код модифицированной программы:

distribution.adb

with Ada.Numerics.Float_Random;

use Ada.Numerics.Float_Random;

with ada.Text_IO;

use Ada.Text_IO;

with Ada.Numerics.Complex_Elementary_Functions;

use Ada.Numerics.Complex_Elementary_Functions;

package body DISTRIBUTIONS   is

  function  PROBABILITY (FORM_DIST : in DIST_KINDS)   return  DURATION is

  begin

     if FORM_DIST = TIME_MACH1 then

        return 0.03;

     end if;

      if FORM_DIST = TIME_MACH2 then

        return 0.07;

     end if;

      if FORM_DIST = TIME_MACH3 then

        return 0.11;

     end if;

      if FORM_DIST = INSPECTION then

        return 0.02;

     end if;

     end;

  function  INSP_RESULT  return  BOOLEAN is

     gen :Generator;

     fact : Integer := 1;

     lyamda : Float :=1.5;

     k: Integer;

  begin

     Reset(gen);

     k:= Random(gen);

     for i in 1..k loop

     fact := fact * i;

     end loop;

     Reset(gen);

     if ((lyamda**k)/fact)*Exp(-lyamda) > 0.05 then

        return true;

     else

        return false;

    end if;

  end;

end  DISTRIBUTIONS;

PLANT_SCHED.adb

-- MAIN procedure

-- from Didenko, CSD

-- 19 Feb 2010

with DISTRIBUTIONS;   use  DISTRIBUTIONS;

with  CALENDAR;   use  CALENDAR;

with  Ada.TEXT_IO;   use  Ada.TEXT_IO;

procedure  PLANT_SCHED   is

  package natural_io is new integer_io(natural);

  use natural_io;

  N_OF_FINISHED_PROD : NATURAL := 0;

  N_OF_REJECTS : NATURAL := 0;

  MACH1_AVAIL, MACH2_AVAIL, MACH3_AVAIL : NATURAL := 0;

--task 3

  number_between_1_n_2 : NATURAL := 0;

--task 3

  number_after_operation : NATURAL := 0;

  task   COORDINATOR is

     entry  SCHED;

  end COORDINATOR;

  task   MACH1 is

     entry  OPER1;

  end  MACH1;

  task   MACH2 is

entry  OPER2;

  end   MACH2;

  task MACH3 is

entry OPER1_N_2;

  end MACH3;

  task STOP_INSPECTION;

  task INSPECT is

entry PRODUCT;

entry TAKE_A_BREAK;

  end INSPECT;

  --task 3

  task STAND_BETWEEN_1_N_2 is

     entry FIRST;

     entry SECOND;

  end STAND_BETWEEN_1_N_2;

--task 3

task INSPECTION_STAND

  is

     entry READY;

     entry START1;

     entry START2;

end INSPECTION_STAND;

task body MACH1 is

     MACH1_JOB_DURATION : DURATION;

  begin

     MACH1_JOB_DURATION := PROBABILITY(TIME_MACH1);

     loop

        Put_Line("Starting task on MACH1");

        accept OPER1;

        delay MACH1_JOB_DURATION;

        Put_Line("Task on MACH1 finished");

 STAND_BETWEEN_1_N_2.FIRST;

        MACH1_JOB_DURATION:=PROBABILITY(TIME_MACH1);

     end loop;

end MACH1;

  --

task body STAND_BETWEEN_1_N_2 is

  begin

     loop

       select

           accept FIRST;

           number_between_1_n_2 := number_between_1_n_2 + 1;

        else

          null;

        end select;

          if  number_between_1_n_2 > 0 then

               select

                   accept Second;

                   number_between_1_n_2 := number_between_1_n_2 - 1;

                else null;

              end select;

          end if;

        delay 0.01;

     end loop;

end STAND_BETWEEN_1_N_2;

task body MACH2 is

     MACH2_JOB_DURATION : DURATION;

  begin

     MACH2_JOB_DURATION := PROBABILITY(TIME_MACH2);

     loop

         Put_Line("Starting task on MACH2");

        delay MACH2_JOB_DURATION;

        Put_Line("Task on MACH2 finished, standing after MACH2");

        STAND_BETWEEN_1_N_2.SECOND;

         INSPECTION_STAND.START1;

         MACH2_JOB_DURATION := PROBABILITY(TIME_MACH2);

     end loop;

end MACH2;

  task body INSPECTION_STAND is

  begin

     loop

        select

           accept START1;

           Put_Line("Inspection after MACH2 started");

           number_after_operation := number_after_operation + 1;

        else

           null;

        end select;

        select

           accept START2;

            Put_Line("Inspection after MACH3 started");

           number_after_operation := number_after_operation + 1;

        else

           null;

        end select;

        if number_after_operation > 0 then

        select

              accept READY;

             Put_Line("Inspection finished successfuly");

              number_after_operation := number_after_operation - 1;

         else null;

           end select;

        end if;

        delay 0.01;

        end loop;

  end INSPECTION_STAND;

task body MACH3 is

     MACH3_JOB_DURATION : DURATION;

begin

     MACH3_JOB_DURATION := PROBABILITY(TIME_MACH3);

       loop

        accept OPER1_N_2;

         Put_Line("Starting task on MACH3");

        delay MACH3_JOB_DURATION;

         Put_Line("Task on MACH3 finished, standing after MACH3");

 INSPECTION_STAND.START2;

        MACH3_JOB_DURATION := PROBABILITY(TIME_MACH3);

end loop;

end MACH3;

--

task body COORDINATOR is

  begin

     accept SCHED;

    loop

 loop

     select

  MACH1.OPER1;

  exit;

  or

  delay 0.01;

  end select;

     select

  MACH3.OPER1_N_2;

  exit;

         or

  delay 0.01;

      end select;

 end loop;

 select

                  accept SCHED;

 else

     null;

               end select;

     end loop;

end COORDINATOR;

--

task body STOP_INSPECTION is

 begin

  loop

   delay 120.00;

   INSPECT.TAKE_A_BREAK;

  end loop;

end STOP_INSPECTION;

--

  task body INSPECT is

  INSP_PASSED: BOOLEAN;

  EXAM_TIME : DURATION;

  START_MANUFACT, STOP_MANUFACT : TIME;

  DURATION_MANUFACT : DURATION;

  package DURATION_I0 is new FIXED_IO(DURATION);

  use DURATION_I0;

 begin

 START_MANUFACT := CLOCK;

 INSP_PASSED := INSP_RESULT;

 EXAM_TIME := PROBABILITY(INSPECTION);

 loop

                   INSPECTION_STAND.READY;

     delay EXAM_TIME;

  if INSP_PASSED then

              N_OF_FINISHED_PROD:= N_OF_FINISHED_PROD + 1;

              Put("Number of finished products ");

             Put(N_OF_FINISHED_PROD);

              Put_line("");

  else

              N_OF_REJECTS:= N_OF_REJECTS + 1;

              Put("Number of finished products ");

              Put(N_OF_REJECTS);

              Put_line("");

         end if;

  EXAM_TIME:= PROBABILITY(INSPECTION);

  INSP_PASSED:= INSP_RESULT;

          exit when N_OF_FINISHED_PROD = 200;

  if TAKE_A_BREAK'COUNT > 0 then

   accept TAKE_A_BREAK;

   delay 15.0;

  end if;

 end loop;

 STOP_MANUFACT := CLOCK;

       DURATION_MANUFACT := STOP_MANUFACT - START_MANUFACT;

       PUT ("Manufacture full cycle length ");

       PUT (DURATION_MANUFACT, 10, 2);

       Put_line("");

 end INSPECT;

begin

  --for I in 1..200 loop

     COORDINATOR.SCHED;

 --end loop;

end PLANT_SCHED;

Полученные результаты:

В ходе выполнения лабораторной работы были выполнены следующие действия:

  1.  Замена распределения случайных величин в соответствии с Пуассоновским распределением (описано в distribution.adb)
    1.  В ходе выполнения программы процесс выполнения комментируется в окне сообщений.
      1.  Ниже представлен пример рабочего процесса с/без использования мониторов. Полученные результаты свидетельствуют, что программа с разграничением доступа к ресурсу работает стабильнее, надежнее и быстрее.

 Пример результатов:

без мониторов

Starting task on MACH2

Starting task on MACH1

Starting task on MACH3

Task on MACH1 finished

Starting task on MACH1

Task on MACH1 finished

Starting task on MACH1

Task on MACH2 finished, standing after MACH2

Inspection after MACH2 started

Starting task on MACH2

Inspection finished successfuly

Number of finished products           1

Task on MACH1 finished

Starting task on MACH1

Task on MACH1 finished

Starting task on MACH1

Task on MACH3 finished, standing after MACH3

Inspection after MACH3 started

Starting task on MACH3

Inspection finished successfuly

Task on MACH2 finished, standing after MACH2

Number of finished products           2

................................

Task on MACH1 finished

Starting task on MACH1

Task on MACH3 finished, standing after MACH3

Inspection after MACH3 started

Starting task on MACH3

Inspection finished successfuly

Task on MACH1 finished

Starting task on MACH1

Number of finished products         199

Task on MACH2 finished, standing after MACH2

Inspection after MACH2 started

Starting task on MACH2

Inspection finished successfuly

Task on MACH1 finished

Starting task on MACH1

Number of finished products         200

Manufacture full cycle length          10.29

с использованием разграничения доступа к ресурсу:

Starting task on MACH2

Starting task on MACH1

Starting task on MACH3

Task on MACH1 finished

Starting task on MACH1

Task on MACH2 finished, standing after MACH2

Inspection after MACH2 started

Inspection finished successfuly

Starting task on MACH2

Task on MACH1 finished

Starting task on MACH1

Number of finished products           1

Task on MACH3 finished, standing after MACH3

Task on MACH1 finished

Starting task on MACH1

Inspection after MACH3 started

Inspection finished successfuly

Starting task on MACH3

Task on MACH2 finished, standing after MACH2

Number of finished products           2

........................................

Task on MACH3 finished, standing after MACH3

Inspection after MACH3 started

Inspection finished successfuly

Task on MACH1 finished

Starting task on MACH3

Starting task on MACH1

Number of finished products         199

Task on MACH2 finished, standing after MACH2

Task on MACH1 finished

Inspection after MACH2 started

Starting task on MACH2

Inspection finished successfuly

Starting task on MACH1

Number of finished products         200

Manufacture full cycle length          9.60