1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#include <iostream>
#include <math.h>
#include<time.h>
#include <fstream>
using namespace std;
float randNum()
{
float x,y,r;
x = rand();
y = RAND_MAX;
r = x/y;
return r;
}
int main ()
{
ofstream fileout(" themba.csv") ;
// Varaible Declaration
int i=1,num,mL,mD,mW,count=0,N=1;
cout<<"please enter total number of arrival jobs:"<<endl;
cin>>num;
float t,tL,D_proctime,t_sim,simulation_t[i],depart_time[count],R,diff,currenttime=0,nextdepaturet,nextarrivalt,QueueL=0;
float q,pL,pD,A=0,B=0,D,array[num] ,arrayL[num],arrivalD[count],arrivalW[count],arraytotL,arrayTot;
//INPUTS//
cout<<"please enter arrival rate:"<<endl;
cin>>q;
cout<<"please enter total number lathe machines:"<<endl;
cin>>mL;
cout<<"Please enter processing rate for lathe: "<<endl;
cin>>pL;
while (i<num)
{
// arrival time for cutting department
t=(log(randNum()))/(-q);
A=A +t;
array[i]=A;
cout<<"arrival t= \t"<<array[i]<<endl;
// processing time for lathes
if (( N>=1)&&(N<=mL))
{
tL=(log(randNum()))/(-N*pL);
B=B +tL;
arrayL[i] =B;
cout<<"proc time= \t"<<arrayL[i]<<endl;
}
else if ( N>mL)
{
tL=(log(randNum()))/(-mL*pL);
B=B +tL;
arrayL[i] =B;
cout<<"proc time= \t"<<arrayL[i]<<endl;
}
//Simualtionn for number of jobs in the cuuting department
diff=(tL-t); // comparing the interarrival time with processing time
t_sim=t_sim+tL; // this is simulation time of the cutting department
simulation_t[i]=t_sim;
if ( diff<0)
{
N=N+1; // increament increasing the # of job in the system
cout<<"N= \t"<<N<<endl;
simulation_t[i-1]=array[i];
}
else if(diff>0)
{
N=N-1;
cout<<"N= \t"<<N<<endl;
depart_time[count]=simulation_t[i-1]; // storing the departure time in array for further use
count=count+1;
}
else
{
N=N;
cout<<"N= \t"<<N<<endl;
}
i=i+1;
QueueL=(N-mL);
cout<<"Queue length= \t"<<QueueL<<endl;
fileout<<arrayL[i]<<","<<N<<","<<QueueL<<","<<endl;
}
for ( count=0; count<num ;count++)
{
R=randNum();
if ( R<0.3)
{
arrivalW[count]=depart_time[count];
cout<<" welding arrival_t= \t"<<arrivalW[count]<<endl;
}
else
{
arrivalD[count]=depart_time[count];
cout<<" drilling arrival_t= \t"<< arrivalD[count]<<endl;
}
}
return 0;
|