排队论系统仿真c语言,排队论仿真程序
自己編的單服務M/M/1排隊論仿真程序,僅供參考!可在VC6.0中運行!
#include
#include
#include
#include
#include
typedef unsigned int eventtype;
double minuxexpdistribution(double dt);
typedef struct//this struct is used to regist events!
{
int No;
double time;
eventtype e;//1 arrive;2 start serving;3
leave;
int id;//person of event
int busy;
int quelen;
}eventtable;
int i=1;int j=1;int k=1;
eventtable tmp;int idtmp=1;int event;
eventtable tt={0,0,0,0,0,0};
eventtable?*pEventTable=&tt;
int xx[1000][1000]={0,0};//use a large piece of 0_zeros to seperate
pEventTable and arrive_t_reg!
double a0=0;
double *arrive_t_reg=&a0;
int xxx[1000][10000]={0};
double b0=0;
double *leave_t_reg=&b0;
void main()
{
double
TIMELIMIT,AvgServeTime,AvgArriveInterval;
cout<
simulatin TIMELIMIT:\n";
cin>>TIMELIMIT;
cout<
average serve time :\n";
cin>>AvgServeTime;
cout<
average arrive time interval :\n";
cin>>AvgArriveInterval;
cout<
srand((unsigned)time(NULL));
double t=0;//system clock
ofstream fout("EventTable.txt");
ofstream foutser("ServeTime.txt");
//set the first person
double leave;
double
arrive=minuxexpdistribution(AvgArriveInterval);
(*(arrive_t_reg+j))=arrive;
j++;
event=1;
t=arrive;
//int m=0;
fout<
fout<
fout<
代表事件類型,1為到達,2為開始服務,3為離開,上邊的語句表示,在0.889時刻1到達,在開始服務前,隊長為1.\n";
fout<
"<
"<
"<
foutser<
do
{
switch(event)
{
case 1:
arrive=minuxexpdistribution(AvgArriveInterval);//determine
the time interval of the next commer!
*(arrive_t_reg+j)=t+arrive;
//cout<
j++;
if((*(pEventTable+i-1)).busy==0&&(*(pEventTable+i-1)).quelen==0)
{
tmp.busy=0;
tmp.e=1;
tmp.id=idtmp;
tmp.No=i;
tmp.quelen=1;
tmp.time=*(arrive_t_reg+idtmp);
*(pEventTable+i)=tmp;
fout<
i++;
idtmp=tmp.id;
t=tmp.time;
event=2;
break;
}
if(
(*(pEventTable+i-1)).busy )//the server is busy!
{
tmp.quelen=(*(pEventTable+i-1)).quelen+1;
tmp.busy=1;
tmp.id=idtmp;
tmp.e=1;
tmp.time=t;
tmp.No=i;
*(pEventTable+i)=tmp;
fout<
if(
*(arrive_t_reg+idtmp+1)>*(leave_t_reg+k-1) )//the
person in service will leave before the next
comer!?{
t=*(leave_t_reg+k-1);
event=3;
idtmp=k-1;//???
break;
}
else//the
nearest comer will arrive before the person in service
leaves;
{
idtmp=tmp.id+1;
event=1;
t=*(arrive_t_reg+idtmp);
break;
}
}
case
2://start serve
tmp.busy=1;
tmp.quelen=(*(pEventTable+i-1)).quelen-1;
tmp.e=2;
tmp.id=idtmp;
tmp.No=i;
tmp.time=t;
*(pEventTable+i)=tmp;
fout<
leave=minuxexpdistribution(AvgServeTime);
foutser<
*(leave_t_reg+tmp.id)=t+leave;
k=tmp.id;
k++;
//arrive=minuxexpdistribution(AvgArriveInterval);//determine
time of the next comer
/
fout<
}
double minuxexpdistribution(double dt)
{
//srand((unsigned)time(NULL));
return -log(1-rand()/32767.0)*dt;
}
總結
以上是生活随笔為你收集整理的排队论系统仿真c语言,排队论仿真程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows Server 2016
- 下一篇: Win10下 Java环境变量配置