资源简介

排队论MM1模型的C++仿真程序,程序中输入lambda,mu和total arrival之后就可以根据参数进行仿真并得出一系列的统计结果

资源截图

代码片段和文件信息

// EE 465 USC
// Simulation of an M/M/1 system

#include 
#include 
#include 
#include 

using namespace std;

#define INFIN   999999999

// Function Name: expon
// Description:  Generates an exponentially distributed random number 
// with parameter \lambda. 
// Input:  lambda (double)
// Output:  An exponentially distributed random number (double)
//
double expon(double lambda)
{
double u; // used to store a random number. 

do
{
u = drand48(); //uniform number in the interval [0.0 1.0]
}
while ((u == 0) || (u == 1)); //special cases that we want to avoid

return -log(1-u)/lambda;

}

// Function Name: print_stats
// Description:  Saves and prints system statistics 
// Input:           stats_file (ostream object): ostream object for the stats file
// avg_customers (double): average customers in the system
// avg_service_time (double): average service time 
// Output:  void (output stored to file and printed in the screen)
//
void print_stats(ostream &stats_file double avg_customers double avg_service_time)
{
cout << “Average No. of Customers: “ << avg_customers << endl;
cout << “Average Service Time: “ << avg_service_time << endl;

stats_file << “Average No. of Customers: “ << avg_customers << endl;
stats_file << “Average Service Time: “ << avg_service_time << endl;
}

// The main function of the program that is called at the beginning.
int main() {
//system variables
long int tot_arrivals cur_arrivals = 0;
double lambda mu;
double event1 = 0.0 event2

评论

共有 条评论