/* 窓口シミュレーション */ #include #include #include #define NMAX 10000 void swap(double *x, double *y); void BubbleSort(int ndata, double data[NMAX]); main() { unsigned int seed; int i,j; int nstep, istep; float a1; double tt[NMAX]; int t1; int n1; double b1, b2, c; double t, dt, tnext; int np, jp; FILE *output; output = fopen("ev.dat","w"); printf("Input: seed \n"); scanf("%u", &seed); printf("Input: Zikan:\n"); scanf("%u", &t1); printf("Input: Kosuu:\n"); scanf("%u", &n1); printf("Input: c:\n"); scanf("%lf", &c); b1=(double)t1/(double)n1; b2=c*b1; srand(seed); for(i=0; i < n1; i++){ j=rand(); a1=j/(RAND_MAX+1.0); tt[i]=t1*a1; /* printf("i= %d, tt=%.5f\n",i,tt[i]); */ /* fprintf(output, "%d %f\n",istep,x); */ } BubbleSort(n1, tt); for(i=0; i < n1; i++){ printf("i= %d, tt=%.5f\n",i,tt[i]); } dt=0.1; nstep=t1/dt; t=0.0; jp=0; np=0; tnext=1e10; for(i=0; i tt[jp] && jp != n1){ jp++; np++; if(np == 1){ tnext=t+b2; } } if(np > 0 && t > tnext){ np--; if(np > 0) { tnext=t+b2; }else{ tnext=1e10; } } printf("istep= %d, t=%lf, tnext=%lf, jp=%d, np=%d\n",i,t,tnext,jp,np); fprintf(output, "%d %lf %d\n",i,t,np); } return; } void BubbleSort(int ndata, double data[NMAX]) { int flag, i, j; flag = 1; for(i = ndata-2; i >=0 && flag == 1; i--) { flag = 0; for(j = 0; j <= i; j++) if(data[j] > data[j+1]) { swap(&data[j], &data[j+1]); flag = 1; } } } void swap(double *x, double *y) { double z; z = *x; *x = *y; *y = z; }