IV. Практическая часть
4.1. Графическое решение модели канальной подсистемы управления базами данных.
Листинг:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, TeeProcs, TeEngine, Chart, Series;
type
TForm1 = class(TForm)
Chart1: TChart;
Series1: TLineSeries;
Series2: TLineSeries;
Series3: TLineSeries;
Series4: TLineSeries;
Series5: TLineSeries;
Panel1: TPanel;
D_L: TRadioButton;
D_n: TRadioButton;
Lambda: TLabeledEdit;
D_m: TRadioButton;
Mu: TLabeledEdit;
_n: TLabeledEdit;
Button1: TButton;
Series1a: TLineSeries;
Series2a: TLineSeries;
Series3a: TLineSeries;
Series4a: TLineSeries;
Series5a: TLineSeries;
Procedure Draw_n_Lmbd_fix(ASeries:TChartSeries;BSeries:TChartSeries;Lambda:real);
Procedure Draw_mu_Lmbd_fix(ASeries:TChartSeries;BSeries:TChartSeries;Lambda:real);
Procedure Draw_Lmbd_n_fix(ASeries:TChartSeries;BSeries:TChartSeries;N:integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function fact(n:integer):real;
var i:integer;
Rez:real;
begin
Rez:=1;
if n>=2 then
for i:=2 to n do
Rez:=Rez*i;
fact:=Rez;
end;
function Erlang(Lambda:real;Mu:real;N:integer):real;
var j:integer;
Rez:real;
begin
Rez:=0;
for j:=0 to N do
Rez:=Rez + exp(j*ln(Lambda/Mu))/ fact(j);
Erlang:= exp(N*ln(Lambda/Mu))/ fact(N)/Rez;
end;
Procedure TForm1.Draw_n_Lmbd_fix(ASeries:TChartSeries;BSeries:TChartSeries;Lambda:real);
Var t:Longint;
P,M:real;
Begin
ASeries.Clear;
BSeries.Clear;
M:=StrToFloat(Mu.Text);
for t:=1 to StrToInt(_n.Text) do
Begin
P:=1-Erlang(Lambda,M,t);
ASeries.AddXY(t,P,'');
BSeries.AddXY(t,Lambda*P/M/t,'');
end;
End;
Procedure TForm1.Draw_mu_Lmbd_fix(ASeries:TChartSeries;BSeries:TChartSeries;Lambda:real);
Var t,n:Longint;
M,P:real;
Begin
ASeries.Clear;
BSeries.Clear;
n:=StrToInt(_n.Text);
for t:=0 to 30 do
Begin
M:=StrToFloat(Mu.Text)/30*t+0.0001;
P:=1-Erlang(Lambda,M,n);
ASeries.AddXY(M,P,'');
BSeries.AddXY(M,Lambda*P/M/n,'');
end;
End;
Procedure TForm1.Draw_Lmbd_n_fix(ASeries:TChartSeries;BSeries:TChartSeries;N:integer);
Var t:Longint;
L,M,P:real;
Begin
M:=StrToFloat(Mu.Text);
ASeries.Clear;
BSeries.Clear;
for t:=0 to 30 do
Begin
L:=StrToFloat(Lambda.Text)/30*t+0.0001;
P:=1-Erlang(L,M,N);
ASeries.AddXY(L,P,'');
BSeries.AddXY(L,L*P/M/N,'');
end;
End;
procedure TForm1.Button1Click(Sender: TObject);
var i:Extended;
j:real;
begin
if (_n.Text<>'') and (Mu.Text<>'') and (StrToFloat(Mu.Text)<>0) and (Lambda.Text<>'') then
if D_n.Checked=True then begin
Draw_n_Lmbd_fix(Series1,Series1a,0.1); Series1.Title:='Lm=0.1 Pо/КЗ';
Draw_n_Lmbd_fix(Series2,Series2a,0.25); Series2.Title:='Lm=0.25 Pо/КЗ';
Draw_n_Lmbd_fix(Series3,Series3a,0.5); Series3.Title:='Lm=0.5 Pо/КЗ';
Draw_n_Lmbd_fix(Series4,Series4a,1); Series4.Title:='Lm=1 Pо/КЗ';
Draw_n_Lmbd_fix(Series5,Series5a,5); Series5.Title:='Lm=5 Pо/КЗ';
Chart1.BottomAxis.Title.Caption:='число каналов';
Chart1.BottomAxis.Increment:=1;
_n.Enabled:=True;
Mu.Enabled:=True;
Lambda.Enabled:=False;
end
else if D_m.Checked=True then begin
Draw_mu_Lmbd_fix(Series1,Series1a,0.1); Series1.Title:='Lm=0.1 Pо/КЗ';
Draw_mu_Lmbd_fix(Series2,Series2a,0.25); Series2.Title:='Lm=0.25 Pо/КЗ';
Draw_mu_Lmbd_fix(Series3,Series3a,0.5); Series3.Title:='Lm=0.5 Pо/КЗ';
Draw_mu_Lmbd_fix(Series4,Series4a,1); Series4.Title:='Lm=1 Pо/КЗ';
Draw_mu_Lmbd_fix(Series5,Series5a,5); Series5.Title:='Lm=5 Pо/КЗ';
Chart1.BottomAxis.Title.Caption:='время обслуживания';
Chart1.BottomAxis.Increment:=0.1;
_n.Enabled:=True;
Mu.Enabled:=True;
Lambda.Enabled:=False;
end
else begin
Draw_Lmbd_n_fix(Series1,Series1a,2); Series1.Title:='N=2 Pо/КЗ';
Draw_Lmbd_n_fix(Series2,Series2a,5); Series2.Title:='N=5 Pо/КЗ';
Draw_Lmbd_n_fix(Series3,Series3a,10); Series3.Title:='N=10 Pо/КЗ';
Draw_Lmbd_n_fix(Series4,Series4a,20); Series4.Title:='N=20 Pо/КЗ';
Draw_Lmbd_n_fix(Series5,Series5a,50); Series5.Title:='N=50 Pо/КЗ';
Chart1.BottomAxis.Title.Caption:='плотность поступления заявок';
Chart1.BottomAxis.Increment:=0.1;
_n.Enabled:=False;
Mu.Enabled:=True;
Lambda.Enabled:=True;
end;
end;
end.
Тест программы:

Рис. 4.1