Java代写 | CPSC 300 Assignment 1 – Hospital Emergency Room Simulation

本次Java代写要求使用Java编程实现一个医院急救室模拟系统,其中涉及的知识点包括Random函数、JAVA IO本地文件读取、接口、抽象类、抽象方法等。

Assignment 1 – Hospital Emergency Room Simulation

Due:

Oct 26, 2018, 11:59PM

Notes:

  • This assignment should be finished in
  • Zip all your files (code files, readme file, test data files, and others if needed) together into one file named “yourlastname_yourfirstname_student#_a#.zip” (or .rar, or .7z, or .tar), then submit this
  • Official test data will be provided several days before the assignment due
  • Until then, work with your own test

Some More Notes:

This assignment appears long but most of it is background and explanations. The physical code is not short, but much of that code involves the data structures employed, which, I assume you are already strongly familiar with.

Your code must be entirely your own (other than built-in Java methods that fall within the restrictions that follow), and, you are NOT allowed to use Java Generics or Java Interfaces of any kind (this includes writing your own Interfaces – write Abstract Classes and Abstract Methods instead). You must also use your own linked structures based on your own defined node class(es) to build all your data structures: no arrays, and no use of Java’s collection structures (arraylists and so on). Your program must also do only console output – no graphics, file dialogs, etc., in order that the markers can compile and run it from a command line.

I am assuming you have never done any work with event-driven simulations, and so I prepared some background on this in a separate document, posted in the same directory. If you already know what an event-driven simulation is, great, otherwise, I’d suggest reading the appendix and then coming back here before reading all the details of this particular simulation. The assignment will look more complicated than it is if you don’t! Further, I suggest reading the details below over a few times and sketching out the data flow before generating the data structures and the object hierarchies you need to tackle this problem. There are several data structures required here, and coding them is assumed to be trivial, as you are already familiar with them from previous classes.

Assignment Description:

In this assignment you will write a program that will simulate the processing of patients through a hospital emergency room, using a discrete event simulation. The ultimate goal is to determine how long patients have to wait to see a doctor, and how their time in the emergency ward in general is spent. Such studies are often used to forecast changes in the operation of a system based on changes in the system itself (they make it easy to ask questions like what if we added more doctors? What if there was a disaster and we suddenly got more patients than we expected? and so on). Simulations like this are used to determine staffing and operating procedures in many everyday situations (e.g. how many checkouts should a store have open at 5pm, so that no one is waiting more than 5 minutes in line?).

The events that you will be simulating are a few common things that happen to patients in an emergency room (at least this emergency room – while attempting a useful simulation, this is not intended to be reflective of a real medical community or all the factors that would have to be studied to manage one effectively). To be able to design an event-driven simulation, we need to talk about the central focus of the simulation – a patient – and the various kinds of events that can happen to patients on their travels through the system.

An Arrival event occurs when the patient walks or is brought through the door – this happens to all patients. There are two types of patients, those who walk in themselves (code W) and those who arrive in an emergency condition by ambulance (code E). In either case, patients are immediately given a patient number for tracking. For the purpose of our simulation, this will start with 28064212 and go up from there.

Walk-in patients wait in line in order of arrival (first in, first out) to get to a triage nurse, where the Assessment event occurs. Only one patient is assessed at a time: a patient is assessed when he or she gets to the head of the line, and is assigned a priority between 1 (highest) and 5 (lowest). This process takes 4 time units (i.e. the next event for this patient will be 4 units in the future), and includes filling out the various forms and describing their medical problems with the triage nurse. Emergency patients do not wait to get assessed: they are assumed to already be at the highest (1) level of priority and these patients skip the assessment lineup and assessment process completely.

After assessment (i.e. 4 time units after a patient got to the head of the assessment line, or immediately upon arrival for an emergency patient, since they don’t go through assessment), an Enter Waiting Room event occurs, and the patient then waits in the waiting room for treatment. Patients are called from the waiting room, as treatment rooms and the doctors who work in each become available. Patients are called in order by priority. If there are many patients with the same priority, which is likely, they will be taken in order of lowest patient number within priority. It’s possible for a patient to go straight in for treatment (starting treatment is the next event, and is explained below) and not have to wait at all (they’d still enter the waiting room, they just would spend no time waiting there). Since new patients with higher priority are taken first, however, it may be quite some time before a low-priority patient gets treatment. Of course, that’s why they tell you not to go to the emergency room for minor medical problems.

 

There are three treatment rooms in our emergency ward, and each has a doctor permanently stationed in it. These each accept a new patient as soon as the previous patient has left the treatment room. Because a doctor is always in every treatment room, a Start Treatment event occurs for the patient when the patient is allowed to enter one of the treatment rooms (i.e. there is one with no patient in it and they’re next!) and treatment begins at that time. Each patient will have a known amount of time that treatment will require, specified in time units and supplied when the patient arrives. That value will allow the simulator to calculate when in the future the next event type, Treatment Completed, will occur, once treatment starts.

Once Treatment Completed occurs, the patient is ready to leave the treatment room (but has not actually left). One of two events will occur in a patient’s future as a result of completing treatment. If a patient has priority 2-5, they will be escorted from the treatment room (and will presumably go home). This Departure event occurs one time unit in the future after Treatment Completed, to take into account the time to get the patient out of the treatment room (i.e. the next patient cannot be moved into the treatment room until the departure of the previous patient is complete). Priority 1 patients, on the other hand, will always be admitted to the hospital – an Admitting to Hospital event. Admission to the hospital involves filling out more paperwork, and requires waiting in the treatment room for the admission nurse to arrive with the forms. There is only one admission nurse, and so only one patient at a time can be admitted – this is first come, first served, where “first come” refers to the time that the patient finished treatment and began waiting for the admission nurse. Once the patient reaches the head of this line (it’s not a physical line since patients are sitting in their treatment rooms, but it’s a line in terms of waiting since several people may be waiting for their turn with the nurse), the Admitting to Hospital event will occur in the treatment room and will take three time units, causing the patient to have a Departure event that far in the future (the delay associated with a departure is included in the admission event). What this ultimately amounts to is that priority 1 patients have to wait an unknown amount of time to be admitted to the hospital after their treatment in order for the admission nurse to show up to begin the admission process, and then departs the treatment room (has a departure event) three units in the future after that (as opposed to a simple 1 unit in the future after treatment completes for lower priority patients). In either case, after a departure event we know another patient will be using the room – Starting Treatment.

Unlike other event types, Admitting to Hospital isn’t divided into separate start and finish events. To avoid ambiguity, consider the Admitting to Hospital event to occur at the time that the event is completed (i.e. 3 units after the admission nurse arrives in the treatment room to see the patient, not when this process starts). Sample output below shows what this should look like.

Note that because there are places where patients have to wait at three different stages (assessment, waiting for treatment, and waiting for admission), you can’t predict far ahead of time when any individual patient will depart, get to treatment, or most other things (just like real life). It all depends on who’s in front of a patient and what everybody’s priority is. You need to follow patients through the complex interactions of the system to obtain this information, which is why we use an event-driven simulation. Your simulation will have to follow patients’ movements through these various stages using the events that occur in the domain to change patient state.

 

Your program should produce output which indicates the sequence of events processed and when they occurred in order by time, noting the number of empty treatment rooms remaining any time that number changes (this will only change, obviously, for events that cause someone to enter or leave a treatment room). You will need to maintain a list of future events in order by time, processing these in order by time to make things happen in the world now and to generate new events that we know will occur at specific times in the future. If you don’t understand why, read the appendix. During the simulation process, at any point where the time unit is the same for two events, the earlier patient number should be done first. This means that as the simulation goes on you will be maintaining a list of pending events that is ordered by primarily by time, but within time, ordered by patient number.

Each of the event types described above should be printed when they occur. Whenever an event is printed, the patient it refers to, and the priority of that patient (if they have been assessed or if they’re an emergency and the priority is thus known) should also be displayed. Your sequence of events should look something like this (these are completely made-up numbers):

Please enter input file name: sim1.txt

Simulation begins…

Time 8: 28064212 (walk-in) arrives

Time 9: 28064213 (emergency) Priority 1 arrives

Time 34: 28064212 Priority 2 enters treatment Room (2 rooms still available)

….

Time 86: 28064212 Priority 2 treatment completed

Time 87: 28064212 Priority 2 departs (3 rooms still available)

As mentioned above, for the admission event, please print the event at the time it is completed rather than when it starts… for example:

 

Time20:28064212(Priority1)finishes treatment
     
Time23:28064212(Priority1)admitted to Hospital
Time23:28064212(Priority1)departs (1 room still available)

Printing the admission message when the admission is completed rather than when it starts simplifies things in that processing the admission event can simply print this message and insert a departure event for the same time cycle (since the admission has been done). A departure following admission will always be the same time cycle the admission completes, and will follow the admission event.

The output of my model solution will show the amount of time the patient in question spent waiting so far as a part of each event that causes any wait. There is no need for you to go this far (we only really need the total wait for each patient at the end and the stats that are asked for), but I found the breakdown to be useful in debugging, and you would likely find it helpful as well.

After all the events have been processed, your program should print a simple table showing how long each patient spent waiting. The total time waiting consists of the time waiting to be assessed, waiting to get into a treatment room, and waiting to be admitted. This table can be as simple as the patient number and the integer waiting time for each patient with some titles, in any order you want. You should then print the total number of patients and the average waiting time per patient.

All of the events that can occur other than patient arrivals are generated by the processing of other events (e.g. if somebody leaves a treatment room, someone else can come in, and assuming we know how long their treatment will take we know when the treatment will be complete). Patient arrivals are unpredictable and will be handled by reading them in from a file. This data file will consist of one arrival event per line, each indicating (1) the time point at which the patient will arrive – an int, (2) whether the patient is an emergency “E” or a walk-in “W” patient – a char, and

(2) how long (in time units) the patient will require in the treatment room once they get there – another int. You will need to prompt the user for a string indicating the text name of the file, because we will be using more than one file of test data.

Sample input might look like:

 

13E28
13W8
14W4
15E18

You are guaranteed that all arrivals will be ordered in the file by time. In this case, nothing would happen before time 13, when the first patient (number 28064212) would arrive. Patient 28064213 would arrive at the same time unit by ambulance. This would be followed by the arrival of two more patients, at times 14 and 15. Any number of patients may arrive at the same time unit

– they are considered to arrive in the order specified in the file in terms of obtaining patient numbers. You may NOT read the entire file ahead of time – only a single arrival event can be in the events list at any time (i.e. there may be many other pending events, but only one arrival). If you don’t understand why, read the appendix (but the main reason is that if you look at any example, only the earliest unprocessed arrival will ever be relevant at any one time).

Now having given you all that detail, the simulation itself is an extremely simple process: all it does is pull off events in order by time and make them happen (what occurs when an event “happens” is different for each event as described above, and may make some changes to data maintained by the simulation and generate future events). It is possible to have any number of events happen during the same time unit (i.e. have >1 event in the event list with the same time associated with it). In the case of tied times, the events should be processed first by priority of patient, and if there’s still a tie there (e.g. two priority-one patients having events happen in the same time unit), in order by patient number with the earlier patient going first.

The only other piece of information you need that is not provided in the data file is the priority of non-emergency patients. In a real scenario we would calculate a likelihood of any patient being of a specific priority based on a statistical distribution (and similarly for the likelihood of a patient arrival at any time). However, in order to have one correct set of output, we have to be able to predict these ahead of time. Since it would look odd to have priorities in the data file and just pretend not to know what they are until the assessment process is complete, we will use a random number generator to represent the triage nurse’s decisions as to priority. This will be use a set seed value so that the same sequence of priorities will be generated each time. Provided you have imported java.util.*, you can use the following routines:

static Random x = new Random(1000);

static int getPriority() { return (x.nextInt(5)+1);}

These do not have to be static in your code, but your Random object needs to be created with a seed of 1000 as is done here (for the record, this should generate the random sequence 3,1,2,5,3,5,2,1,5,1,5,… each time).

In addition to the event list driving the simulation itself, you will also need to model the processing of patients – i.e. there will have to be places to wait (queues or priority queues). The way you should approach this is by keeping track of the patients that exist (i.e. everybody you’ve seen) and then using those patient instances as data for other data structures (e.g. the first patient joins a line of patients waiting to be assessed, then moves to a waiting room to wait there by priority, and so on. Your patient class should contain data members to record the information you’re interested in keeping for a patient (e.g. priority, waiting times, etc.). You should write these data structures early, so that you know they’re bug-free before implementing the bulk of this assignment. That way if you’re wondering why somebody seems to be waiting too long, you know it won’t be because (for example) something got inserted into a linked list incorrectly. One other hint to note is that despite having a number of treatment rooms, you don’t care which room any patient uses – only how many are currently unoccupied.

I suggest beginning by drawing a diagram of the flow of patients through the various components in the emergency ward. This will give you an idea of where patients have to wait and the kind of data structures you will need to model this. It will also help you see what causes a patient to move from one spot to another – i.e. what changes have to happen in the system in the present and the future as a result of processing all the above events). Everything that changes in the present can be modified directly, while changes in the future will simply involve inserting events in the event list to be processed at the appropriate time. Your simulator itself should simply be taking the next event (since they’re in order by time!) and making the changes that it causes happen, including the insertion of future events in the list of events.

Remember to use abstract classes and methods to make your data structures generic using Abstract Classes and Methods. As already mentioned, your list of events must contain only one arrival event at any point (see the Appendix for a couple of different reasons why this should be the case).

 


程序代写代做C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: [email protected]  微信:dmxyzl003


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

发表评论