資源簡介
排隊論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:?“?< cout?<“Average?Service?Time:?“?<
stats_file?<“Average?No.?of?Customers:?“?< stats_file?<“Average?Service?Time:?“?<}
//?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
評論
共有 條評論