数据结构——离散事件模拟
来源:互联网 发布:linux ftp登录 编辑:程序博客网 时间:2024/06/05 15:44
- 算法:
假设某银行有4个窗口对外接待客户,从早晨银行开门起不断有客户进入银行。由于每个窗口在某个时刻只能接待一个客户,因此在客户人数众多时需要在每个窗口前顺次排队,对于刚进入银行的客户,如果某个窗口的业务员正空闲,则可上前输业务;反之,若4个窗口均有客户所占,他便会排在人数最少的队伍后面。编制一个程序模拟银行的这种业务活动并计算一天中客户在银行的平均逗留时间。
typedef struct{ int OccurTime;//事件发生时刻 int NType;//事件类型,0表示到达事件,1至4表示四个窗口离开事件}Event,ElemType;//事件类型,有序链表LinkList的数据元素类型typedef LinkList EventList//事件链表类型,定义为有序链表typedef struct{ int ArrivalTime;//到达时刻 int Duration;//办理事务所需时间}QElemType;//队列的数据元素类型EventList ev; //事件链表Event en; //事件结点LinkQueue q[5]; //客户队列QElemType customer; //客户记录int TotalTime,CustomerNum; //累计逗留时间 ,累计客户数量int cmp(Event a, Event b);//依事件a的发生时刻<或=或>事件b的发生时刻分别返回-1或0或1void OpenDay(){ TotalTime=0; CustomerNum=0; InitList(ev); //初始化事件链表 en.OccurTime=0; //设置第一个客户到达事件 en.NType=0; //插入事件 OrderInsert(ev,en,cmp); //初始化任务队列 for(i=1;i<5;i++){ InitQueue(q[i]); } }//客户到达void CustomerArrived(){ ++CustomerNum; //增加客户数量 Random(durtime,intertime); t=en.OccurTime+intertime; if(t<CloseTime) OrderInsert(ev,(t,0),cmp); i=Minimum(q); Enqueue(q[i],(en.OccurTime,durtime)); if(QueueLength(q[i])==1) OrderInsert(ev,(en.OccurTime+durtime,i),cmp); }//客户离开void CustomerDepature(){ i=en.NType; DeQueue(q[i],c); //删除队列元素(客户离开) TotalTime+=en.Duration-customer.ArrivalTime; //累加客户业务等待时间 if(!QueueEmpty(q[i])){ GetHead(q[i],customer); orderInsert(ev,(en.OccurTime+curtomer.Duration,i),(*cmp)()); }}//银行排队模拟程序void Bank_Simulation(int CloseTime){ OpenDay(); while(!ListEmpty(ev)){ DelFirst(GetHead(ev),p);en=GetCurElem(p); if(en.NType==0){ CustomerArrived(); //客户到来 }else{ CustomerDepature(); //客户离开 } } printf("The Average Time is %f\n",(float)TotalTime/CustomerNum);}
1 0
- 数据结构——离散事件模拟
- 离散事件模拟实现——数据结构(C语言版)
- 离散事件模拟——银行队列问题//数据结构作业
- 数据结构 离散事件模拟 银行等待时间
- 数据结构_离散事件的模拟
- 严蔚敏 数据结构C语言 银行排队队列 离散事件模拟
- 21、数据结构笔记之十九列队实现离散事件模拟
- 22、数据结构笔记之十九列队实现离散事件模拟
- 离散事件模拟
- 离散事件模拟
- 队列-模拟离散事件
- 离散事件模拟
- 3.5离散事件模拟
- C语言 离散事件模拟
- 离散事件模拟-银行管理
- 离散事件模拟-银行管理
- 离散事件模拟-银行管理
- 离散事件模拟-银行管理
- Win10下loadrunner11安装与运行
- Android 5.0 CTS 代码修改日记
- Unity3D 自动添加Fbx Animation Event
- SpringBoot之Mybatis篇(注解&配置文件)(MVC版)
- 欢迎使用CSDN-markdown编辑器
- 数据结构——离散事件模拟
- iOS webview与Js的交互。以及修改cookie、header头
- Access-Control-Allow-Origin与跨域
- Oracle与Sql Serer的链接桥梁之透明网关的部署与配置详解(二)安装GateWays
- 关于Monkey的一切都在这里
- Java HashMap、HashTable详解
- Problems encountered during text search
- Android架构思考(模块化、多进程)(转载学习)
- Linux上部署web应用(mysql,tomcat)