Name :-Khushboo
Roll no:-MCA/4518/10
#include
#include
#include
#define MAX 5
typedef struct arrival
{
float prob;
float c_prob;
int min;
};
typedef struct service
{
float prob;
float c_prob;
int min;
};
typedef struct simulation
{
int cust_no;
float random; int inter_arr;
int c_inter_arr;
float rand_no;
int service_tym;
int s_start; int s_end;
int w_tym;
int t_s_tym;
int idle_tym;
};
typedef struct FEL {
char ch;
int min;
int cust_no; };
FEL fel[(MAX*2)];
arrival arr[8];
service ser[6];
simul ation sim[MAX];
void arr_prob() {
int i;
for(i=0;i<8;i++)
{
arr[i].min=i+1;
arr[i].prob=.125;
if(i==0)
arr[i].c_prob=0.0;
else
arr[i].c_prob=arr[i-1].c_prob+arr[i-1].prob; }
}
void ser_prob() {
int i;
ser[0].prob=0.1;ser[1].prob=0.2;ser[2].prob=0.3;
ser[3].prob=0.25;ser[4].prob=0.1;
ser[5].prob=0.05;
for(i=0;i<6;i++)
{
ser[i].min=i+1;
if(i==0)
ser[i].c_prob=0.0;
else
ser[i].c_prob=ser[i-1].c_prob+ser[i-1].prob; }
}
int ser_tym(float x) {
int i;
for(i=5;i>=0;i--)
if(x>=arr[i].c_prob)
break;
return(ser[i].min); }
int arr_tym(float x) {
int i;
for(i=7;i>=0;i--)
if(x>=arr[i].c_prob)
break;
return(arr[i].min); }
int max(int x,int y)
{
return(x>y?x:y);
}
int wait(int x,int y) {
if(x>y) return(x-y);
else
return 0;
}
int idle(int x,int y)
{
if(x return(y-x);
else
return 0;
} void init()
{
int i=0;
for(i=0;i
{
if(i==0)
{
sim[i].cust_no=i+1;
sim[i].random=0.0;
sim[i].inter_arr=0;
sim[i].c_inter_arr=0;
sim[i].rand_no=(float)(rand()%100)/100;
sim[i].service_tym=ser_tym(sim[i].rand_no);
sim[i].s_start=0;
sim[i].s_end=sim[i].s_start+sim[i].service_tym;
sim[i].w_tym=0;
sim[i].t_s_tym=sim[i].s_end-sim[i].c_inter_arr;
sim[i].idle_tym=0;
}
else
{
sim[i].cust_no=i+1;
sim[i].random=(float)(rand()%100)/100;
sim[i].inter_arr=arr_tym(sim[i].random);
sim[i].c_inter_arr=sim[i-1].c_inter_arr+sim[i].inter_arr;
sim[i].rand_no=(float)(rand()%100)/100;
sim[i].service_tym=ser_tym(sim[i].rand_no);
sim[i].s_start=max(sim[i-1].s_end,sim[i].c_inter_arr);
sim[i].s_end=sim[i].s_start+sim[i].service_tym;
sim[i].w_tym=wait(sim[i-1].s_end,sim[i].c_inter_arr);
sim[i].t_s_tym=sim[i].s_end-sim[i].c_inter_arr;
sim[i].idle_tym=idle(sim[i-1].s_end,sim[i].c_inter_arr);
}
} } void print()
{
int i;
printf("c_no rand i_arr arr rand serv start end wait t_s_tym i_tym\n\n"); for(i=0;i
{
printf("%d%10.3f%5d",sim[i].cust_no,sim[i].random,sim[i].inter_arr);
printf("%6d%7.2f%5d",sim[i].c_inter_arr,sim[i].rand_no,sim[i].service_tym);
printf("%7d%5d%7d",sim[i].s_start,sim[i].s_end,sim[i].w_tym);
printf("%7d%10d\n",sim[i].t_s_tym,sim[i].idle_tym);
} } void create_fel()
{
int i=0,j=0,k=0;
printf("FEL (A=arrival,D=depart)\n\n");
for(;j
{
if(sim[j].c_inter_arr
#include
#include
#define MAX 5
typedef struct arrival
{
float prob;
float c_prob;
int min;
};
typedef struct service
{
float prob;
float c_prob;
int min;
};
typedef struct simulation
{
int cust_no;
float random; int inter_arr;
int c_inter_arr;
float rand_no;
int service_tym;
int s_start; int s_end;
int w_tym;
int t_s_tym;
int idle_tym;
};
typedef struct FEL {
char ch;
int min;
int cust_no; };
FEL fel[(MAX*2)];
arrival arr[8];
service ser[6];
simul ation sim[MAX];
void arr_prob() {
int i;
for(i=0;i<8;i++)
{
arr[i].min=i+1;
arr[i].prob=.125;
if(i==0)
arr[i].c_prob=0.0;
else
arr[i].c_prob=arr[i-1].c_prob+arr[i-1].prob; }
}
void ser_prob() {
int i;
ser[0].prob=0.1;ser[1].prob=0.2;ser[2].prob=0.3;
ser[3].prob=0.25;ser[4].prob=0.1;
ser[5].prob=0.05;
for(i=0;i<6;i++)
{
ser[i].min=i+1;
if(i==0)
ser[i].c_prob=0.0;
else
ser[i].c_prob=ser[i-1].c_prob+ser[i-1].prob; }
}
int ser_tym(float x) {
int i;
for(i=5;i>=0;i--)
if(x>=arr[i].c_prob)
break;
return(ser[i].min); }
int arr_tym(float x) {
int i;
for(i=7;i>=0;i--)
if(x>=arr[i].c_prob)
break;
return(arr[i].min); }
int max(int x,int y)
{
return(x>y?x:y);
}
int wait(int x,int y) {
if(x>y) return(x-y);
else
return 0;
}
int idle(int x,int y)
{
if(x
return 0;
} void init()
{
int i=0;
for(i=0;i
{
sim[i].cust_no=i+1;
sim[i].random=0.0;
sim[i].inter_arr=0;
sim[i].c_inter_arr=0;
sim[i].rand_no=(float)(rand()%100)/100;
sim[i].service_tym=ser_tym(sim[i].rand_no);
sim[i].s_start=0;
sim[i].s_end=sim[i].s_start+sim[i].service_tym;
sim[i].w_tym=0;
sim[i].t_s_tym=sim[i].s_end-sim[i].c_inter_arr;
sim[i].idle_tym=0;
}
else
{
sim[i].cust_no=i+1;
sim[i].random=(float)(rand()%100)/100;
sim[i].inter_arr=arr_tym(sim[i].random);
sim[i].c_inter_arr=sim[i-1].c_inter_arr+sim[i].inter_arr;
sim[i].rand_no=(float)(rand()%100)/100;
sim[i].service_tym=ser_tym(sim[i].rand_no);
sim[i].s_start=max(sim[i-1].s_end,sim[i].c_inter_arr);
sim[i].s_end=sim[i].s_start+sim[i].service_tym;
sim[i].w_tym=wait(sim[i-1].s_end,sim[i].c_inter_arr);
sim[i].t_s_tym=sim[i].s_end-sim[i].c_inter_arr;
sim[i].idle_tym=idle(sim[i-1].s_end,sim[i].c_inter_arr);
}
} } void print()
{
int i;
printf("c_no rand i_arr arr rand serv start end wait t_s_tym i_tym\n\n"); for(i=0;i
printf("%d%10.3f%5d",sim[i].cust_no,sim[i].random,sim[i].inter_arr);
printf("%6d%7.2f%5d",sim[i].c_inter_arr,sim[i].rand_no,sim[i].service_tym);
printf("%7d%5d%7d",sim[i].s_start,sim[i].s_end,sim[i].w_tym);
printf("%7d%10d\n",sim[i].t_s_tym,sim[i].idle_tym);
} } void create_fel()
{
int i=0,j=0,k=0;
printf("FEL (A=arrival,D=depart)\n\n");
for(;j
Comments