|
|
@ -40,7 +40,6 @@ QueuePtr front;//队头指针
|
|
|
|
QueuePtr rear; // 队尾指针
|
|
|
|
QueuePtr rear; // 队尾指针
|
|
|
|
} LinkQueue;
|
|
|
|
} LinkQueue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventList ev; // 事件表
|
|
|
|
EventList ev; // 事件表
|
|
|
|
Event en; // 事件
|
|
|
|
Event en; // 事件
|
|
|
|
LinkQueue q[5]; // 四个客户队列
|
|
|
|
LinkQueue q[5]; // 四个客户队列
|
|
|
@ -108,9 +107,12 @@ printf("The Average Time is %f\n", (float)TotalTime / CustomerNum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int cmp(Event a, Event b) // 比较事件发生先后
|
|
|
|
int cmp(Event a, Event b) // 比较事件发生先后
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (a.OccurTime > b.OccurTime) return 1;
|
|
|
|
if (a.OccurTime > b.OccurTime)
|
|
|
|
if (a.OccurTime = b.OccurTime) return 0;
|
|
|
|
return 1;
|
|
|
|
if (a.OccurTime < b.OccurTime) return -1;
|
|
|
|
if (a.OccurTime = b.OccurTime)
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (a.OccurTime < b.OccurTime)
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpenForDay() // 银行开门
|
|
|
|
void OpenForDay() // 银行开门
|
|
|
@ -162,19 +164,18 @@ OrderInsert(ev, { en.OccurTime + durtime,i }, cmp);//队列长度为1时,设
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CustomerDepature() // 客户离开
|
|
|
|
void CustomerDepature() // 客户离开
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i = en.NType;
|
|
|
|
int i = en.NType;
|
|
|
|
DeQueue(q[i], customer); // 删除第i队列的排头客户
|
|
|
|
DeQueue(q[i], customer); // 删除第i队列的排头客户
|
|
|
|
TotalTime += en.OccurTime - customer.ArrivalTime; // 累计客户逗留时间
|
|
|
|
TotalTime += en.OccurTime - customer.ArrivalTime; // 累计客户逗留时间
|
|
|
|
if (!QueueEmpty(q[i])) {
|
|
|
|
if (!QueueEmpty(q[i]))
|
|
|
|
|
|
|
|
{
|
|
|
|
GetHead(q[i], customer);
|
|
|
|
GetHead(q[i], customer);
|
|
|
|
OrderInsert(ev, {en.OccurTime + customer.Duration, i}, cmp); // 插入事件
|
|
|
|
OrderInsert(ev, {en.OccurTime + customer.Duration, i}, cmp); // 插入事件
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Minimum(LinkQueue Q[5]) // 求长度最短队列
|
|
|
|
int Minimum(LinkQueue Q[5]) // 求长度最短队列
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int minLength = QueueLength(Q[1]);
|
|
|
|
int minLength = QueueLength(Q[1]);
|
|
|
@ -190,7 +191,6 @@ i = j;
|
|
|
|
return i;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Status InitList(LinkList &L) // 链表初始化
|
|
|
|
Status InitList(LinkList &L) // 链表初始化
|
|
|
|
{
|
|
|
|
{
|
|
|
|
L = (LinkList)malloc(sizeof(LNode));
|
|
|
|
L = (LinkList)malloc(sizeof(LNode));
|
|
|
@ -265,12 +265,14 @@ ListTraverse(ev);
|
|
|
|
Status ListTraverse(LinkList &L) // 遍历链表
|
|
|
|
Status ListTraverse(LinkList &L) // 遍历链表
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LNode *p = L->next;
|
|
|
|
LNode *p = L->next;
|
|
|
|
if (!p) {
|
|
|
|
if (!p)
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("List is empty.\n");
|
|
|
|
printf("List is empty.\n");
|
|
|
|
return ERROR;
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (p != NULL) {
|
|
|
|
while (p != NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("OccurTime:%d,Event Type:%d\n", p->data.OccurTime, p->data.NType);
|
|
|
|
printf("OccurTime:%d,Event Type:%d\n", p->data.OccurTime, p->data.NType);
|
|
|
|
p = p->next;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -278,8 +280,6 @@ printf("\n");
|
|
|
|
return OK;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Status InitQueue(LinkQueue &Q) // 链队列的初始化
|
|
|
|
Status InitQueue(LinkQueue &Q) // 链队列的初始化
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Q.front = Q.rear = (QueuePtr)malloc(sizeof(QNode));
|
|
|
|
Q.front = Q.rear = (QueuePtr)malloc(sizeof(QNode));
|
|
|
@ -324,7 +324,8 @@ int QueueLength(LinkQueue Q)//返回队列的长度
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
QNode *p = Q.front->next;
|
|
|
|
QNode *p = Q.front->next;
|
|
|
|
while (p) {
|
|
|
|
while (p)
|
|
|
|
|
|
|
|
{
|
|
|
|
p = p->next;
|
|
|
|
p = p->next;
|
|
|
|
count++;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -334,7 +335,9 @@ return count;
|
|
|
|
Status GetHead(LinkQueue Q, QElemType &e) // 获取队头元素
|
|
|
|
Status GetHead(LinkQueue Q, QElemType &e) // 获取队头元素
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Q.front == Q.rear)
|
|
|
|
if (Q.front == Q.rear)
|
|
|
|
{ return ERROR;}
|
|
|
|
{
|
|
|
|
|
|
|
|
return ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
e = Q.front->next->data;
|
|
|
|
e = Q.front->next->data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Status QueueEmpty(LinkQueue Q) // 判断队列是否为空
|
|
|
|
Status QueueEmpty(LinkQueue Q) // 判断队列是否为空
|
|
|
@ -349,7 +352,8 @@ void PrintQueue()//打印队列
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// 打印当前队列
|
|
|
|
// 打印当前队列
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
for (i = 1; i <= 4; i++) {
|
|
|
|
for (i = 1; i <= 4; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("窗口 %d 有 %d 个客户:", i, QueueLength(q[i]));
|
|
|
|
printf("窗口 %d 有 %d 个客户:", i, QueueLength(q[i]));
|
|
|
|
QueueTraverse(q[i]);
|
|
|
|
QueueTraverse(q[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -358,11 +362,13 @@ printf("\n");
|
|
|
|
Status QueueTraverse(LinkQueue Q) // 遍历队列Q
|
|
|
|
Status QueueTraverse(LinkQueue Q) // 遍历队列Q
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QNode *p = Q.front->next;
|
|
|
|
QNode *p = Q.front->next;
|
|
|
|
if (!p) {
|
|
|
|
if (!p)
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("--Is empty.\n");
|
|
|
|
printf("--Is empty.\n");
|
|
|
|
return ERROR;
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (p) {
|
|
|
|
while (p)
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("(到达时刻 %d min 办理业务需要花费 %d min) ", p->data.ArrivalTime, p->data.Duration);
|
|
|
|
printf("(到达时刻 %d min 办理业务需要花费 %d min) ", p->data.ArrivalTime, p->data.Duration);
|
|
|
|
p = p->next;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|