Exemplo n.º 1
0
void Bank_simulation(int CloseTime){
	//银行业务模拟,统计一天内客户在银行的逗留时间
	//全局变量
	static Event en;//事件表
	static EvenList ev;//事件
	static LinkQueue q[5];//4个客户列队
	static QElemType customer;//客户记录
	static int TotalTime,CustomerNum;//累计逗留时间,客户数
	//变量结束
	EvenList p,e;
	OpenForDay(TotalTime,CustomerNum,en,ev,q);
	while(!ListEmpty(ev)){
		e=GetHead(ev);
		DelFirst(e,p);
		
		en=GetCurElem(p);

		if(en.NType==0)
			CustomerArrived(CloseTime,CustomerNum,en,ev,q);
		else CustomerDeparture(en,ev,q,customer,TotalTime);

		if(TotalTime>CloseTime)break;
	}
	printf("%0.2f\n",(float)TotalTime/CustomerNum);
}
Exemplo n.º 2
0
 void Bank_Simulation()
 {
   Link p;
   OpenForDay(); // 初始化
   while(!ListEmpty(ev))
   {
     DelFirst(ev,GetHead(ev),p);
     en.OccurTime=GetCurElem(p).OccurTime;
     en.NType=GetCurElem(p).NType;
     if(en.NType==Qu)
       CustomerArrived(); // 处理客户到达事件
     else
       CustomerDeparture(); // 处理客户离开事件
   } // 计算并输出平均逗留时间
   printf("顾客总数:%d, 所有顾客共耗时:%d分钟, 平均每人耗时: %d分钟\n",CustomerNum,TotalTime,TotalTime/CustomerNum);
 }
Exemplo n.º 3
0
 void Bank_Simulation()
 { // 银行业务模拟函数
   Link p;
   OpenForDay(); // 初始化事件表ev且插入第1个到达事件,初始化队列
   while(!ListEmpty(ev)) // 事件表ev不空
   {
     DelFirst(ev,ev.head,p); // 删除事件表ev的第1个结点,并由p返回其指针,在bo2-6.cpp中
 //  if(p->data.OccurTime<50) // 输出前50分钟内发生的事件到文件d.txt中
 //    fprintf(fp,"p->data.OccurTime=%3d p->data.NType=%d\n",p->data.OccurTime,p->data.NType);
     en.OccurTime=GetCurElem(p).OccurTime; // GetCurElem()在bo2-6.cpp中,返回p->data(ElemType类型)
     en.NType=GetCurElem(p).NType;
     if(en.NType==Qu) // 到达事件
       CustomerArrived(); // 处理客户到达事件
     else // 由某窗口离开的事件
       CustomerDeparture(); // 处理客户离开事件
   } // 计算并输出平均逗留时间
   printf("窗口数=%d 两相邻到达的客户的时间间隔=0~%d分钟 每个客户办理业务的时间=1~%d分钟\n",Qu,Khjg,Blsj);
   printf("客户总数:%d, 所有客户共耗时:%ld分钟,平均每人耗时:%d分钟,",CustomerNum,TotalTime,TotalTime/CustomerNum);
   printf("最后一个客户离开的时间:%d分\n",en.OccurTime);
 }