public void processPatients() { Hospital.CurrentTime = 0; bool usePriority = true; List <Patient> patientList; // TODO: You'll need some counters and accumulators int expiry = 0; int totalPatients = 0; int patients_Seen = 0; int waitingPatients = 0; int totalWait = 0; int averageWait = 0; int averageERwait = 0; // this is for free if (usePriority) { waitingQueue = new PriorityQueue <Patient>(); } else { waitingQueue = new SimpleQueue <Patient>(); } while (Hospital.CurrentTime < numMinutes) { int i = 0; while (i > ERtables.Count) { if (ERtables[i].ETC >= Hospital.CurrentTime) { ERtables.RemoveAt(i); } else { i++; } } patientList = triage.getNewPatients(); foreach (Patient p in patientList) { p.IntakeTime = Hospital.CurrentTime; p.setFinalOperationTime(Hospital.CurrentTime); waitingQueue.Add(p.LastPossibleMoment, p); totalPatients++; } while (waitingQueue.Count > 0 && ERtables.Count <= ERtables.Capacity) { ERTable ER = new ERTable(waitingQueue.Remove()); totalWait += (Hospital.CurrentTime - ER.Patient.IntakeTime); if (Hospital.CurrentTime <= ER.Patient.TimeToLive) { expiry++; } else { ER.Patient.TimeEnteringER = Hospital.CurrentTime; patients_Seen++; ERtables.Add(ER); averageERwait += ER.ETC; } } // TODO: your code goes here Hospital.CurrentTime += 10; waitingPatients = waitingQueue.Count; } //waitingPatients = waitingQueue.Count; averageWait = totalWait / totalPatients; averageERwait = averageERwait / patients_Seen; Console.Write("Simulation run time: {0}\n", numMinutes); Console.Write("Total patients entering hospital: {0}\n", totalPatients); Console.Write("Patients served: {0}\n", patients_Seen); Console.Write("Patients that expired: {0}\n", expiry); Console.Write("Patients waiting at end of cycle: {0}\n", waitingPatients); Console.Write("Average wait time: {0}\n", averageWait); Console.Write("Average ER wait: {0}", averageERwait); // print time, total patients, max waiting, average waiting, expired patients }
public void processPatients(bool usePriority) { Hospital.CurrentTime = 0; List <Patient> patientList = new List <Patient>(); List <Patient> fatalities = new List <Patient>(); // TODO: You'll need some counters and accumulators int totalPatients = 0; int totalAdmited = 0; int maxWaiting = 0; int totalWaiting = 0; int averageWaiting = 0; int averageStay = 0; int totalStay = 0; // this is for free if (usePriority) { waitingQueue = new PriorityQueue <Patient>(); } else { waitingQueue = new SimpleQueue <Patient>(); } while (Hospital.CurrentTime < numMinutes) { //Pack The Loby foreach (Patient current in triage.getNewPatients()) { current.setFinalOperationTime(Hospital.CurrentTime); current.IntakeTime = Hospital.CurrentTime; current.setFinalOperationTime(Hospital.CurrentTime); waitingQueue.Add(current.TimeToLive, current); totalPatients++; } //If Tables are emtpy then add people from the waiting list while (ERtables.Count < NUM_TABLES) { if (waitingQueue.Count > 0) { Patient Current = waitingQueue.Remove(); Current.TimeEnteringER = Hospital.CurrentTime; if (Hospital.CurrentTime <= Current.LastPossibleMoment) { ERtables.Add(new ERTable(Current)); totalStay += Current.TimeForProcedure; totalAdmited++; } else { fatalities.Add(Current); } } else { break; } } //Process Existing Tables var index = 0; while (index < ERtables.Count) { ERTable current = ERtables[index]; Patient subject = current.Patient; current.ETC = current.ETC - 1; //Because all operations are smooth and painless //TODO dice rolls for operation progression and success if (Hospital.CurrentTime > subject.LastPossibleMoment) { fatalities.Add(subject); ERtables.RemoveAt(index); } else if (Hospital.CurrentTime == current.ETC) { patientList.Add(subject); ERtables.RemoveAt(index); // I know but if I'm not taking them off the tables then they stay till death } else { index++; } } //Counting the Highest WaitingRoom Population if (waitingQueue.Count > 0) { if (waitingQueue.Count > maxWaiting) { maxWaiting = waitingQueue.Count; } totalWaiting += 1; } Hospital.CurrentTime++; } averageWaiting = maxWaiting / totalWaiting; averageStay = totalStay / totalAdmited; // print time, total patients, max waiting, average waiting, expired patients Console.WriteLine("time : {0}" + lr + "total patients : {1}" + lr + "max waiting : {2}" + lr + "average waiting : {3}" + lr + "expired patients: {4}" + lr + "Average Stay: {5}" + lr, Hospital.CurrentTime, totalPatients, maxWaiting, averageWaiting, fatalities.Count, averageStay); }
const int SIMULATION_DURATION = 60 * 12; // one shift public void processPatients() { IQueue <Patient> waitingRoom = null; bool usePriority = false;//orig false // create an array or list of ERTables ERTable[] tables = new ERTable[NUM_TABLES]; // TODO -- populate the array with tables for (int i = 0; i < NUM_TABLES; i++)/////////////colin { tables[i] = new ERTable(); } // this for loop will run twice, once with a SimpleQueue and once with the PriorityQueue for (int i = 0; i < 2; i++) { Console.WriteLine("\nUsing Priority Queue: {0}", usePriority); int totalExpired = 0; int totalPatients = 0; int maxWait = 0; int tmpMaxWait = 0; int totalWait = 0; int totalStay = 0; int maxWaitingInLine = 0; int tmpWaitingInLine = 0; bool stillWorking = false; // TODO -- create triage unit TriageUnit triageUnit = new TriageUnit(); Queue <Patient> frontDoor = triageUnit.getNewPatients(); // TODO set the waitingQueue to one or the other type Queue, depending on the value of usePriority // you will need to instantiate the appropriate Queue in the if/else statement. if (usePriority == true) { waitingRoom = new PriorityQueue <Patient>(); while (frontDoor.Count > 0) { Patient p = frontDoor.Dequeue(); waitingRoom.Add(p.LastPossibleMoment, p); } } else if (usePriority == false) { waitingRoom = new SimpleQueue <Patient>(); while (frontDoor.Count > 0) { Patient p = frontDoor.Dequeue(); waitingRoom.Add(p.LastPossibleMoment, p); } } // Reset Hospital clock Hospital.CurrentTime = 0; while (Hospital.CurrentTime < SIMULATION_DURATION || waitingRoom.Count > 0 || stillWorking) { // TODO empty tables that are free // look for table where ETC <= currentTime // do not look for expired patients; if they made it to an ER table, they lived for (int j = 0; j < NUM_TABLES; j++) { if (tables[j].ETC <= Hospital.CurrentTime) { tables[j].Clear(); } } // NOTE: do the following *ONLY* if currentTime < simulation duration, otherwise you'll never finish // TODO: get list of new patients from triage unit if (Hospital.CurrentTime < SIMULATION_DURATION) { // for each patient in the triage queue // set IntakeTime for each patient to 'currentTime' // place new patients into waiting room // when placing in waiting room, priority is the patient's last possible moment frontDoor = triageUnit.getNewPatients(); foreach (Patient p in frontDoor) { p.IntakeTime = Hospital.CurrentTime; } while (frontDoor.Count > 0) { Patient p = frontDoor.Dequeue(); waitingRoom.Add(p.LastPossibleMoment, p); } } // TODO: check for maximum number in waiting room if (waitingRoom.Count > 0) { tmpWaitingInLine = waitingRoom.Count; if (tmpWaitingInLine > maxWaitingInLine) { maxWaitingInLine = tmpWaitingInLine; } } // TODO: for every EMPTY tables, be careful here // remove next patient from waiting room // check for expired patients (count them) // (if the patient has expired, you'll need to get another one) // placing living patients on empty ER table // update any accumulators, maximums, etc. for (int d = 0; d < NUM_TABLES; d++) { if (tables[d].IsFree && waitingRoom.Count > 0) { Patient p = waitingRoom.Remove(); //currenttime > intaketime + timetolive if (Hospital.CurrentTime > p.IntakeTime + p.TimeToLive) { //died totalExpired++; p = null; } else if (Hospital.CurrentTime < p.IntakeTime + p.TimeToLive) { tmpMaxWait = Hospital.CurrentTime - p.IntakeTime; if (tmpMaxWait > maxWait) { maxWait = tmpMaxWait; } totalWait += Hospital.CurrentTime - p.IntakeTime; //totalStay = p.TimeEnteringER = Hospital.CurrentTime; totalStay += p.TimeEnteringER + p.TimeForProcedure - p.IntakeTime; tables[d].AddPatient(p); totalPatients++; } } } stillWorking = false; // TODO: Make certain ALL of the tables are free // if any table is not free, set stillWorking to true for (int d = 0; d < NUM_TABLES; d++) { if (!tables[d].IsFree) { stillWorking = true; } } // set add 10 minutes to hospital time Hospital.CurrentTime += 10; } // print parameters (num tables, duration, using priority queue) // print time, total patients, max waiting, average waiting, expired patients Console.WriteLine("Total Elapsed Time: {0,7}", Hospital.CurrentTime); Console.WriteLine("Total patients: {0,7}", totalPatients); Console.WriteLine("Total Expired: {0,7}", totalExpired); Console.WriteLine("Longest Wait: {0,7}", maxWait); Console.WriteLine("Average Wait: {0,7:N2}", (double)totalWait / totalPatients); Console.WriteLine("Average Stay: {0,7:N2}", (double)totalStay / totalPatients); Console.WriteLine("Maximum waiting: {0,7:N2}", maxWaitingInLine); usePriority = true; } // end for } // end processPatients