| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1199 人关注过本帖
标题:M/G/1排队系统的仿真
只看楼主 加入收藏
zhuheng1986
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-20
收藏
 问题点数:0 回复次数:2 
M/G/1排队系统的仿真

有哪位高手指教一下 如何编程实现这个系统啊 老师的要求是 M/G/1排队系统 任一时刻看到系统的队长和一个顾客到来时看见的队长 与他(她)离开时看到的队长 三者的平稳分布相等 我搜了不少关于理发店的程序 但是M/G/1排队系统 是单服务台服务系统
有高手经过请多多指教 本人不胜感激

搜索更多相关主题的帖子: 系统 仿真 排队 队长 顾客 
2006-05-20 12:40
zinking
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:35
帖 子:916
专家分:0
注 册:2004-12-5
收藏
得分:0 
今天高兴,呵呵,给你敲敲代码吧呵呵
[CODE]


/*
BANK CUSTOMER SIMULATOR0.0
FROM SOFTWARE DESIGER BOOK
COPY BY ZINKING
200605021
*/


#include<stdio.h>
#include<stdlib.h>
#define CLOSETIME 10000
#define M 3
typedef struct QueueNode{
int arrivetime;
int duration;
struct QueueNode* next;
}QueueNode;
typedef struct QueueHeader{
QueueNode *front,*rear;
int length;
}QueueHeader;
typedef struct EventNode{
int occurTime;
int eventType;
struct EventNode* next;
}EventNode;
typedef struct EventList{
strcut EventNode *front,*rear;
int eventNum;
}EventList;

QueueHeader q[M+1];
EventList *eventlst;
int seed=300;
int generate(EventNode **p)
{
*p=(EventNode*)malloc(sizeof(EventNode));
if(!(*p))
{
printf("allocation error!");
return -1;
}
return 0;
}

void InsertEvent(EventList *eventlst,int occurTime,int etype)
{
EventNode *p,*q,*qre;
p=(EventNode*)malloc(sizeof(EventNode));
p->occurTime=occurTime;
p->eventType=etype;
eventlst->eventNum++;
q=eventlst->front;
qre=NULL;
while(q&&occurTime>q->occurTime)
{
qre=q;
q=q->next;
}
if(!qre)
{
p->next=eventlst->front;
eventlst->front=p;
}
else
{
p->next=q;
qre->next=p;
}
if(eventlst->eventNum==1)eventlst->rear=p;
}

void DeleteEvent(EventList* eventlst,EventNode** event)
{
EventNode *p;
p=eventlst->front;
eventlst->front=p->next;
if(--eventlst->eventNum<1)
event->rear=eventlst->front;
*event=p;
}

void EnQueue(QueueHeader* swindow,int t1,int t2)
{
QueueNode* p;
p=(QueueNode*) malloc(sizeof(QueueNode));
p->arrivetime=t1;p->duration=t2;
swindow->length++;
if(swindow->length==1)
{
p->next=NULL;
swindow->front=p;
swindow->rear=p;
}
else
{
p->next=swindow->rear->next;
swindow->rear->next=p;
swindow->rear=p;
}
}

void DeQueue(QueueHeader* swindow,QueueNode* f)
{
QueueNode *p;
if (swindow->length>0)
{
f->arrivetime=swindow->front->arrivetime;
f->duration=swindow->front->duration;
p=swindow->front;
swindow->front=swindow->front->next;
swindow->length--;
if(swindow->length==0) swindow->rear=NULL;
free(p);
}
}

void random(int* durtime,int* intervaltime)
{
*durtime=rand()+1;
*intervaltime=rand()+1;
}

int rand()
{
int k;
k=(int)(((double)seed/32767)*10000)%29;
sed=(13107*seed+6553)%32767;
return k;
}
int Minlength()
{
int minx,k,i;
minx=q[1].length;
k=1;
for(i=2;i<M+1;++i)
if(q[i].length<minx) {minx=q[i].length;k=i}
return k;
}


int main()
{
int durtime,interval,totaltime=0;
int i,c,count=0;
QueueNode f;
EventNode *pe,*event;
eventlst(EventList*)malloc(sizeof(EventList));
if(eventlst==NULL)return 0;
if(generate(&pe)==-1)return 1;
pe->occurTime=0;
pe->eventType=0;
pe->next=NULL;
eventlst->front=pe;
evenlst->rear=pe;
eventlst->eventNum=1;
for(i=1;i<M+1;i++)
{
q[i].front=q[i].rear=NULL;
q[i].length=0;
}

while(eventlst->eventNum>0)
{
DeleteEvent(eventlst,&event);
if (event->eventType==0)
{
printf("A client entered!");
count++;
random(&drtime,&interval);
if((event->occurTime+interval)<CLOSETIME)
InsetEvent(eventlst,event->occurTime+interval,0);
c=Minlength();
EnQueue(&q[c],event->occurTime,durtime);
printf("Insert to window %d",c);
printf(" (arrive time: %d duration: %d )\n",event->occurTime,durtime);
if(q[c].length==1)
InsetEvent(eventlst,event->occurTime+durtime,c);
}
else
{
i=event->eventType;
DeQueue(&q[i],&f);
printf("sevice window %d: A client left! \n",i);
totaltime+=event->occurTime-f.arrivetime;
if(q[i].length!=0)
InsertEvent(enventlst,event->occurtime+q[i].front->duration,i);

}
}
printf("\n Total Customer: %d\n",count);
printf("Average duration: %d\n",totaltime/count);

return 2;
}



[/CODE]

http://kongfuziandlife. http://codeanddesign.
2006-05-21 10:51
菜鸟上路
Rank: 4
等 级:贵宾
威 望:14
帖 子:1120
专家分:0
注 册:2006-3-21
收藏
得分:0 
这运行错误啊

2006-05-21 11:20
快速回复:M/G/1排队系统的仿真
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037433 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved