📄 arrivalgen.h
字号:
#ifndef ARRIVALGEN_H
#define ARRIVALGEN_H
#include <cstdlib>
#include <math.h>
//class invariant for the arrivalGenerator class:
//An arrivalGenerator object generates the number of the next person arriving
// for service, if there is one. Whether or not a person arrives is
// determined at random according to a set probability.
//The arrivalGenerator object contains:
// 1) The probability that is used to determine if an arrival occurs.
// 2) The number of the next arrival, as an identifier for that person.
//The srand function takes an int number as a seed. It uses the seed to generate a long sequence of (pseudo) random numbers between 0 and a large maximum called MAX_RAND. Since srand sets up a whole sequence of numbers, the program should not call srand more than once.
//The rand() function actually returns the next number in the random sequence. Use rand () wherever you need a random number
class arrivalGenerator
{
public:
arrivalGenerator (int s, double P,int intertime)
{
srand (s); //seed the random sequence
probability = P;
nextCustomer = -1;
// timer = 0;
inter = intertime;
}
bool isArrival (int arrivetime)
{
bool returnVal = false;
// double event = rand () % 100 + 1; //Get a random number betw
// 1 and 100
// if (event / 100.0 <probability) //Determine if an arrival
// occurred
// { // timer++;
//if(timer== inter){
returnVal = true;
nextCustomer++;
arrivaldate[nextCustomer] = arrivetime;
// timer=0;
//}
// }
return returnVal;
}
int Duree_entre_deux_arrive()
{
double returnval;
returnval = (double) (-log(1.0 - (double)((rand() % 100) / 100.0))*inter);
if(returnval<0.5) return(0);
else if(returnval<1.0) return(1);
else return((int)returnval);
}
double getpropale(){
double propa = rand() % 101;
return( propa/100.0);
}
int getArrival ()
{
return nextCustomer;
}
int getarrivetime(int numcustomer){
return arrivaldate[numcustomer];
}
void cleararrivetime(int numcustomer){
arrivaldate[numcustomer] = -1;
}
private:
double probability;
int nextCustomer;
// int timer ;
int inter;
int arrivaldate[MAXSIZE];
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -