⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queuemmmk.cpp

📁 简单的 Discrete Event Simulator M/M/K/K queue 含Readme。 可在此基础上开发复杂的仿真程序 请用 tar -xzvf sim.tar.gz 解压
💻 CPP
字号:
/***************************************************************************                          queuemmmk.cpp  -  description                             -------------------    begin                : Thu Oct 16 2003 ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/#include "queuemmmk.h"QueueMMmK::~QueueMMmK(){	elist.clear();}/** No descriptions */void QueueMMmK::reset(){ // initialize all states and statistics    Nsys = Narr = Ndep = Nblock = Nqueue = 0;    area = clock = 0.0;}void QueueMMmK::simulate(int departures){  reset();                        // clear states and statistics  Event* CurrentEvent;  elist.insert(exp_rv(lambda),ARR); // Generate first arrival event  while (Ndep < departures)  {    CurrentEvent = elist.get();               // Get next Event from list    double prev = clock;                      // Store old clock value    clock=CurrentEvent->time;                 // Update system clock    area += Nsys*(clock-prev);                   //  update system statistics    switch (CurrentEvent->type) {    case ARR:                                 // If arrival        Narr++;        elist.insert(clock+exp_rv(lambda),ARR); //  generate next arrival        if (Nsys == qK)                          // if system capacity is full, the request is blocked            Nblock++;        else        {            Nsys++;            if (Nsys>qm)                Nqueue++;                           // put in the queue if all servers are busy            else                elist.insert(clock+exp_rv(mu),DEP); //  generate departure event for current customer        }      break;    case DEP:                                 // If departure      Nsys--;                                 //  decrement system size      Ndep++;                                 //  increment num. of departures      if (Nqueue > 0)                         // If the queue is not empty      {        Nqueue--;                  elist.insert(clock+exp_rv(mu),DEP);   //  generate next departure for the customers coming from queue      }      break;    }    delete CurrentEvent;  }}double QueueMMmK::exp_size()  // expected number of customers in system{    double s=0;    double p=1;    double q=1;     int n;    for (n=1; n<=qm; n++)    {        q*=(lambda/mu/n);        p+=q;        s+=n*q;    }    for (n=qm+1; n<=qK; n++)    {        q*=(lambda/mu/qm);        p+=q;        s+=n*q;    }    return (s/p);}double QueueMMmK::exp_time()  // expected time in system{    return exp_size()/(lambda*(1-exp_blocking()));}double QueueMMmK::exp_blocking()  // expected blocking{    double p=1;    double q=1;    int n;    for (n=1; n<=qm; n++)    {        q*=(lambda/mu/n);        p+=q;    }    for (n=qm+1; n<=qK; n++)    {        q*=(lambda/mu/qm);        p+=q;    }    return (q/p);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -