unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Const MaxSize=MaxInt;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
Edit2: TEdit;
Label4: TLabel;
Edit3: TEdit;
Label5: TLabel;
Label6: TLabel;
Edit4: TEdit;
Label7: TLabel;
Edit5: TEdit;
Label8: TLabel;
Label9: TLabel;
Edit6: TEdit;
Label10: TLabel;
Edit7: TEdit;
Label11: TLabel;
Label12: TLabel;
Edit8: TEdit;
Label13: TLabel;
Edit9: TEdit;
Label14: TLabel;
Label15: TLabel;
Edit10: TEdit;
Label17: TLabel;
Label16: TLabel;
Edit11: TEdit;
Label18: TLabel;
procedure Button1Click(Sender: TObject);
private
public
end;
terminal = record
time:byte;
inwork: boolean;
end;
computer = record
time:byte;
inwork: boolean;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure compare(var t1,t2,t3:terminal);
var a:array[1..3]of integer;
k:integer;
begin
a[1]:=t1.time;
a[2]:=t2.time;
a[3]:=t3.time;
if a[3] if a[2] case k of
1: if not t1.inwork then t1.inwork:=true else
if (t3.time begin
if not t3.inwork then t3.inwork:=true
else t2.inwork:=true;
end
else
begin
if not t2.inwork then t2.inwork:=true
else t3.inwork:=true;
end;
2: if not t2.inwork then t2.inwork:=true else
if (t3.time begin
if not t3.inwork then t3.inwork:=true
else t1.inwork:=true;
end
else
begin
if not t1.inwork then t1.inwork:=true
else t3.inwork:=true;
end;
3: if not t3.inwork then t3.inwork:=true else
if (t2.time begin
if not t2.inwork then t2.inwork:=true
else t1.inwork:=true;
end
else
begin
if not t1.inwork then t1.inwork:=true
else t2.inwork:=true;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var users:array[1..MaxSize] of byte;
terminal1:array[1..MaxSize] of terminal;
terminal2:array[1..MaxSize] of terminal;
terminal3:array[1..MaxSize] of terminal;
computer1, computer2: computer;
i,j,k,l,otkaz:integer;
Count,TimeOfWorkOfComputer1,TimeOfWorkOfComputer2,TimeUser,
DeltaTimeUser,TimeTerminal1,DeltaTimeTerminal1,TimeTerminal2,
DeltaTimeTerminal2,TimeTerminal3,DeltaTimeTerminal3: integer;
begin
Count:= strtoint(edit1.Text);
TimeOfWorkOfComputer1:= strtoint(edit10.Text);
TimeOfWorkOfComputer2:= strtoint(edit11.Text);
TimeUser:= strtoint(edit8.Text);
DeltaTimeUser:= strtoint(edit9.Text);
TimeTerminal1:= strtoint(edit2.Text);
DeltaTimeTerminal1:= strtoint(edit3.Text);
TimeTerminal2:= strtoint(edit4.Text);
DeltaTimeTerminal2:= strtoint(edit5.Text);
TimeTerminal3:= strtoint(edit6.Text);
DeltaTimeTerminal3:= strtoint(edit7.Text);
randomize;
for i:=1 to Count do
begin
users[i]:=TimeUser+random(DeltaTimeUser*2)-DeltaTimeUser;
terminal1[i].time:=TimeTerminal1+random(2*DeltaTimeTerminal1)-DeltaTimeTerminal1;
terminal1[i].inwork:=false;
terminal2[i].time:=TimeTerminal2+random(2*DeltaTimeTerminal2)-DeltaTimeTerminal2;
terminal2[i].inwork:=false;
terminal3[i].time:=TimeTerminal3+random(2*DeltaTimeTerminal3)-DeltaTimeTerminal3;
terminal3[i].inwork:=false;
end;
computer1.time:=TimeOfWorkOfComputer1;
computer1.inwork:=false;
computer2.time:=TimeOfWorkOfComputer2;
computer2.inwork:=false;
i:=1;
j:=1;
k:=1;
l:=1;
otkaz:=0;
while (i<=Count) do
begin
dec(users[i]);
if (users[i]=0) then
begin
if (terminal1[j].inwork and terminal2[k].inwork and terminal3[l].inwork) then inc(otkaz)
else compare(terminal1[j],terminal2[k],terminal3[l]);
inc(i);
end;
if terminal1[j].inwork then dec(terminal1[j].time);
if terminal2[k].inwork then dec(terminal2[k].time);
if terminal3[l].inwork then dec(terminal3[l].time);
if computer1.inwork then dec(computer1.time);
if computer2.inwork then dec(computer2.time);
if (terminal1[j].time=0) then
if not computer1.inwork then
begin
inc(j);
computer1.inwork:=true;
end
else inc(terminal1[j].time);
if (terminal2[k].time=0) then
if not computer1.inwork then
begin
inc(k);
computer1.inwork:=true;
end
else inc(terminal2[k].time);
if (terminal3[l].time=0) then
if not computer2.inwork then
begin
inc(l);
computer2.inwork:=true;
end
else inc(terminal3[l].time);
if (computer1.time=0) then
begin
computer1.time:=TimeOfWorkOfComputer1;
computer1.inwork:=false;
end;
if (computer2.time=0) then
begin
computer2.time:=TimeOfWorkOfComputer2;
computer2.inwork:=false;
end;
end;
label1.Caption:='Вероятность отказа = '+inttostr(otkaz)+' из '+inttostr(Count)+' ('+floattostr(round(100*otkaz/count))+'%)';
end;
end.