Thursday 21 April 2016

Two Channel Queuing System

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{ int nt,np,i,j;
int t[10],at[10],bt[10];
float p[20],ap[20],bp[20],ct[20],ca[20],cb[20];
int ra[20],rs[20];
clrscr();
printf("Enter the no. of time between arrivals:");
scanf("%d",&nt);
printf("Enter the no. of service time: ");
scanf("%d",&np);
printf("Enter the time between arrivals:");
for(i=0;i<nt;i++)
scanf("%d%f",&t[i],&p[i]);
printf("Enter the Service time for Able:");
for(i=0;i<np;i++)
scanf("%d%f",&at[i],&ap[i]);
printf("Enter the Service time for Baker:");
for(i=0;i<np;i++)
scanf("%d%f",&bt[i],&bp[i]);
//Calculating cumulative freqs
ct[0]=p[0];ca[0]=ap[0];cb[0]=bp[0];
for(i=1;i<nt;i++)
ct[i]= ct[i-1]+p[i];
for(i=1;i<np;i++)
{ ca[i]=ca[i-1]+ap[i];
cb[i]=cb[i-1]+bp[i];
}
randomize();
for(i=0;i<12;i++)
{ ra[i]=rand()%100;
rs[i]=rand()%100;
}
int tba[20],atsb[20],btsb[20],ast[20],bst[20],atse[20],btse[20];
int tq[20],cta[20],ab[20],st[20],tsb[20],tse[20];
ra[0]=0;
for(i=0;i<12;i++)
{ for(j=0;j<nt;j++)
if(ra[i]< (ct[j]*100))
{ tba[i]=t[j];
break;
}
}
for(i=0;i<12;i++)
{ for(j=0;j<np;j++)
{ if(rs[i]< (ca[j]*100))
{ ast[i]=at[j];
break;
}
if(rs[i]< (cb[j]*100))
{ bst[i]=bt[j];
break;
}
}
}
tba[0]=0;cta[0]=0;tsb[0]=0;st[0]=ast[0];
tse[0]=tsb[0]+st[0];tq[0]=0;ab[0]=0;btse[0]=0;
for(i=1;i<12;i++)
{ cta[i]=cta[i-1]+tba[i];
if(tse[i-1]<=cta[i])
{ ab[i]=0;
tsb[i]=cta[i];
st[i]=ast[i];
tse[i]=tsb[i]+st[i];
}
else if(tse[i-1]>cta[i])
{ if(btse[i-1]<=tse[i-1])
{ ab[i]=1;
tsb[i]=cta[i];
st[i]=bst[i];
tse[i]=tsb[i]+st[i];
btse[i]=tse[i];
}
else
{ ab[i]=0;
tsb[i]=tse[i-1];
st[i]=ast[i];
tse[i]=tsb[i]+st[i];
}
}
tq[i]=tsb[i]-cta[i];
}
printf("\nThe Simulation Table is as follows:\n");
printf("\t\t\tAble        Baker\n");
printf("\nAoc  rda tba cta rds tsb  st tse tsb  st tse  tq");
for(i=0;i<5;i++)
{ printf("\n%2d   %2d   %2d  %2d  %2d",i+1,ra[i],tba[i],cta[i],rs[i]);
if(ab[i]==0)
printf("  %2d  %2d  %2d  --  --  --  ",tsb[i],st[i],tse[i]);
else
printf("  --  --  --  %2d  %2d  %2d  ",tsb[i],st[i],tse[i]);
printf("%2d",tq[i]);
}
getch();
}

1 comment:

  1. thanks for a nice information. this is a very nice and pretty information.

    Queuing system

    ReplyDelete