-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate_trans.c
201 lines (197 loc) · 6.07 KB
/
state_trans.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include<stdio.h>
#include<time.h>
#include"variable.h"
extern int MaxSeqLen1,MinSec1,MaxSec1,MinRestSec1,MaxRestSec1,VIPSERVLen1,WaitTime1;
extern void state_trans(void)//WINDOW windows[],int size,......)普通客户
{
int i,degree;
int arrival,sign,stop;
for(i=0;i<8;i++)
{
switch(windows[i].state)
{
case CLOSE://关闭
if(i>1&&close==0&&normServeLen>=3*size1)//动态打开普通窗口
{
windows[i].state=FREE;
ischange=1;
size1++;
}
else if(i<=1&&close==0&&vipServeLen>=3)//动态打开vip窗口
{
windows[i].state=FREE;
ischange=1;
size2++;
}
break;
case FREE://空闲:
if(strcmp(windows[i].serveNo," ")!=0)//接到任务)
{
windows[i].state=WAIT;//状态切换到“等待顾客”;
ischange=1;
windows[i].wtime++;//启动等待计时;
}
else if((windows[i].flag==1)&&(i>1)&&(size1>3))//有休息请求,且请求被通过)
{
windows[i].state=PAUSE;//状态切换到“暂停”;
ischange=1;
size1--;
srand(time(NULL));
stop=MinRestSec1+rand()%(MaxRestSec1-MinRestSec1+1);
windows[i].resttime=stop;
windows[i].planrtime=stop;
windows[i].rtime++;//启动休息计时;
windows[i].restLen++;
}
else if((windows[i].flag==1)&&(i<=1)&&(size2==2))//有休息请求,且请求被通过)
{
windows[i].state=PAUSE;//状态切换到“暂停”;
ischange=1;
size2--;
srand(time(NULL));
stop=MinRestSec1+rand()%(MaxRestSec1-MinRestSec1+1);
windows[i].resttime=stop;
windows[i].planrtime=stop;
windows[i].rtime++;//启动休息计时;
windows[i].restLen++;
}
else if((i==size1+1)&&(close==0)&&(normServeLen<3*size1)&&(size1>3))//动态关闭多余的普通窗口
{
windows[i].state=CLOSE;
ischange=1;
size1--;
}
else if((i>1)&&(close==1)&&(headp==NULL))//下班后关闭窗口
{
windows[i].state=CLOSE;
ischange=1;
size1--;
}
else if((i==size2-1)&&(close==0)&&(vipServeLen<3)&&(size2==2))//关闭多余的vip窗口
{
windows[i].state=CLOSE;
ischange=1;
size2--;
}
else if((i<=1)&&(close==1)&&(headpVIP==NULL))//下班后关闭vip窗口
{
windows[i].state=CLOSE;
ischange=1;
size2--;
}
break;
case WAIT://等待顾客:
srand(time(NULL));
arrival=rand()%2;//随机数模拟顾客是否到来;
if(arrival==0&&windows[i].wtime<WaitTime1)//顾客未到达且等待未超时)
{
windows[i].wtime++;
} //do nothing
else if(arrival==0&&windows[i].wtime>=WaitTime1)//顾客未到达且等待时间到)
{
windows[i].wtime=0;
windows[i].state=FREE;
ischange=1;
strcpy(windows[i].serveNo," ");
} //转为“空闲"状态;......
else if(arrival==1&&windows[i].wtime<WaitTime1)//顾客到达且等待时间未超时)
{
windows[i].wtime=0;
windows[i].state=DEAL;
ischange=1;
windows[i].custCount++;
if(windows[i].serveNo[0]=='V')
{
windows[i].custvipCount++;
}
else
{
windows[i].custnormCount++;
}
srand(time(NULL)); //开始不一样
sign=MinSec1+rand()%(MaxSec1-MinSec1+1);
windows[i].dealtime=sign;
windows[i].plandtime=windows[i].plandtime+sign; //结束不一样
} //转为“办理中”状态;启动服务计时;......
break;
case DEAL://办理中:
if(windows[i].dtime<windows[i].dealtime)//未达到计划办理时间
{
windows[i].serveLen++;
windows[i].dtime++;
}//donothing
else if(windows[i].dtime>=windows[i].dealtime) //开始不一样
{
// windows[i].serveLen++
windows[i].dtime=0;
windows[i].dealtime=0;
windows[i].state=FINISH;
ischange=1;
strcpy(windows[i].serveNo," ");
}//转换为”办理结束“状态;
break;
case FINISH://办理结束:
srand(time(NULL));
degree=rand()%3;
switch(degree)
{
case 0:
(windows[i].custsatisfyGood)++;
break;
case 1:
(windows[i].custsatisfyNorm)++;
break;
case 2:
(windows[i].custsatisfyBad)++;
break;
}
if((strcmp(windows[i].serveNo," "))!=0)//接到任务)
{
windows[i].state=WAIT;
ischange=1;
}//转换为“等待顾客”状态;
else if(windows[i].flag==1)
{
windows[i].state=PAUSE;//状态切换到“暂停”;
ischange=1;
size1--;
srand(time(NULL));
stop=MinRestSec1+rand()%(MaxRestSec1-MinRestSec1+1);
windows[i].resttime=stop;
windows[i].planrtime=stop;
windows[i].rtime++;//启动休息计时;
windows[i].restLen++;
}//有休息请求,转换为暂停状态 */
else//无任务)
{
windows[i].state=FREE;
ischange=1;
}//转换为“空闲”状态;
break;
case PAUSE://暂停:
if(windows[i].rtime<windows[i].resttime)
{
windows[i].rtime++;
windows[i].restLen++; //不一样
}
else if((windows[i].rtime)>=(windows[i].resttime)) //开始不一样
{
if(i>1)
{
size1++;
}
else
{
size2++;
}
windows[i].state=FREE;
ischange=1;
windows[i].resttime=0;
// windows[i].restLen++;
windows[i].rtime=0;
windows[i].flag=0;
}//转换为“空闲”状态;
break;
}
}
}