?? blockpro1.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 + -