📄 postoffice_2.cpp
字号:
#include "PerformSeer.h"
class POST_OFFICE : public SIMMODEL {
public:
void initiate();
};
class CUSTOMER : public ELEMENT {
public:
real64 arrivTime;
real64 leavProb;
real64 servTime;
};
class CLERK : public PROCESS {
public:
void process();
};
class GENERATOR : public PROCESS {
public:
void process();
};
POST_OFFICE PostOffice;
QUEUE WaitingQueue;
RANDOM R1(1);
RANDOM R2(2);
RANDOM R3(3);
real64 DayLength;
real64 MeanArrInterval;
real64 MinServiceTime;
real64 MaxServiceTime;
uint16 MinClerkNum;
uint16 MaxClerkNum;
uint16 ClerkNum;
uint16 ChairNum;
uint32 LeavedNum;
uint32 ServedNum;
METER <real64> DelayInQueue;
METER <real64> BusyClerkNum;
void Read_Parameter();
void Print_Result();
int main( int argc, char** argv )
{
Read_Parameter();
for (ClerkNum = MinClerkNum; ClerkNum <= MaxClerkNum; ClerkNum += 1) {
PostOffice.clear();
PostOffice.initiate();
PostOffice.simulate();
Print_Result();
}
return 0;
}
void Read_Parameter()
{
DayLength = 540;
MeanArrInterval = 4;
MinServiceTime = 5;
MaxServiceTime = 10;
MinClerkNum = 1;
MaxClerkNum = 5;
ChairNum = 10;
printf( "\nCLERKS CLERKS CUSTOMERS NUMBER DELAY IN QUEUE NUMBER IN QUEUE" );
printf( "\nNUMBER UTILIZATION SERVED / LEAVED AVERAGE / MAXIMUM AVERAGE / MAXIMUM" );
printf( "\n===========================================================================\n" );
}
void Print_Result()
{
printf( "\n %3d %7.3f %4d %4d %7.3f %7.3f %7.3f %4d",
ClerkNum, BusyClerkNum.get_timeaverage()/(real64)ClerkNum, ServedNum, LeavedNum,
DelayInQueue.get_average(), DelayInQueue.get_maximum(),
WaitingQueue.get_avglen(), WaitingQueue.get_maxlen() );
}
void POST_OFFICE::initiate()
{
GENERATOR *generator;
LeavedNum = 0;
ServedNum = 0;
R1.reset();
R2.reset();
R3.reset();
WaitingQueue.clear();
DelayInQueue.clear();
BusyClerkNum.clear();
BusyClerkNum = 0;
create_process( generator );
generator->activated();
}
void GENERATOR::process()
{
CLERK *clerk;
CUSTOMER *customer;
real64 interval;
while (1) {
interval = R1.exponential( (real64)1 / MeanArrInterval );
if (SIMTIME + interval > DayLength)
exit();
pass_time( interval );
customer = new CUSTOMER;
customer->arrivTime = SIMTIME;
customer->leavProb = (real64)(WaitingQueue.get_length()) / (real64)ChairNum;
customer->servTime = ( R2.uniform(MinServiceTime, MaxServiceTime) );
if (R3.bernoulli(customer->leavProb) == 1) {
LeavedNum += 1;
delete customer;
}
else {
ServedNum += 1;
WaitingQueue.insert( customer );
if (BusyClerkNum < ClerkNum) {
create_process( clerk );
clerk->activated();
}
}
}
}
void CLERK::process()
{
CUSTOMER *customer;
BusyClerkNum += 1;
while (WaitingQueue.get_head() != NULL) {
customer = (CUSTOMER*) WaitingQueue.pop_head();
DelayInQueue = SIMTIME - customer->arrivTime;
pass_time( customer->servTime );
delete customer;
}
BusyClerkNum -= 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -