我已经开始创建一个 c++ 程序来模拟 FiFo 等作业调度算法。我还远未完成,但我现在的主要问题是如何在我的程序中创建时间流。
到目前为止,这是我的主要代码:
for (i = 1; i < 10; i++)
{
Time1 = clock();
//this is the alogrithm to generate poisson arrival sequence
do{
k = k + 1;
// Generate a random number between 0 and 1
// return a uniform number in [0,1].
double u = rand() / (double)RAND_MAX;
p = p * u;
}while (p > L);
A[i] = k-1;
Time2 = clock();
DT = Time2 -Time1;
TotalTime=TotalTime + DT;
cout << " Total time " << TotalTime
<< " table :" << A[i]
<< " Arrival Time "
<< TotalTime <<endl ;
我的主要问题是:我的时钟时间测量单位是时钟()函数输出的时间单位是“奇怪”的数字。我应该使用其他功能吗?
10 次迭代的结果
Total time 6.19522e+032 table :28 Arrival Time 6.19522e+032
Total time 6.19522e+032 table :29 Arrival Time 6.19522e+032
Total time 6.19522e+032 table :30 Arrival Time 6.19522e+032
Total time 6.19522e+032 table :31 Arrival Time 6.19522e+032
Total time 6.19522e+032 table :32 Arrival Time 6.19522e+032
Total time 6.19522e+032 table :33 Arrival Time 6.19522e+032
Total time 6.19522e+032 table :34 Arrival Time 6.19522e+032
Total time 6.19522e+032 table :35 Arrival Time 6.19522e+032
Total time 6.19522e+032 table :36 Arrival Time 6.19522e+032
PS:如果你想在你的机器上运行它,我可以提供其余的代码。