利用优先级队列实现事件驱动模拟


//------------------------------------------------
#include<iostream.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include<ctype.h> //用于函数isdigit
#include "pryQueue.h"
//---事件驱动模拟
// 通过程序模拟来研究银行顾客在一家有n>=2个窗口的银行的到达和离开的情况
// 模拟的关键部分为客户时间,包括到达和离开。假定每个柜员都能准确地完成工作
// 计划。
// 顾客进入银行时产生到达事件,在顾客确定服务窗口时确定顾客离开的事件。每个
// 事件都被加上时间戳,然后放到优先级队列中,这样便可以根据用户到达和离开的
// 时间顺序处理这些事件。
// 每个刚到达顾客负责生成下一个到达事件,并生成自己的离开事件,离开事件只需
// 要修改服务窗口信息就可以
// 收集服务中每个窗口的服务顾客总人数、服务总时间等

 
//---------EVENT
enum EventType{arrival,departure};
class Event
{
private:
 int time;//时间时间戳
 EventType etype;//事件类型
 int customerID;//顾客ID
 int tellerID;//服务窗口ID
 int waittime;
 int servicetime;
public:
 Event(void);
 Event(int t,EventType et,int cn,int tn,int wt,int st);

 int GetTime(void) const;
 EventType GetEventType(void) const;
 int GetCustomerID(void) const;
 int GetTellerID(void) const;
 int GetWaitTime(void) const;
 int GetServiceTime(void) const;
};
Event::Event(void)
{
 time=0;
 etype=arrival;
 customerID=1;
 tellerID=0;
 waittime=0;
 servicetime=0;
}
Event::Event(int t,EventType et,int cn,int tn,int wt,int st)
{
 time=t;
 etype=et;
 customerID=cn;
 tellerID=tn;
 waittime=wt;
 servicetime=st;
}
int Event::GetTime() const
{

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值