《銀行離散事件模擬》數(shù)據(jù)結(jié)構(gòu)上機(jī)實(shí)習(xí)報(bào)告_第1頁
《銀行離散事件模擬》數(shù)據(jù)結(jié)構(gòu)上機(jī)實(shí)習(xí)報(bào)告_第2頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、銀行離散事件模擬數(shù)據(jù)結(jié)構(gòu)上機(jī)實(shí)習(xí)報(bào)告實(shí)習(xí)題目:銀行離散事件模擬需求分析:為了計(jì)算所有客戶在銀行的平均逗留時(shí)間,需要掌握每個(gè)客戶到達(dá)銀行和離開銀行的時(shí)間,后者減去前者即為每個(gè)客戶在銀行的逗留時(shí)間。用當(dāng)天的客戶數(shù)去除以所有客戶的逗留時(shí)間之和便是所求的平均逗留時(shí)間。三概要設(shè)計(jì):數(shù)據(jù)結(jié)構(gòu),使用到帶頭結(jié)點(diǎn)鏈表EvevtList,結(jié)點(diǎn)是LNode,提供的操作有:InitList,DelFirst,GetCurElem,GetHead,OrderInsert,此鏈表用于存放客戶的進(jìn)入或者離開的事件,存放數(shù)據(jù)包括進(jìn)入的時(shí)間,處理的時(shí)間,離開的時(shí)間使用一個(gè)隊(duì)列Queue,節(jié)點(diǎn)是QNode,隊(duì)列的數(shù)據(jù)元素類型為Q

2、ElemType,提供的主要操作有:InitQueue,QueueEmpty,QueueLength,GetHead,EnQueue,DeQueue,此隊(duì)列用于模擬進(jìn)入銀行后等待辦理業(yè)務(wù)的客戶排隊(duì)情況。其存儲(chǔ)的數(shù)據(jù)有時(shí)間到達(dá)的時(shí)間和處理事物所需的時(shí)間。層次調(diào)用關(guān)系,包括三個(gè)文件:Main.cpp,Queue.h和LinkList.h,后兩個(gè)用于數(shù)據(jù)結(jié)構(gòu)的定義,主要的程序在Main.cpp中,從main()進(jìn)入調(diào)用Bank_Simulation(),Bank_Simulation()調(diào)用到OpenForDay(),CustomerArrived()和CustomerDeparture(),Cus

3、tomerArrived()調(diào)用Random()和Minimum();事件鏈表的設(shè)計(jì)typedef struct int OccurTime; int NType; Event,ElemType; typedef struct LNode / 結(jié)點(diǎn)類型 ElemType data; LNode *next; *Link,*Position; struct LinkList / 鏈表類型 Link head,tail; / 分別指向線性鏈表中的頭結(jié)點(diǎn)和最后一個(gè)結(jié)點(diǎn) int len; / 指示線性鏈表中數(shù)據(jù)元素的個(gè)數(shù) ;typedef LinkList EventList;隊(duì)列的設(shè)計(jì)typedef

4、 struct int ArrivalTime; / 到達(dá)時(shí)刻 int Duration; / 辦理事務(wù)所需時(shí)間 QElemType; / 定義隊(duì)列的數(shù)據(jù)元素類型QElemType為結(jié)構(gòu)體類型 typedef struct QNode QElemType data; QNode *next; *QueuePtr; struct LinkQueue QueuePtr front,rear; / 隊(duì)頭、隊(duì)尾指針 ;主要過程void Bank_Simulation() / 銀行業(yè)務(wù)模擬函數(shù) 開門營業(yè); while(有客戶進(jìn)入或者等待辦理) / 事件表ev不空 判斷應(yīng)該進(jìn)行何種操作 若是客戶到達(dá) Cu

5、stomerArrived(); / 處理客戶到達(dá)事件 若是客戶處理結(jié)束離開銀行 CustomerDeparture(); / 處理客戶離開事件 計(jì)算平均使用時(shí)間輸出相關(guān)數(shù)據(jù) 四詳細(xì)設(shè)計(jì):LinkList.h#define Qu 2#define jg 5#define doing 30 #include #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 typedef int Status; typedef int Boolean;

6、typedef struct int OccurTime; int NType; Event,ElemType; typedef struct LNode ElemType data; LNode *next; *Link,*Position; struct LinkList Link head,tail; int len; ; typedef LinkList EventList; EventList ev; Event en,et; void InitList(LinkList &L) Link p; p=(Link)malloc(sizeof(LNode); if(p) p-next=N

7、ULL; L.head=L.tail=p; L.len=0; else exit(ERROR); Status DelFirst(LinkList &L,Link h,Link &q) q=h-next; if(q) h-next=q-next; if(!h-next) L.tail=h; L.len-; return OK; else return FALSE; ElemType GetCurElem(Link p) return p-data; Status ListEmpty(LinkList L) if(L.len) return FALSE; else return TRUE; Po

8、sition GetHead(LinkList L) return L.head; void OrderInsert(LinkList &L,ElemType e,int (*comp)(ElemType,ElemType) Link o,p,q; q=L.head; p=q-next; while(p!=NULL&comp(p-data,e)next; o=(Link)malloc(sizeof(LNode); o-data=e; q-next=o; o-next=p; L.len+; if(!p) L.tail=o; Queue.htypedef struct int ArrivalTim

9、e; int Duration; QElemType; typedef struct QNode QElemType data; QNode *next; *QueuePtr; struct LinkQueue QueuePtr front,rear; ; void InitQueue(LinkQueue &Q) if(!(Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode) exit(OVERFLOW); Q.front-next=NULL; void DestroyQueue(LinkQueue &Q) while(Q.front) Q.rear=Q.

10、front-next; free(Q.front); Q.front=Q.rear; Status QueueEmpty(LinkQueue Q) if(Q.front-next=NULL) return TRUE; else return FALSE; int QueueLength(LinkQueue Q) int i=0; QueuePtr p; p=Q.front; while(Q.rear!=p) i+; p=p-next; return i; Status GetHead(LinkQueue Q,QElemType &e) QueuePtr p; if(Q.front=Q.rear

11、) return ERROR; p=Q.front-next; e=p-data; return OK; void EnQueue(LinkQueue &Q,QElemType e) QueuePtr p; if(!(p=(QueuePtr)malloc(sizeof(QNode) exit(OVERFLOW); p-data=e; p-next=NULL; Q.rear-next=p; Q.rear=p; Status DeQueue(LinkQueue &Q,QElemType &e) QueuePtr p; if(Q.front=Q.rear) return ERROR; p=Q.fro

12、nt-next; e=p-data; Q.front-next=p-next; if(Q.rear=p) Q.rear=Q.front; free(p); return OK; Main.cpp#includeLinkList.h#includeQueue.h long int ZongShiJian=0; int CloseTime,YongHuShu=0; LinkQueue qQu;QElemType customer; int cmp(Event a,Event b) if(a.OccurTime=b.OccurTime) return 0; else return (a.OccurT

13、ime-b.OccurTime)/abs(a.OccurTime-b.OccurTime); void OpenForDay() int i; InitList(ev); en.OccurTime=0; en.NType=Qu; OrderInsert(ev,en,cmp); for(i=0;iQu;+i) InitQueue(qi); void Random(int &d,int &i) d=rand()%doing+1; i=rand()%(jg+1); int Minimum(LinkQueue Q) int lQu; int i,k=0; for(i=0;iQu;i+) li=Queu

14、eLength(Qi); for(i=1;iQu;i+) if(lil0) l0=li; k=i; return k; void CustomerArrived() QElemType f; int durtime,intertime,i; +YongHuShu; Random(durtime,intertime); et.OccurTime=en.OccurTime+intertime; et.NType=Qu; i=Minimum(q); if(et.OccurTimeCloseTime) OrderInsert(ev,et,cmp); f.ArrivalTime=en.OccurTime

15、; f.Duration=durtime; EnQueue(qi,f); if(QueueLength(qi)=1) et.OccurTime=en.OccurTime+durtime; et.NType=i; OrderInsert(ev,et,cmp); void CustomerDeparture() int i; i=en.NType; DeQueue(qi,customer); ZongShiJian+=en.OccurTime-customer.ArrivalTime; if(!QueueEmpty(qi) GetHead(qi,customer); et.OccurTime=en

16、.OccurTime+customer.Duration; et.NType=i; OrderInsert(ev,et,cmp); void Bank_Simulation() Link p; OpenForDay(); while(!ListEmpty(ev) DelFirst(ev,ev.head,p); en.OccurTime=GetCurElem(p).OccurTime; en.NType=GetCurElem(p).NType; if(en.NType=Qu) CustomerArrived(); else CustomerDeparture(); printf(【該窗口數(shù)為】: %d 【兩相鄰到達(dá)客戶的時(shí)間間隔】: 0%d分鐘 【每個(gè)客戶業(yè)務(wù)辦理時(shí)間】: 1%d分鐘n,Qu,jg,doing); printf(【客戶總數(shù)】:%dn,YongHuShu); printf(【所有客戶共耗時(shí)】:%ld分鐘n,ZongShiJian); printf(【平均每人耗時(shí)】:%d分鐘n,ZongShiJian/YongHuShu); void main() printf( _ 請(qǐng)您輸入銀行營業(yè)【時(shí)間長(zhǎng)度】(單位:分鐘),確認(rèn)請(qǐng)按Enter: ); sc

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論