#include #include #include #include int intarrival(int a){ if(1<=a && a<=25) return 1; else if (26 <= a && a <= 65) return 2; else if (66 <=a && a <= 85) return 3; else return 4; } int servicea(int a){ // 0.1 0.3 0.25 0.2 0.15 if(1<=a&& a<=10) return 1; else if(11<=a&& a<=40) return 2; else if(41<=a&& a<=65) return 3; else if(66<=a&&a<=85) return 4; else return 5; } int serviceb(int a){ // 0.35 0.27 0.2 0.18 if(1<=a&& a<=35) return 2; else if(36<=a&& a<=62) return 3; else if(63<=a&& a<=82) return 4; else return 5; } int sum(int* array){ int s=0; for(int i =0;i<20;i++) s+=array[i]; return s; } class customer{ public: int intarrival; int service; int preference; int arrival; int who_serves; int service_start; int service_ends; int time_in_queue; customer(){ //arrival = rand()%10; intarrival = 10*(rand()%10)+(rand()%10); service = 10*(rand()%10)+(rand()%10); preference = rand()%2; time_in_queue = 0; } }; main(){ ofstream fout; fout.open("simulation2.data"); customer c[30]; int afinish=0,bfinish=0; // arrival_time c[0].intarrival=0; c[0].arrival = 0; for(int i=1;i<30;i++) c[i].arrival = c[i-1].arrival + intarrival(c[i].intarrival); // who_serves, plus when if(c[0].preference==0) { c[0].who_serves = 0; c[0].service_start = 0; c[0].service_ends = servicea(c[0].service); afinish = c[0].service_ends; } else { c[0].who_serves = 1; c[0].service_start = 0; c[0].service_ends = serviceb(c[0].service); bfinish = c[0].service_ends; } for(int i = 1; i<30; i++) { if((afinish afinish) { c[i].service_start = c[i].arrival; c[i].service_ends = c[i].service_start + servicea(c[i].service); } else { c[i].service_start = afinish; c[i].service_ends = c[i].service_start + servicea(c[i].service); } afinish = c[i].service_ends; } else {// B serves c[i].who_serves = 1; if(c[i].arrival > bfinish) { c[i].service_start = c[i].arrival; c[i].service_ends = c[i].service_start + serviceb(c[0].service); } else { c[i].service_start = bfinish; c[i].service_ends = c[i].service_start + serviceb(c[0].service); } bfinish = c[i].service_ends; } }; for(int i=0;i<30;i++) c[i].time_in_queue = c[i].service_start - c[i].arrival; for(int i = 0;i<29;i++) { fout << i+1 << "& "; fout << c[i].intarrival << "& "; fout << intarrival(c[i].intarrival) << "& "; fout << c[i].arrival << "& "; fout << c[i].service << "& "; fout << char(65+c[i].who_serves) << "& "; if(c[i].who_serves == 1) fout << "& & & "; fout << c[i].service_start << "& "; if(c[i].who_serves == 0) fout << servicea(c[i].service); else fout << serviceb(c[i].service); fout << "& "; fout << c[i].service_ends << "& "; if(c[i].who_serves==0) fout << "& & & "; fout << c[i].time_in_queue << "\\\\"; fout << endl; } }