📄 bank_teller.cpp
字号:
// bank_teller.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <time.h>
#include "Queue.h"
#include "server.h"
#include "arrivalGen.h"
#include "titre.h"
//Now that we have a queue class, a server class, and an arrivalGenerator class, we can put together a simulation of the line at a bank teller.
int main ()
{ int totalserveur,totalgroup;
int N ;
int intertime = 0 ;
int articletemps;
int paiementemps;
int SERVICETIME ;
int SEED = time(NULL);
const int PWIDTH = 6;
int MAXTIME ;
int totalAttenteTemps = 0;
int totalAttenteCustomers = 0;
int totalServiceTemps = 0;
int totalServiceCustomers = 0;
int AttenteTemps = 0;
int i=0,j,m,mode;
int numclient;
int arrivetime;
double PROBABILITY = 1 ;
double duree_moyen_attente = 0.00;
double duree_moyen_service = 0.00;
setprojet("PROJET SIMULATEUR","FILE D'ATTENTE AU SUPERMARCHER","F.QUASSETTE","FALK","YUE JUN","PENG YU","07/12/2003");
cout<<" entrer les argument de system de simulation:\n";
cout<<" Nombre total de Caisses:";
cin >> totalserveur;
cout<<" Nombre total de groups:";
cin >> totalgroup;
while( (totalserveur%totalgroup)!=0 ) {
cout<<" Nombre total de Caisses:";
cin >> totalserveur;
cout<<" Nombre total de groups:";
cin >> totalgroup;
}
N=totalserveur/totalgroup;
cout<<"Nombre de Caisses par group:"<<N<<endl;
int tr = N*N;
if(N==1) tr = 0;
cout<<"Le Temps moyen d'arrivee entre deux client par group:";
cin >> intertime;
cout<<"Le Temps de paiment:";
cin >> paiementemps;
cout<<"Le Temps d'une article:";
cin >> articletemps;
cout<<"Le temps total de travail au supermarcher:";
cin >> MAXTIME;
while( mode!=1 && mode!=2 )
{ cout<<"Le Mode d'Apparition (1:complication a trace 2:simplexe sans trace):";
cin >> mode;
}
cout<<"\n";
cout<<"\n";
cout<<"|-----------------------LE PROCESSUS DE SIMULTTION------------------------------|"<<endl;
server** teller;
teller = new server*[N];
if(mode==1)
cout <<" Minute";
for(j =0;j<N;j++){
teller[j] = new server(0); //Set up these objets of tellers with the
// given service time 0.
//en effet *(teller+j)=teller[j]
if(mode==1)
cout<< " Serving#"<<j; //Table headings
}
if(mode==1)
cout << " Queue "<<endl;
Queue line;
arrivalGenerator arrivalMachine (SEED, PROBABILITY,intertime);
//Run throught the minutes of the simulation
int minute = 1;
int interarrival = 0;
while(minute <= MAXTIME)
{ //these Tellers advances its timer, removes customer if
// service is finished.
if(i==0)
{ arrivalMachine.isArrival(minute);
line.push (arrivalMachine.getArrival ()); //get the number of arrival client
interarrival = arrivalMachine.Duree_entre_deux_arrive();
while(interarrival==0)
{i++;
interarrival = arrivalMachine.Duree_entre_deux_arrive();
}
}
for(i;i>0;i--)
{ arrivalMachine.isArrival(minute);
line.push (arrivalMachine.getArrival ()); //get the number of arrival client
}
for(m=0;m<interarrival;m++)
{ if(mode==1) cout << setw (PWIDTH) << minute+m << " > ";
for (j = 0;j<N;j++)
{ teller[j]->Update();
//If the teller is open, give first person in line to the
// teller for service, and remove the person from the line.
if (teller[j]->isAvailable ()) //examine whether the teller is vide.
{ numclient = line.getFirstInLine ();
if(numclient!=-1)
{SERVICETIME = paiementemps+ articletemps*(rand()%5 + 1);
teller[j]->setservertime(SERVICETIME);
arrivetime = arrivalMachine.getarrivetime(numclient);
if(arrivetime!=-1)
{AttenteTemps = (minute+m) - arrivetime;
totalAttenteTemps += AttenteTemps;
if(AttenteTemps>0)
totalAttenteCustomers++;
if((minute+m)+SERVICETIME-1 > MAXTIME)
{}
// totalServiceTemps += MAXTIME-(minute+m)+1;
else{
totalServiceTemps += SERVICETIME;
totalServiceCustomers++;
}
teller[j]->StartService (numclient);
line.pop ();
}
}
}
if(mode==1)
cout<< *teller[j] << " ";
}
if(mode==1)
cout << line << endl;
}
minute += interarrival;
}
cout<<endl;
if(totalAttenteCustomers > 0)
duree_moyen_attente = (double)totalAttenteTemps/(double)totalAttenteCustomers;
if(totalServiceCustomers > 0)
duree_moyen_service = (double)totalServiceTemps/(double)totalServiceCustomers;
cout<<"|----------------------LE RESULTAT DE SIMULTTION--------------------------|"<<endl;
cout<<"| |"<<endl;
cout<<"| Le temps Total d'Attente:"<<totalAttenteTemps<<endl<<endl;
cout<<"| Le nombre Total de Customers attentes:"<<totalAttenteCustomers<<endl<<endl;
cout<<"| Le temps moyen d'attente: "<<duree_moyen_attente<<" |"<< endl;
cout<<"| |"<<endl;
cout<<"| Le temps Total de Sercice:"<<totalServiceTemps<<endl<<endl;
cout<<"| Le nombre Total de Customers servis:"<<totalServiceCustomers<<endl<<endl;
cout<<"| Le temps moyen de service: "<<duree_moyen_service<<" |"<<endl;
cout<<"| Le temps moyen d'action:"<<tr<<" |"<<endl;
cout<<"| Le temps moyen de reponse:"<<duree_moyen_attente+tr+duree_moyen_service<<endl;
cout<<"|-------------------------------------------------------------------------|"<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -