離散事件模擬 銀行排隊

2021-10-08 08:00:14 字數 2528 閱讀 4230

某銀行有四個視窗接待客戶,每個視窗在某個時刻只能接待乙個客戶,人數多時則需要進行排隊,剛進來的客戶,視窗無人則進行業務辦理,有人則排隊,排在人數最少的隊伍後面。

問題:計算在銀行關閉之前,計算客戶在銀行逗留的平均時間

用c寫的,給書上**的實現了下,**如下:

#include

#include

#include

#include

typedef

struct

elemtype;

typedef

struct lnode lnode,

* linklist;

//事件表,鍊錶

typedef linklist evenlist;

//事件鍊錶型別

typedef

struct

qelemtype;

//佇列

typedef

struct qnode qnode,

* queueptr;

//銀行排隊鍊錶

typedef

struct

linkqueue;

//佇列

evenlist ev;

//事件驅動

elemtype en;

//事件

linkqueue q[5]

;//排隊器

qelemtype customer;

//排隊中的人

int totaltime, customernum;

//總時間 總人數

void

linkinit

(linklist& l)

void

linkinsert

(linklist l,

int i, elemtype e)

//事件插入if(

!l)return

; linklist s =

(linklist)

malloc

(sizeof

(lnode));

s->data = e;

s->next = l-

>next;

l->next = s;

}void

linkdispaly

(linklist l)

printf

("\n");

}int

order

(linklist l, elemtype e)

}return i;

}void

queueinit

(linkqueue& q)

void

qeueinsert

(linkqueue& q, qelemtype e)

qelemtype qeuedelete

(linkqueue& q)

queueptr s;

re = q.front-

>data;

s = q.front;

q.front = q.front-

>next;

free

(s);

return re;

}int

queuelength

(linkqueue q)

return count;

}int

minlength

(linkqueue *q)

return re;

}qelemtype queuehead

(linkqueue q)

void

openforday()

}void

customerarrived

(elemtype e,

int closetime)

i =minlength

(q);

qeueinsert

(q[i]

, re)

; en.occurtime = e.occurtime + durtime;

en.ntype = i;if(

queuelength

(q[i])==

1)}void

customerdeparture

(elemtype e)

}void

bank_simulation

(int closetime)

else

q = ev;

ev = ev-

>next;

free

(q);

printf

("當前時間表:");

linkdispaly

(ev)

;printf

(, totaltime, customernum);}

printf

("%f\n",(

float

)totaltime / customernum);}

intmain()

離散事件模擬 銀行排隊

假設不存在插隊的情況,並且人人都會選擇排到人數最少的那乙個視窗排隊。假設人們陸續到達銀行,不會同時到達銀行。如下 include include include define max size 10000 佇列的初始化長度 define end time 10000 銀行關門時間 using nam...

離散事件模擬 銀行排隊時間模擬

在資料結構中有個講述如何模擬銀行排隊,最終算出每個人平均的逗留時間。這是需要資料結構的知識。將銀行的每個視窗看成是乙個佇列,那麼對於每次來乙個人,都需要從最短的佇列進行排隊。其實更優秀的做法是從最短的等待時間佇列來排隊 這裡的做法是這樣的,首選在乙個佇列中插入乙個人,整個事件是事件驅動的,每次去檢查...

離散事件模擬 銀行管理

離散事件模擬 銀行管理 timelimit 1000ms memory limit 65536k 題目描述 現在銀行已經很普遍,每個人總會去銀行辦理業務,乙個好的銀行是要考慮平均逗留時間的,即 在一定時間段內所有辦理業務的人員逗留的時間的和 總的人數。逗留時間定義為人員離開的時間減去人員來的時間。銀...