Friday, July 15, 2011

Abel And Baker Problem

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


void main()
{
clrscr();
    int i,j,cust;

cout<<"Enter the number of customers (<20) : ";
cin>>cust;
float rar[20];         //Random assignment of arrival
for(i=0;i<cust;i++)
{
rar[i]=random(100);
}
cout<<"Enter prabability for arrivals : ";
float par[20];        //Probability of Arrival
for(i=0;i<4;i++)
cin>>par[i];
float cumar[20];       // Cumilitive of Arrival
for(i=0;i<4;i++)
{
if(i==0)
cumar[i]=(par[i])*100;
else
cumar[i]=cumar[i-1]+(par[i])*100;
}


     
float rsr[20];          //Random assignment for service 
for(i=0;i<cust;i++)
{
rsr[i]=random(100);
}





float tba[20]; //Time Between Arrival
tba[0]=0;
for(i=1;i<cust;i++)
{
for(j=0;j<4;j++)
{
if(rar[i]<cumar[j])
break;
}
tba[i]=(j+1);
}

float clk[20];   // Clock  time of arrival
for(i=0;i<cust;i++)
{
if(i==0)
clk[0]=0;
else
clk[i]=clk[i-1]+tba[i];
}

cout<<"Enter prabability for service for Abel : ";
float pabel[20];          //Probability of abel
for(i=0;i<4;i++)
cin>>pabel[i];
cout<<"Enter prabability for service for Baker : ";
float pbaker[20];          //Probability of baker
for(i=0;i<4;i++)
cin>>pbaker[i];
float cumabel[20];   //Cumilitive Probability Of Abel
for(i=0;i<4;i++)
{
if(i==0)
cumabel[i]=(pabel[i])*100;
else
cumabel[i]=cumabel[i-1]+(pabel[i])*100;
}
float cumbaker[20];   //Cumilitive Probability Of Baker
for(i=0;i<4;i++)
{
if(i==0)
cumbaker[i]=(pbaker[i])*100;
else
cumbaker[i]=cumbaker[i-1]+(pbaker[i])*100;
}



        
float sta[20];          //Service time Abel and Baker
float stb[20]; 



for(i=0;i<cust;i++)
{

for(j=0;j<4;j++)
if(rsr[i]<cumabel[j])
{
sta[i]=(j+2);
break;
}
}




for(i=1;i<(cust+1);i++)
{

for(j=0;j<4;j++)
if(rsr[i]<cumbaker[j])
{
stb[i]=(j+3);
break;
}


}
stb[0]=4;

   
float sfa=0,sfb=0;
float sba[20],sbb[20],sea[20],seb[20];
for(i=0;i<cust;i++)
{


if(clk[i]==0)
{
sba[i]=0;
sea[i]=sba[i]+sta[i];
sfa=sea[i];
sbb[i]=stb[i]=seb[i]=0;
}


else
if(clk[i]>=sfa)
{
sba[i]=clk[i];
sea[i]=sba[i]+sta[i];
sfa=sea[i];
sbb[i]=stb[i]=seb[i]=0;
}
else
if(clk[i]<sfa && clk[i]>=sfb)
{
sbb[i]=clk[i];
seb[i]=sbb[i]+stb[i];
sfb=seb[i];
sba[i]=sta[i]=sea[i]=0;
}
else
if(clk[i]<sfa && clk[i]<sfb)
{
if(sfa<=sfb)
{
sba[i]=sfa;
sea[i]=sba[i]+sta[i];
sfa=sea[i];
sbb[i]=stb[i]=seb[i]=0;
}
else
{
sbb[i]=sfb;
seb[i]=sbb[i]+stb[i];
sfb=seb[i];
sba[i]=sta[i]=sea[i]=0;
}
}
}
system("cls");
cout<<"rd\ttba\tclk\trds\tsba\tsta\tsea\tsbb\tstb\tseb"<<endl;
cout<<"-\t-\t0\t"<<rar[0]<<'\t'<<sba[0]<<'\t'<<sta[0]<<'\t'<<sea[0]<<'\t'<<sbb[0]<<'\t'<<stb[0]<<'\t'<<seb[0]<<endl;
for(i=1;i<=cust-1;i++)
cout<<rar[i]<<'\t'<<tba[i]<<'\t'<<clk[i]<<'\t'<<rsr[i]<<'\t'<<sba[i]<<'\t'<<sta[i]<<'\t'<<sea[i]<<'\t'<<sbb[i]<<'\t'<<stb[i]<<'\t'<<seb[i]<<endl;










getch();
}

No comments:

Post a Comment