home *** CD-ROM | disk | FTP | other *** search
- Program EX_0506;
- {Listing 11P - see documentation in TUTOR.SSS }
-
- uses crt, SSS;
- { For Pascal other than Turbo/Quick erase above line }
-
- const
- ARRIVL = 1;
- STARTA = 2;
- ENDACT = 3;
- NEXTAC = 4;
-
- FINAL = 3;
-
- type
- bool_arr = array[1..3] of Boolean;
- real_arr = array[1..3] of real;
-
- { For MS Pascal $include:'SSSP1.H' }
-
- var
- busy, block : bool_arr;
- defect : real_arr;
- i, ecode : integer;
- statn, rewkn: integer;
- serial : real;
- debugf : Boolean;
- ch : char;
-
- { For MS Pascal $include:'SSSP2.H' }
-
- procedure prime;
- begin
- debugf := false;
- serial := 1.0;
- INIQUE(3,2,3);
- INISTA(1,'Prod t #1',0,0,0,0);
- INISTA(2,'Prod t #2',0,0,0,0);
- INISTA(3,'Prod t #3',0,0,0,0);
- CREATE(0.0, 0);
- SIMEND(6.0);
-
- for i:=1 to 3 do
- begin
- busy[i] := false;
- block[i] := false;
- end;
- defect[1] := 0.3;
- defect[2] := 0.2;
- defect[3] := 0.1;
- end;
-
- procedure deciph(i: integer);
- begin
- statn := i mod 4; (* station number *)
- rewkn := i shr 2; (* how many reworks *)
- end;
-
- procedure triggr(i: integer);
- begin
- REMVFQ(i, 1);
- SCHED(0, NEXTAC, IDE);
- if i > 1 then CREATE(0, i - 1);
- end;
-
- procedure unblk(statn: integer);
- begin
- DISPOS;
- if block[statn] = true then
- begin
- if ((NQ(statn) > 0) and (busy[statn] = false)) then
- triggr(statn);
- block[statn] := false;
- end;
- end;
-
- begin
-
- prime;
-
- repeat
- ecode := NEXTEV;
- if ecode > 0 then
- begin
- case ecode of
-
- ARRIVL: begin
- if IDE > 0 then unblk(IDE) else
- begin
- CREATE(EX(0.5), 0);
- SETA(1,RN(0.25, 0.05));
- SETA(2,serial);
- serial := serial + 1.0;
- SCHED(0, NEXTAC, 1);
- end;
- end;
-
- NEXTAC: begin
- deciph(IDE);
- if debugf then write('At ',T:6:2,' # ',
- A(2):2:0,' for ',A(1):4:2,
- ' h. to station # ',statn,
- ' for ',rewkn,' rework');
- if busy[statn] or block[statn] then
-
- begin
- QUEUE(statn, 0);
- if debugf then writeln(' and waits');
- if ((NQ(statn) > 4) and (statn > 1))
- then block[statn - 1] := true;
- end else
-
- begin
- SCHED(0, STARTA, IDE);
- if debugf then
- begin
- writeln(' and processed');
- ch := ReadKey;
- if ch = 'q' then halt;
- end;
- end;
- end;
-
- STARTA: begin
- deciph(IDE);
- if debugf then writeln('At ',T:6:2,
- ' # ',A(2):2:0,' starts work');
- if rewkn = 0 then TALLY(statn, 1);
- busy[statn] := true;
- SCHED(A(1), ENDACT, IDE);
- end;
-
- ENDACT: begin
- deciph(IDE);
- TALLY(statn, 0);
- if debugf then write('At ',T:6:2,
- ' # ',A(2):2:0,' ends work');
- busy[statn] := false;
- if RA > defect[statn] then
-
- begin
- if statn = FINAL then
- begin
- DISPOS;
- if debugf then
- writeln(' and discharged');
- end else
-
- begin
- SETA(1, RN(0.25, 0.05));
- SCHED(0, NEXTAC, statn + 1);
- if debugf then
- writeln(' and goes on');
- end;
- end else
-
- begin
- SETA(1, A(1)/2);
- SCHED(0, NEXTAC,
- statn + 4*(rewkn + 1));
- if debugf then
- writeln(' and recycled');
- end;
-
- if debugf then writeln('At ',T:6:2,
- ' ',NQ(statn),' are waiting at ',statn);
- if NQ(statn) > 0 then triggr(statn);
- end;
- end;
- end;
- until ecode = 0;
-
- SUMRY('');
-
- end.