FEL is Future event list. A list of event notices for future events. The event notice must contain all the information necessary to execute the event (in particular the time it is scheduled to occur). The event list is the main data structure in a discrete-event simulator so its important to code for FEL.
#include<stdio.h>
#include<conio.h>
/*****************************FEL for a grocery shop!!**********************************/
//Defining structure for customer!!
typedef struct
{
int cno,inter_arr,arr_time,ser_time,beg_time,wait_time,end_time,sys_time,idle_time;
}cust;
//Defining structure for FEL because we have entries for arrival,departure,end & their respective time!!
typedef struct
{
char ename;
int time;
}event;
//For lookup function for inter-arrival time!!
int lookup_interarr(int i)
{
if(i>=0 && i<13)
return 1;
else if(i>=13 && i<25)
return 2;
else if(i>=25 && i<38)
return 3;
else if(i>=38 && i<50)
return 4;
else if(i>=50 && i<63)
return 5;
else if(i>=63 && i<75)
return 6;
else if(i>=75 && i<87)
return 7;
else
return 8;
}
//Lookup function for service time!!
int lookup_service(int s)
{
if(s>=0 && s<11)
return 1;
else if(s>=11 && s<31)
return 2;
else if(s>=31 && s<61)
return 3;
else if(s>=61 && s<86)
return 4;
else if(s>=86 && s<96)
return 5;
else
return 6;
}
//Function for printing customer details!!
void print_cust(cust c)
{
getch();
printf("\n");
printf("%d\t",c.cno);
printf("%d\t",c.inter_arr);
printf("%d\t",c.arr_time);
printf("%d\t",c.ser_time);
printf("%d\t",c.beg_time);
printf("%d\t",c.wait_time);
printf("%d\t",c.end_time);
printf("%d\t",c.sys_time);
printf("%d\t",c.idle_time);
}
//For customer one we assign the variables!!
cust initial_cust(cust c)
{
c.cno=1;
c.inter_arr=0;
c.arr_time=0;
c.ser_time=lookup_service(rand()%100);
c.beg_time=0;
c.wait_time=0;
c.end_time=c.ser_time;
c.sys_time=c.ser_time;
c.idle_time=0;
print_cust(c);
return c;
}
//Function for checking max among two!!
int maximum(int end,int arr)
{
return end>=arr?end:arr;
}
//Function for printing FEL!!
void print_fel(event fel[],int t)
{
int i,temp;
char tmp;
if(fel[0].time>fel[1].time)
{
temp=fel[0].time;
fel[0].time=fel[1].time;
fel[1].time=temp;
tmp=fel[0].ename;
fel[0].ename=fel[1].ename;
fel[1].ename=tmp;
}
for(i=0;i<3;i++)
printf("(%c,%d)",fel[i].ename,fel[i].time);
printf("\n%d\t",t);
}
//Main body!!
void main()
{
cust c[30];
event fel[3];
int i,t=0,inter=1,depr=0;
clrscr();
printf("\n\n\nNOTE:""Press any key to see entries one by one!!""");
getch();
clrscr();
printf("\n*************************Grocery Shop Simulation Entries**********************\n");
printf("Custno\tIntrAr\tArr\tSerTime\tBeg\tWait\tEnd\tSysTime\tIdle");
c[0]=initial_cust(c[0]);
for(i=1;i<30;i++)
{
c[i].cno=i+1;
c[i].inter_arr=lookup_interarr(rand()%100);
c[i].arr_time=c[i-1].arr_time+c[i].inter_arr;
c[i].ser_time=lookup_service(rand()%100);
c[i].beg_time=maximum(c[i-1].end_time,c[i].arr_time);
c[i].wait_time=c[i].beg_time-c[i].arr_time;
c[i].end_time=c[i].beg_time+c[i].ser_time;
c[i].sys_time=c[i].ser_time+c[i].wait_time;
c[i].idle_time=c[i-1].beg_time>c[i].arr_time?0:c[i].arr_time-c[i-1].beg_time;
print_cust(c[i]);
}
printf("\n******************************************************************************");
printf("\n\nPress any key if you want to see FEL!!");
getch();
fel[0].ename='A';
fel[0].time=0;
fel[1].ename='D';
fel[1].time=c[0].ser_time;
fel[2].ename='E';
fel[2].time=60;
clrscr();
printf("\n***********************FEL***********************\n");
printf("Time \tFEL\n%d\t",t);
while(t<60)
{ //If its a inter_arrival event add to arrival!! As we do as (A,30) for example!!
if(fel[0].time==t)
{
fel[0].time=t+c[inter].inter_arr;
inter++;
}
//If its a departure event add to departure!! As we do as (D,30) for example!!
{
if(fel[1].time==t)
{
fel[1].time= t+c[depr].ser_time;
depr++;
}
t++;
print_fel(fel,t);
}
getch();
}
printf("\n\n****************************************************************");
}
by Aanchal Gupta(MCA/4510/11)
Comments