📄 blockprobablity.cpp
字号:
#include "stdio.h"
#include "math.h"
#define UL unsigned long
#define znew (z=36969*(z&65535)+(z>>16))
#define wnew (w=18000*(w&65535)+(w>>16))
#define MWC ((znew<<16)+wnew)
#define SHR3 (jsr^=(jsr<<17),jsr^=(jsr>>13),jsr^=(jsr<<5))
#define CONG (jcong=69069*jcong+1234567)
#define FIB ((b=a+b),(a=b-a))
#define KISS ((MWC^CONG)+SHR3)
#define LFIB4 (c++,t[c]=t[c]+t[UC(c+58)]+t[UC(c+119)]+t[UC(c+178)])
#define SWB (c++,bro=(x<y),t[c]=(x=t[UC(c+58)])-(y=t[UC(c+19)]+bro))
#define UNI (KISS*2.328306e-10)
#define VNI ((long) KISS)*4.656613e-10
#define UC (unsigned char)/*a cast operation*/
#define pi 3.14159
#define mu 0.1
#define N 1000
/* Global static variables: */
static UL z=362436069, w=521288629, jsr=123456789, jcong=380116160;
static UL a=224466889,b=7584631,t[256];
static UL x=0,y=0,bro; static unsigned char c=0;
/* Random seeds must be used to reset z,w,jsr,jcong and
the table t[256] Here is an example procedure, using KISS: */
FILE *f;
//**********业务初始化************
struct customer
{
int arrive_time;
int leave_time;
int flag;
}customer[N];
//**********产生随机数*************
void settable(UL i1,UL i2,UL i3,UL i4,UL i5,UL i6)
{ int i; z=i1;w=i2,jsr=i3; jcong=i4,a=i5,b=i6;
for(i=0;i<256;i++) t[i]=KISS; }
double block(double ld)
{
int k;
double a[2*N];
settable(12345,65435,34221,12345,9983651,95746118);
for(k=0;k<2*N;k++)
{
a[k]=UNI;
// fprintf(f,"%f ",a[k]);
}
//************产生到达顾客间隔******************
double y[N];
for(k=0;k<N;k++)
{
y[k]=-log(a[k])/ld;
fprintf(f,"%f ",y[k]);
}
//************产生顾客到达时刻******************
double z[N]; z[0]=0.000;
for(k=1;k<N;k++)
{
z[k]=z[k-1]+y[k-1];
fprintf(f,"%f ",z[k]);
}
//************产生顾客服务间隔******************
double x[N];
for(k=0;k<N;k++)
{
x[k]=-log(a[k+N])/mu;
fprintf(f,"%f ",x[k]);
}
//************产生顾客离开时刻******************
double w[N]; w[0]=0.000;
for(k=1;k<N;k++)
{
w[k]=z[k]+x[k];
fprintf(f,"%f ",w[k]);
}
int C;
C=15; //服务器数
customer[0].arrive_time =customer[0].leave_time=0;
for(int i=1;i<N;i++)
{
customer[i].arrive_time=(int)(100*z[i]); //扩大100倍表示以10ms为一个计时单位
fprintf(f,"%d ",customer[i].arrive_time); //将到达时刻转换为整数
}
fprintf(f,"\n");
fprintf(f,"\n");
for(i=1;i<N;i++)
{
customer[i].leave_time=(int)(100*w[i]);
fprintf(f,"%d ",customer[i].leave_time); //将离开时刻转换为整数
}
fprintf(f,"\n");
int n;
n=0;
int j;
for(j=0;j<N;j++)
{
customer[j].flag=0;
}
int T;
T=int(100*N/ld);
for(i=0;i<T;i++)
{
for(j=1;j<N;j++)
{
if((i==customer[j].arrive_time)&&(C==0))
{
n++;
customer[j].flag=1;
}
if((i==customer[j].arrive_time)&&(C>0)) C--; //如果该时刻有顾客到达则服务器数减1
if((i==customer[j].leave_time)&&(customer[j].flag==0)) C++;
}
}
printf("产生被阻塞的顾客数:");
printf("%d \n",n);
float blockpro;
blockpro=(float)n/(N-1);
printf("阻塞率为:");
printf("%f \n",blockpro);
return blockpro;
}
void main()
{
f=fopen("out.txt","w");
double ld,blockpro;
ld=0.1;
do{
ld=ld+0.1; printf("ld=%f\n",ld);
blockpro=block(ld); printf("\n");
fprintf(f,"%f ",blockpro);
}while(ld<1.0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -