Смекни!
smekni.com

Моделирование системы массового обслуживания (стр. 3 из 3)

Memo1. ReadOnly: =True;

END

else // вывод в отдельном окне

BEGIN

Form4. Show;

For i: =1 to Turn_Count Do

Turnikets [i]. Lab. Free;

Form4. Memo1. Lines. Add ('Эксперимент №: '+IntToStr (Eksp));

Form4. Memo1. Lines. Add ('Общее время моделирования: '+IntToStr (Time));

Form4. Memo1. Lines. Add ('Прошло зрителей: '+IntToStr (Count_Of_F_People));

Form4. Memo1. Lines. Add ('Из них гостей: '+ IntToStr (G_Count));

Form4. Memo1. Lines. Add ('Максимальная длина очереди: '+IntToStr (Max_Queue));

Form4. Memo1. Lines. Add ('Средняя длина очереди: '+FloatToStrF (AverageQueue,ffFixed,2,2));

Form4. Memo1. Lines. Add (' ');

Form4. Memo1. Lines. Add ('Количество заявок');

For i: =1 to Turn_Count Do

Form4. Memo1. Lines. Add ('Турникет №'+IntToStr (I) +': '+IntToStr (Turnikets [i]. Zayavki));

Form4. Memo1. Lines. Add (' ');

Form4. Memo1. Lines. Add ('Время работы');

For i: =1 to Turn_Count Do

Form4. Memo1. Lines. Add ('Турникет №'+IntToStr (I) +': '+IntToStr (Turnikets [i]. Rabota));

Form4. Memo1. Lines. Add (' ');

Form4. Memo1. Lines. Add ('Время простоя');

For i: =1 to Turn_Count Do

Form4. Memo1. Lines. Add ('Турникет №'+IntToStr (I) +': '+IntToStr (Turnikets [i]. Prostoy));

Form4. Memo1. Lines. Add ('***********************************');

Form4. Memo1. Lines. Add (' ');

Form4. Memo1. Visible: =True;

Form4. Memo1. ReadOnly: =True;

END;

End;

Procedure TForm1. Add_G;

Var

i, Min,Min_i: Integer;

Begin

Min: =Turnikets [1]. Queue_Len;

Min_i: =1;

For i: =2 To Turn_Count Do

Begin

if Turnikets [i]. Queue_Len<Min Then

Begin

Min: =Turnikets [i]. Queue_Len;

Min_i: =i;

End;

End;

Inc (Turnikets [Min_i]. Queue_Len);

If Turnikets [Min_i]. Queue_Len>Max_Queue Then Max_Queue: =Turnikets [Min_i]. Queue_Len;

For i: =Turnikets [Min_i]. Queue_Len DownTo 2 do

Begin

Turnikets [Min_i]. Queue [i]: =Turnikets [Min_i]. Queue [i-1] ;

End;

Turnikets [Min_i]. Queue [1]. Status: =1; // 1-ый в очереди

Turnikets [Min_i]. Queue [1]. T_in_Queue: =0;

if Turnikets [Min_i]. Status=False Then

Turnikets [Min_i]. R_Obsl: =TimeRandom (G_ServeMin,G_ServeMax);

Turnikets [Min_i]. Status: =True;

Inc (G_Count);

End;

Procedure TForm1. Add_4el;

Var

i, Min,Min_i: Integer;

Begin

Min: =Turnikets [1]. Queue_Len;

Min_i: =1;

For i: =2 To Turn_Count Do

Begin

if Turnikets [i]. Queue_Len<Min Then

Begin

Min: =Turnikets [i]. Queue_Len;

Min_i: =i;

End;

End;

Inc (Turnikets [Min_i]. Queue_Len);

If Turnikets [Min_i]. Queue_Len>Max_Queue Then Max_Queue: =Turnikets [Min_i]. Queue_Len;

Turnikets [Min_i]. Queue [Turnikets [Min_i]. Queue_Len]. Status: =0;

Turnikets [Min_i]. Queue [Turnikets [Min_i]. Queue_Len]. T_in_Queue: =0;

if Turnikets [Min_i]. Status=False Then

Turnikets [Min_i]. R_Obsl: =TimeRandom (ServeMin,ServeMax);

Turnikets [Min_i]. Status: =True;

End;

Function TForm1. TimeRandom;

Begin

Result: =Random (Max-Min+1) +Min;

End;

Procedure TForm1. Refresh;

Var

I: Integer;

Begin

For i: = 1 to Ap_Cnt do

Begin

Turnikets [i]. Queue_Len: =0;

Turnikets [i]. T_Obsl: =0;

Turnikets [i]. R_Obsl: =0;

Turnikets [i]. Status: =False;

Turnikets [i]. Zayavki: =0;

Turnikets [i]. Rabota: =0;

Turnikets [i]. Prostoy: =0;

Turnikets [i]. Lab: =TLabel. Create (PageControl1);

Turnikets [i]. Lab. Left: =7;

Turnikets [i]. Lab. Top: =140+i*20;

(PageControl1 as TPageControl). Pages [0]. InsertControl (Turnikets [i]. Lab);

End;

End;

Function TForm1. Zna4_Read;

Var

Zn: Integer;

Begin

Try

Zn: =StrToInt (ET. Text);

Except

ShowMessage ('Значение поля некорректно!!! ');

End;

if Zn<Min Then Zn: =Min;

if Zn>Max Then Zn: =Max;

ET. Text: =IntToStr (Zn);

Result: =Zn;

End;

procedure TForm1. Timer1Timer (Sender: TObject);

Var

I,J: Integer;

// s: string;

begin

Chart1. Series [0]. Clear;

Inc (Time);

Label17. Caption: ='Время моделировния '+IntToStr (Time);

Inc (Time_4el);

Inc (Time_Guest);

inc (k);

// kartinka

if (k=100) and (change=true) then

begin

inc (kartinka);

Image1. Picture. LoadFromFile (s+inttostr (kartinka) +'. jpg');

k: =0;

if kartinka=11 then

kartinka: =1;

end;

if Time_4el=Random_4el Then // Зритель пришел

Begin

Add_4el;

Random_4el: =TimeRandom (ComeMin,ComeMax);

Time_4el: =0;

End;

if Time_Guest=Random_Guest Then // Гость пришел

Begin

Add_G;

Random_Guest: =TimeRandom (G_ComeMin,G_ComeMax);

Time_Guest: =0;

End;

For I: =1 to Turn_Count Do

Begin

Full_Queue_Len: =Full_Queue_Len+Turnikets [i]. Queue_Len;

If Turnikets [i]. Status Then

Begin

Inc (Turnikets [i]. Rabota);

Turnikets [i]. Lab. Caption: ='ТУРНИКЕТ №'+IntToStr (i) +' занят ';

Turnikets [i]. Lab. Caption: =Turnikets [i]. Lab. Caption+' '+'Очередь '+IntToStr (Turnikets [i]. Queue_Len-1);

End

Else

Begin

Inc (Turnikets [i]. Prostoy);

Turnikets [i]. Lab. Caption: ='ТУРНИКЕТ №'+IntToStr (i) +' свободен ';

Turnikets [i]. Lab. Caption: =Turnikets [i]. Lab. Caption+' '+'Очередь '+IntToStr (Turnikets [i]. Queue_Len);

End;

If Turnikets [i]. Status Then

Begin

Inc (Turnikets [i]. T_Obsl);

If Turnikets [i]. T_Obsl=Turnikets [i]. R_Obsl Then // Закончено время обслуживания

Begin

Inc (Turnikets [i]. Zayavki);

Turnikets [i]. T_Obsl: =0;

Inc (Count_Of_F_People);

Dec (Turnikets [i]. Queue_Len);

For J: =1 To Turnikets [i]. Queue_Len Do

Turnikets [i]. Queue [j]: =Turnikets [i]. Queue [j+1] ;

if Turnikets [i]. Queue_Len=0 Then // больше никого нет. Ожидание

Begin

Turnikets [i]. Status: =False;

Turnikets [i]. R_Obsl: =0;

End

Else

Begin

If Turnikets [i]. Queue [1]. Status=0 Then

Begin

Turnikets [i]. R_Obsl: =TimeRandom (ServeMin,ServeMax);

End

Else

Begin

Turnikets [i]. R_Obsl: =TimeRandom (G_ServeMin,G_ServeMax);

End;

End;

End;

End;

Chart1. Series [0]. Add (turnikets [i]. Zayavki,'');

if Edit12. Visible=true then

ProgressBar1. Position: =Time;

End;

If ( (Edit12. Visible=true) and (Time=SetTime)) or // КОНЕЦ!!!

(Count_Of_F_People=People_Count) Then

Begin

Timer1. Enabled: =False;

Button2. Enabled: =false;

ToolButton1. Enabled: =false;

ToolButton2. Enabled: =true; // Save

N21. Enabled: =true;

Button3. Enabled: =true;

AverageQueue: =Full_Queue_Len/ (Time*Turn_Count);

Show_Report;

End;

Label_Count_4el. Font. Color: =ClBlue;

Label_Count_4el. Caption: ='Прошло человек '+IntToStr (Count_Of_F_People);

end;

procedure TForm1. FormCreate (Sender: TObject);

begin

Randomize;

Time: =0;

G_Count: =0;

Turn_Count: =0;

Count_Of_F_People: =0;

Max_Queue: =0;

Full_Queue_Len: =0;

AverageQueue: =0;

Time_4el: =0;

Random_4el: =0;

Time_Guest: =0;

Random_Guest: =0;

PageControl1. Pages [1]. TabVisible: =false;

PageControl1. TabIndex: =0;

end;

procedure TForm1. MenuItem4Click (Sender: TObject);

begin

Close;

end;

procedure TForm1. ToolButton3Click (Sender: TObject);

begin

Close;

end;

procedure TForm1. N1Click (Sender: TObject);

begin

Change: =true;

N1. Checked: =true;

N1. Default: =true;

N2. Checked: =false;

N2. Default: =false;

end;

procedure TForm1. N2Click (Sender: TObject);

begin

change: =false;

N2. Checked: =true;

N2. Default: =true;

N1. Checked: =false;

N1. Default: =false;

end;

procedure TForm1. CheckBox1Click (Sender: TObject);

begin

if CheckBox1. Checked=true

then

begin

Edit12. Visible: =true;

ComboBox1. Visible: =true;

end

else

begin

Edit12. Visible: =false;

ComboBox1. Visible: =false;

end;

end;

procedure TForm1. Na4aloExecute (Sender: TObject);

begin

Inc (Eksp);

FormCreate (Button1. NewInstance);

ComeMin: =Zna4_READ (Edit2,1, 20);

ComeMax: =Zna4_Read (Edit3,ComeMin,ComeMin+50);

ServeMin: =Zna4_READ (Edit4,1, 20);

ServeMax: =Zna4_Read (Edit5,ServeMin,ServeMin+50);

G_ComeMin: =Zna4_READ (Edit6,1, 200);

G_ComeMax: =Zna4_Read (Edit7,ComeMin,ComeMin+200);

G_ServeMin: =Zna4_READ (Edit9,1,100);

G_ServeMax: =Zna4_Read (Edit8,ServeMin,ServeMin+100);

Turn_Count: =Zna4_Read (Edit10,1,100);

People_Count: =Zna4_Read (Edit1,10,10000);

Speed: =Zna4_Read (Edit11,1,1000);

Timer1. Interval: =1000 div Speed;

Refresh (Turn_Count);

Random_4el: =TimeRandom (ComeMin,ComeMax);

Random_Guest: =TimeRandom (G_ComeMin,G_ComeMax);

Timer1. Enabled: =True;

change: =true;

if Edit12. Visible=true then

begin

if ComboBox1. ItemIndex=0 then

SetTime: =Zna4_READ (Edit12,10,43200);

if ComboBox1. ItemIndex=1 then

SetTime: =Zna4_READ (Edit12,1,720) *60;

if ComboBox1. ItemIndex=2 then

SetTime: =Zna4_READ (Edit12,1,12) *3600;

end;

ProgressBar1. Position: =0;

if Edit12. Visible=true then

ProgressBar1. Max: =SetTime

else

ProgressBar1. Max: =0;

ToolButton2. Enabled: =false;

Button3. Enabled: =false;

N21. Enabled: =false;

ToolButton1. Enabled: =true;

Button2. Enabled: =true;

end;

procedure TForm1. StopExecute (Sender: TObject);

begin

Timer1. Enabled: =false;

show_report;

ToolButton2. Enabled: =true;

Button3. Enabled: =true;

N21. Enabled: =true;

ToolButton1. Enabled: =false;

Button2. Enabled: =false;

end;

procedure TForm1. MenuItem11Click (Sender: TObject);

begin

Form2. Show;

end;

procedure TForm1. SaveExecute (Sender: TObject);

begin

If SaveDialog1. Execute then

Memo1. Lines. SaveToFile (SaveDialog1. FileName);

end;

procedure TForm1. createExecute (Sender: TObject);

var

i: byte;

begin

if Button2. Enabled=true then

for i: =1 to Turn_Count do

Turnikets [i]. Lab. Free;

// Turnikets [i]. Lab. Caption: ='';

Label17. Caption: ='';

Label_Count_4el. Caption: ='';

Randomize;

Time: =0;

G_Count: =0;

Turn_Count: =0;

Count_Of_F_People: =0;

Max_Queue: =0;

Full_Queue_Len: =0;

AverageQueue: =0;

Time_4el: =0;

Random_4el: =0;

Time_Guest: =0;

Random_Guest: =0;

Refresh (Turn_Count);

Timer1. Enabled: =false;

for i: =1 to Turn_Count do

Turnikets [i]. Lab. Visible: =false;

ProgressBar1. Position: =0;

Chart1. Series [0]. Clear;

end;

procedure TForm1. SpeedButton1Click (Sender: TObject);

begin

PageControl1. Pages [1]. TabVisible: =false;

PageControl1. ActivePage: =PageControl1. Pages [0] ;

end;

procedure TForm1. SettingsExecute (Sender: TObject);

begin

Form3. Show;

end;

procedure TForm1. VisibleSettingsExecute (Sender: TObject);

begin

PageControl1. Pages [1]. TabVisible: =true;

PageControl1. TabIndex: =1;

end;

procedure TForm1. FormShow (Sender: TObject);

begin

s: =GetCurrentDir+'&bsol;';

end;

procedure TForm1. HelpExecute (Sender: TObject);

begin

winhelp (Form1. Handle,'справка. hlp',help_context,1);

end;

end.