排队论M/M/S混合制排队模型 C++代码
时间: 2023-08-25 14:07:34 浏览: 135
以下是一个简单的排队论M/M/S混合制排队模型的C++代码示例:
```cpp
#include <iostream>
#include <cmath>
using namespace std;
double factorial(int n) {
if (n == 0) {
return 1.0;
} else {
return n * factorial(n - 1);
}
}
double poisson(double lambda, int n) {
return pow(lambda, n) * exp(-lambda) / factorial(n);
}
double mmss(double lambda, double mu1, double mu2, int s) {
double rho = lambda / (s * mu1 + mu2);
double p0 = 0.0;
for (int i = 0; i <= s; i++) {
p0 += poisson(lambda / (s * mu1 + mu2), i);
}
p0 += poisson(lambda / (s * mu1 + mu2), s) * (1.0 - pow(rho, s + 1)) / (1.0 - rho);
double lq = pow(lambda / (s * mu1 + mu2), s + 1) * rho / (factorial(s) * pow(1.0 - rho, 2));
double wq = lq / lambda;
double w = 1.0 / mu1 + wq;
double l = lambda * w;
double ls = pow(lambda / (s * mu1 + mu2), s) * rho * (1.0 - rho) / (factorial(s) * pow(1.0 - rho, 2));
double ws = ls / mu2;
double lsys = l + ls;
double wsys = w + ws;
cout << "P0: " << p0 << endl;
cout << "Lq: " << lq << endl;
cout << "Wq: " << wq << endl;
cout << "W: " << w << endl;
cout << "L: " << l << endl;
cout << "Ls: " << ls << endl;
cout << "Ws: " << ws << endl;
cout << "Lsys: " << lsys << endl;
cout << "Wsys: " << wsys << endl;
}
int main() {
double lambda, mu1, mu2;
int s;
cout << "Enter arrival rate (lambda): ";
cin >> lambda;
cout << "Enter service rate at server 1 (mu1): ";
cin >> mu1;
cout << "Enter service rate at server 2 (mu2): ";
cin >> mu2;
cout << "Enter number of servers at first station (s): ";
cin >> s;
mmss(lambda, mu1, mu2, s);
return 0;
}
```
该程序首先定义了一个阶乘函数和一个泊松分布函数,然后定义了一个mmss函数,该函数接受到达率lambda,第一台服务器的服务率mu1,第二台服务器的服务率mu2和第一台服务器的数量s,并计算出排队论模型的各种指标。最后,程序通过从用户获取输入来调用mmss函数并输出结果。
阅读全文