原创PS型节点排队论代码,1.遇到类型转换不成功,2.声明报错了。。讨论解决。。
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
Edit2: TEdit;
Label4: TLabel;
Edit3: TEdit;
Label5: TLabel;
Edit4: TEdit;
Label6: TLabel;
Edit5: TEdit;
Label7: TLabel;
Edit6: TEdit;
Label8: TLabel;
Edit7: TEdit;
Label9: TLabel;
Edit8: TEdit;
Label10: TLabel;
Edit9: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
Procedure GetOneLivingGuest(var GuestTime:double;var GuesttoNode:double);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
NumofNode,NumofCusmtor,NumofServer,NumofCustmer,Buf:integer;
f,y,now,v,overtime,servertime:double;
k,guest:integer;
Tnow,Tovertime,GuestTimes:double;
Tserver,Dbuffer,curguest,GuestNodes:integer;
implementation
{$R *.dfm}
function InitialNode(NumofNode,NumofCustmer,NumofServer,Buf:integer):Boolean;
begin
if (NumofNode>=1)and(NumofCustmer>=1)and(NumofServer>=1)and(Buf>=0) then
Result:=True
else
Result:=False;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
for i:=1 to 10 do
//begin
Randomize ; //初始化随机数发生器
i:=Random(10);
//label1.Caption:=IntToStr(i);
f:=i/10;
end;
//end;
function AppendOneGuest( y:double;guest:integer):Boolean;//一个顾客到达
begin
Randomize ;
y:=FloatToStr(random(f)); // 记录顾客到来时间点
NumofCustmer:=guest+1; //顾客总数加1
NumofNode:=NumofNode+1; //节点数加1
NumofServer:=NumofServer-1;
Buf:=Buf-1;
if Buf>=0 then //服务台数加1
Result:=True
else
Result:=False;
end;
function DrivetoNextEvent(now,v,overtime,servertime:double):real; //推进节点的下一事件
begin
now:=y;
v:=5/NumofCustmer;
servertime:= NumofServer/v;
overtime:=y+servertime;
if overtime>y+servertime then
NumofNode:=NumofNode+1
else
NumofCustmer:=NumofCustmer+1;
begin
now:=overtime;
end;
end;
function GetCurTime(Tnow:double):real;
begin Tnow:=now;
end;
function GetNextTime(Tovertime: double):real;
begin Tovertime:=overtime;
end;
function GetNumofServer(Tserver :integer):integer;
begin Tserver:= NumofServer;
end;
function GetSizeofBuffer(Dbuffer:integer):integer;
begin Dbuffer:= Buf;
end;
function GetNumofGuest(curguest: integer):integer;
begin if Tnow>=Tovertime then
curguest:=guest-1
else curguest:=guest+1;
end;
Procedure TForm1.GetOneLivingGuest(var GuestTime:double;var GuesttoNode:double);
var GuestTimes,GuestNodes:double;
begin
GuestTimes:=GuestTime;
GuestNodes:=GuesttoNode;
GuestTime:=Tnow;
if Tnow>=Tovertime then
GuestNodes:=0
//ShowMessage('服务完毕')
else GuestNodes:=1 ;
//showMessage('正在服务');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//Randseed:=i+1; //每次点击按钮均重新定义随机数种子
//i:=Random(10);
//label1.Caption:=IntToStr(i);
k:=1;
Tserver:=2;
Buf:=50;
guest:=1;
GuestNodes:=1;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Tserver:=Tserver+k;
Buf:=Buf-k;
guest:=guest+k;
GuestNodes:=GuestNodes+k;
Edit1.Text:=FloatToStr(Tnow);
Edit2.Text:=FloatToStr(Tovertime);
Edit3.Text:=IntToStr(Tserver);
Edit4.Text:=IntToStr(Dbuffer);
Edit5.Text:=IntToStr(curguest);
Edit6.Text:=FloatToStr(GuestTimes);
Edit7.Text:=IntToStr(GuestNodes);
Edit8.Text:=FloatToStr(v);
Edit9.Text:=FloatToStr(NumofNode);
k:=k+1;
if k>20 then
//Timer1.Enabled:= False;
if k>20 then
ShowMessage('仿真完毕!');
//对程序的流程做简单的处理。
end;
end.
问题是