Friday, July 15, 2011

Single Channel Queue Problem

#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<iomanip.h>


void main()
{
clrscr();
int i,j,c,rat[20],rst[20],at[20],st[20],stb[20],ste[20],cwq[20],css[20],its[20];
float pa[9],ps[7],iat;
int wtime=0;
float wcust=0.0;
float tservice=0.0;
float tidle=0.0;
float time_arr=0.0;
float time_spent=0.0;
cout<<"Enter no of inter arrival times ( less than 8 minutes)";
cin>>iat;
pa[0]=0;ps[0]=0;
for(i=1;i<=iat;i++)
pa[i]=(float)((1/iat)*1000);


for(i=1;i<=6;i++)
{
cout<<"\nEnter probability for service time "<<i<<" minute";
cin>>ps[i];
ps[i]*=100;
}




cout<<"Enter number of customers (number should be less than 20)";
cin>>c;


for(i=1;i<=iat;i++)
pa[i]+=pa[i-1];


for(i=1;i<=6;i++)
ps[i]+=ps[i-1];


for(i=0;i<c;i++)
{
rat[i]=random(1000);
rst[i]=random(100);




for(j=0;j<iat;j++)
{
if(rat[i]>pa[j] && rat[i]<=pa[j+1])
at[i]=j+1;
}


for(j=0;j<6;j++)
{
if( rst[i]==0)
st[i]=6;
if(rst[i]>ps[j] && rst[i]<=ps[j+1])
st[i]=j+1;
}
}
at[0]=0;
for(i=1;i<=(iat+1);i++)
at[i]+=at[i-1];


stb[0]=0;
ste[0]=stb[0]+st[0];


for(i=1;i<c;i++)
{
if(at[i]>ste[i-1])
stb[i]=at[i];
else
stb[i]=ste[i-1];
ste[i]=stb[i]+st[i];
}
its[0]=0;
for(i=0;i<c;i++)
{
cwq[i]=stb[i]-at[i];
css[i]=cwq[i]+st[i];
if(i>0)
its[i]=stb[i]-ste[i-1];
}
for(i=0;i<c;i++)
{
wtime=cwq[i]+wtime;
tservice=st[i]+tservice;
tidle=its[i]+tidle;
time_arr=at[i]+time_arr;
time_spent=css[i]+time_spent;
if(cwq[i]!=0)
wcust++;
}


clrscr();
cout<<"\ncust      at   st   tsb    tse   cwq   css  its";
for(i=0;i<c;i++)
cout<<"\n"<<setw(5)<<i+1<<setw(7)<<at[i]<<setw(5)<<st[i]<<setw(5)<<stb[i]<<setw(6)<<ste[i]<<setw(6)<<cwq[i]<<setw(6)<<css[i]<<setw(6)<<its[i];
cout<<"\nAVERAGE WAITING TINE FOR CUSTOMERS"<<"\n"<<wtime/c<<"\n";
cout<<"PROBABILITY THAT CUSTOMER HAS TO WAIT IN QUEUE"<<"\n"<<wcust/c<<"\n";
cout<<"FRACTION OF IDLE TIME OF SERVER"<<"\n"<<tidle/tservice<<"\n";
cout<<"AVERAGE SERVICE TIME "<<"\n"<<tservice/c<<"\n";
cout<<"AVERAGE TIME BETWEEN ARRIVAL"<<"\n"<<time_arr/(c-1)<<"\n";
cout<<"AVERAGE WAITING TIME FOR THOSE WHO WAIT"<<"\n"<<wtime/wcust<<"\n";
cout<<"AVERAGE TIME CUSTOMER SPENDS ON SYSTEM"<<"\n"<<time_spent/c<<"\n";




getch();
}




/*
OUTPUT

cust      at   st   tsb    tse   cwq   css  its
    1      0    1    0       1      0      1     0
    2      3    1    3       4      0      1     2
    3      6    2    6       8      0      2     2
    4     11    2   11    13     0      2     3
    5     17    5   17    22     0      5     4
    6     20    3   22    25     2      5     0
    7     21    4   25    29     4      8     0
    8     26    1   29    30     3      4     0
    9     28    4   30    34     2      6     0
   10     34    4   34    38     0     4     0

*/

No comments:

Post a Comment