I have seen the two textbooks ("Data Structure (C language version)" There is also this yellow book) is used in this explanation, and it is the bank business simulation (too new). In detail, the way the two books simulated by the two books is still different. The 1997 version of the "Data Structure (C language version)" bank or old-fashioned business model (after all in 1997), now many places still in this business model - several windows queue in the same time. This way is actually not reasonable, often there will be no previous business, it is still not later, and it is often grinded in front. The other team is getting shorter, so that you can't hate the front of the person.). The 1999 version of this yellow book is changed to a list of listed business, and each of the customers send a number. If the counter is idle, it is called the number of customers to handle the business; if several days The counter is idle, determines the order of these counter calls in accordance with a law (the easiest is the order of the counter number). In this way, it will ensure that the customer accepts the service in order to come first - because everyone is in a team. Such business models I have seen in Beijing's Xizhimen Industrial and Commercial Bank, it should be said that this is a relatively reasonable business model. However, in this article is the most important thing, such business model is better (a queue is always better than the N queen).
This part of the original book is too ugly. I have dizzy, I don't know if I can make it according to the original book, because I didn't understand (by white: relying on, your boy is still coming). I simulated according to the actual situation, achieved as follows:
#ifndef simulation_h
#define simulation_h
#include
#include
#include
Class Teller
{
PUBLIC:
INT TOTALCUSTOMERCOUNT;
Int TotalServentetime;
Int finishServentime;
Teller (): totalcustomercount (0), TotalServentime (0),
FINISHSERVICETIME (0) {}
}
// # Define PrintProcess
Class Simulation
{
PUBLIC:
Simulation ()
{
COUT << Endl << "Enter analog Parameters << ENDL;
Cout << "The number of counters:"; cin >> Tellernum;
Cout << "Business hours:"; cin >> simutime;
COUT << "The minimum interval from two customers came:"; cin >> arrivallow;
Cout << "The maximum interval between two customers came:"; cin >> arrivalh;
Cout << "counter service minimum time:"; cin >> serviceLow;
Cout << "counter service maximum time:"; cin >> servicehigh;
ArrivalRange = arrivalhigh - arrivalow 1;
ServiceRange = ServiceHigh - Servicelow 1; SRAND (NULL);
}
Simulation (int Tellernum, int Simutime, int Arrivalow, int ArvalHigh, int servicelow, int servicehigh)
: TellerNum (TellerNum), SimuTime (SIMUTIME), ARRIVALLOW (ARRIVALLOW), ARRIVALHIGH (ARRIVALHIGH),
ServiceLow (ServiceLow), ServiceHigh (ServiceHigh),
ArrivalRange (ArriValHigh - Arrivallow 1), ServiceHigh - Servicelow 1)
{SRAND (NULL);}
void initialize ()
{
CURTIME = nextTime = 0;
Customernum = Customertime = 0;
For (INT i = 1; i <= tellernum; i )
{
Tellers [i] .totalcustomercount = 0;
Tellers [i] .totalServentEtime = 0;
Tellers [i] .finishServentime = 0;
}
Customer.makeempty ();
}
Void Run ()
{
INITIALIZE ();
NEXTARRIVED ();
#ifdef printprocess
Cout << Endl;
COUT << "tellerid";
For (int K = 1; k <= tellernum; k ) cout << "/ tteller << k;
Cout << Endl;
#ENDIF
For (CURTIME = 0; curtime <= simutime; curtime )
{
IF (CURTIME> = nexttime)
{
Customerarrived ();
NEXTARRIVED ();
}
#ifdef printprocess
COUT << "Time:" << curtime << "
#ENDIF
For (INT i = 1; i <= tellernum; i )
{
IF (Tellers [i] .finishServentime IF (Tellers [i] .finishServentime == Curtime &&! Customer.Isempty ()) { INT t = nextservice (); #ifdef printprocess COUT << '/ t' << Customernum 1 << '(' << Customer.Getfront () << ',' << t << ')'; #ENDIF CustomerDeparture (); tellers [i] .totalcustomercount ; Tellers [i] .totalServentetime = T; Tellers [i] .finishServentime = T; } #ifdef printprocess Else Cout << "/ t"; #ENDIF } #ifdef printprocess Cout << Endl; #ENDIF } PRINTRESULT (); } Void Ptintsimupara () { COUT << Endl << "Analog Parameters" << ENDL; Cout << "The number of counter:" << Tellernum << "/ T business hours:" << SimuTime << endl; Cout << "The minimum interval from two customers came:" "arrivalow << endl; COUT << "The maximum interval between two customers came:" "arrivalhigh << Endl ;; Cout << "counter service minimum time:" serviceLow << endl; COUT << "Counter service maximum time:" "servicehigh << Endl; } Void PrintResult () { INT TSN = 0; Long TST = 0; Cout << Endl; COUT << "------------- Simulation Results ------------------"; Cout << Endl << "Tellerid / TAVENUM / TAVICETIME / TAVERAGETIME" << Endl; For (INT i = 1; i <= tellernum; i ) { COUT << "teller" << i; Cout << '/ t' << Tellers [i] .totalcustomercount << ""; TSN = Tellers [i] .totalcustomercount; Cout << '/ t' << Tellers [i] .totalServentime << ""; TST = (long) Tellers [i] .totalServiceTime; Cout << '/ t'; IF (Tellers [i] .totalcustomercount) cout << (float) Tellers [i] .totalservice / (float) Tellers [i] .totalcustomercount; Else Cout << 0; Cout << "<< Endl; } COUT << "Total / T" << TSN << "/ t" << TST << "/ t"; IF (TSN) cout << (float) TST / (FLOAT) TSN; Else Cout << 0; Cout << "<< Endl; COUT << "Customer Number: / T" << Customernum << "/ TNO Service: / T" << Customernum - TSN << ENDL; COUT << "Customer Waittime: / t" << Customertime << "/ TAVGWAITTIME: / T"; IF (TSN) COUT << (float) Customertime / (FLOAT) TSN; Else Cout << 0; Cout << Endl; } Private: Int tellernum; Int Simutime; INT CURTIME, NEXTTIME; Int Customernum; Long Customertime; Int Arrivallow, ArriValhigh, ArrivalRange Int Servicelow, ServiceHigh, ServiceRange Teller Tellers [21]; Queue void nextarrived () { NEXTTIME = arrivalow rand ()% arrivalrange; } Int nextservice () { Return ServiceLow Rand ()% ServiceRange; } Void Customerarrived () { Customernum ; Customer.enqueue (NextTime); } Void CustomerDeparture () { Customertime = (long) CURTIME - (long) Customer.dequeue (); } } #ENDIF A few description l Run () The process is like this: CURTIME is a clock, from starting businesspes, naturally lapse until the business. When the customer's incident occurred (customer to time is equal to the current time, less than the determination is because the customer arrives at the same time - input arrallow = 0, and at the same time, only give a customer emission number), give this customer Number (with customer to time to mark this customer, enter the team, to the number of customers 1). When the counter service is completed (the counter service is equal to the current time), the number of service number is increased by 1, the service time is accumulated, the customer leaves the event, the next customer to the counter. Because the counter starts are idle, the actual code is a bit inserted. Finally, when stopping business, stop the number, but also in the service-oriented customers continue to the service, others are still queued. l The simulation results are: the number of services, service time, average service time, total service number, service time, average service time, time, the number of customers, not being served (too late), accept Service customer waiting time, average waiting time. l This algorithm is relatively low. It is actually not completed this simulation without the queue (to drive the current clock with the customer, the counter directly announced the service completion time), but this is a big difference with the actual situation - no Waiting for people to know when? Although the result is the same, it is very inexplicable, especially when teaching purposes. Of course, this algorithm this algorithm is not worth advocating in order to improve simulation efficiency. l Note #define printprocess, remove the comment, when running the simulation, you can print out the service situation of each time counter (the second customer, customer arrival time, accept service time), but only 4 counters Hereinafter, the screen is full (the format is chaotic). [Post ", I didn't intend to write this article. Later, when I started to achieve simulation, I can't stop. This is an example of the first practical application in the data structure, and there is also practical significance. You can see the work intensity of each counter under different business densities (or which counter is given to the Nassing bonus, either rotate the counter), the wait time of the customer in various situations (people are round to themselves) There are also a variety of cases set up several counters reasonable (few free time, very short wait time, almost zero unpaid number). For example, this: For (int i = 1; i <16; i ) { Simulation A (i, 240, 1, 4, 8, 15); A.Run (); } You simulate it, you will get it, in less busy banks, 4 ~ 5 counters are suitable - most of the current banks are like this.