admin 管理员组文章数量: 887021
2023年12月19日发(作者:access统计男女人数)
CS 310
Programming Assignment 4
Due April 27, 2014 5:00 P.M.
About 15 years in
The Martian Adventure Recreational Society, or MARS (no affiliation to M&M Mars Candy company)
has a problem. Ever since it opened up Mars for space tourism, the number of visitors to Mars has been
overwhelming and has been the company's biggest moneymaker. However, a small percentage of
tourists have died after returning to Earth, and this has threatened to cut into MARS' profits.
It seems that while visiting the red planet, approx. 5% of visitors encounter a microbe which attaches to
their systems immediately upon contact. Although it appears to remain dormant so long as the
contractants remain on Mars, upon contact with Earth's polluted atmosphere, this microbe reacts
violently, causing death within 10 to 15 minutes of penetrating the atmosphere. Fortunately, the crack
biochemists at MARS have developed a cure which will render the microbe harmless. The cure is
100% effective if administered in time to take full effect. However, the cure requires two separate doses:
the first dose is standard, but the second dose varies depending upon the individual's reaction to the
first dose. Therefore, in order for the cure to be effective, each individual must be monitored carefully
for the two minutes following the first dose, in order for the administering physician to determine the
correct amount of the second dose. Once the correct second dose is received, it takes approximately
one minute to circulate completely through the bloodstream to disable the microbe. The result of these
requirements is that although the cure can be 100% effective, an infected individual must receive the
first dose at least 3 minutes prior to his/her pending death (time to wait two minutes after receiving the
first dose, plus one minute after receiving the second dose) in order for the treatment to cure the
microbe.
The current procedure for attending to the tourists who return from Mars is to place each returning
tourist in a standard queue to receive the cure as s/he arrives back on Earth. All tourists receive the cure
as a precaution, since it has been shown by the MARS scientists that receiving the treatment causes no
ill effects, even when the microbe is not present. However, there is only one doctor available at any
given time to administer and observe the person receiving the cure. Also, the doctor observes the
person for both phases of the cure. Thus the doctor is unable to administer the cure to the next person
in line until this time period for the current person's second dose has passed. Unfortunately, some
tourists have died from microbe exposure while waiting in line to receive the cure.
In order to avoid this problem, the MARS scientists have developed a test that can harmlessly detect
the presence of the microbe. However the test, which takes 2 minutes to administer and provide results,
does not detect the presence of the microbe with 100% accuracy. Instead, it gives the result as a
percentage (from 0% to 100%) that an individual has the microbe. The MARS scientists have
determined that if a person has the microbe present, the test result is in the range of 40%-100%. Also, if
a person does not have the microbe present, the test result is in the range of 0%-80%. (In other words,
any result less than 40% means that the individual is not infected, and any result greater than 80%
means that the individual is definitely infected, although this result is unrelated with how many minutes
the individual will survive without the cure.)
MARS wishes to see how well the test for the microbe can avoid tourist fatalities and has come up with
the following alternative to handle tourist arrivals which uses two queues: 1) a standard "Testing"
queue, and 2) a priority "Treatment" queue. When a tourist arrives, MARS employees check to see
whether the doctor administering the cure is available, and whether both queues are empty, in which
case the tourist immediately is given the first treatment dose. Otherwise, the tourist enters the Testing
queue (thereby delaying his/her entrance to the Treatment queue for at least two minutes). Once the test
result is obtained, unless the tourist tests negative for the microbe (a result of less than 40%), s/he
enters the Treatment queue in a position that is determined by the result of the test: the higher the
percentage obtained on the test, the closer s/he is placed towards the head of the queue. (In case of ties,
tourists should be placed in the queue in order of their arrival.)
Having concluded all testing of both the test and cure and having received FDA approval to administer
them to any potentially infected individuals, MARS now wishes to determine which scenario will best
minimize the number of tourist fatalities. They are thus approaching your company (since we are all
hopeful that 15 years from now you will have graduated from GMU and have a job) to implement both
scenarios and help MARS decide which one will be the most effective.
Trips to Mars
The method that MARS uses to transport passengers to and from the red planet is a closely held secret.
However, MARS has given you the following specifications to model how tourists return:
Tourists return one at a time.
The probability that a tourist returns in any time step is 20%.
Once a tourist returns, the "microbe clock" starts ticking.
If a tourist has encountered the microbe, s/he will die within 10-15 minutes of his/her arrival time if the
cure has not been administered and completed before that time. (Your model should randomly compute
the precise amount of time remaining for each returning tourist.)
Once a tourist arrives on Earth, s/he enters queues in accordance to the scenario that is being tested
(Scenario 1 contains only one queue - Treatment, while Scenario 2 contains two queues – Testing and
Treatment).
Each tourist in line is dequeued according to the appropriate scenario. If a tourist is found to be DOA
when s/he arrives at the head of either queue, the death is recorded and the individual is removed from
the queue. You may assume this requires no additional time (since in real life, this presumably would
have been noticed prior to arrival at the front of the line).
If a person occupying either the Testing or Treatment queue dies, the death is recorded and the
individual is removed. Because this occurs while being attended to, you may assume that no additional
time is necessary for removing the deceased individual.
Scenario 1
In this scenario, each tourist enters one queue to receive treatment. The Treatment queue is a standard
(non-prioritized) queue. The next person in line exits the queue as soon as the doctor administering the
treatment becomes available, but must wait with the doctor until the treatment is complete (or until s/he
runs out of time and dies). Thus, the cure is not administered while the tourist is in the queue, and the
tourist cannot leave until the procedure for the cure is complete.
Scenario 2
In this scenario, each tourist that returns checks to see if the doctor administering the cure is available.
If the doctor is idle, AND there are no other tourists around (either at the testing station, or in either
queue) the tourist immediately goes to the doctor for treatment. Otherwise, the tourist enters the Testing
queue to be tested for the microbe. The Testing queue is a standard queue. As soon as the tester is
available, the tourist at the head of the queue exits the queue and receives the test. S/he then waits in
the testing station to receive his/her test results. As soon as the test results are obtained, the tourist
enters the Treatment queue in the appropriate position, based upon the results received from the test.
The Treatment queue is a Priority queue. All tourists then wait in the Treatment queue until they
receive treatment or are removed. Note that tourists whose test results are below the threshold are free
to leave and do not enter the Treatment queue.
Implementation
In order to implement this project, you will need to create several classes. The first class is a generic
Queue class. You must implement this class using a linked list.
The Queue class must contain the following member functions:
Constructor
Enqueue
Dequeue
Insert into queue by priority
Is_Empty
The second class is the Tourist class. This class contains information about the tourist such as time of
arrival, whether s/he is infected with the microbe, time remaining before death (assuming s/he is
infected and receives no treatment), the result of the test if/when administered, etc. Use appropriate
member functions and member variables to represent this information.
The third class is the Scenario_1 class. This class contains a member variable of type Queue to hold the
arriving tourists, as well as member variables to keep track of the current simulation time, the number
of tourists that have arrived, the number of tourists that have encountered the microbe, the number of
tourists that have died, occupancy of the cure station, etc. It also contains member functions to handle
the tourists that arrive, such as putting them into the queue or sending them to the doctor for treatment,
etc.
The fourth class is the Scenario_2 class. This class is similar to the Scenario_1 class, except that it
contains two queues (the standard queue used for the line to receive the test, and the priority queue
used for the line to receive treatment). This class also contains information about the testing station.
You may wish to add additional classes depending upon the overall design of your program.
Running the simulation
Tourists are only able to arrive from Mars within a time span of 12 hours per day (when there is a direct
line of sight from the MARS facility to the planet Mars). Therefore, you will run the simulation for 12
hours, using 30 second time increments (for a total of 1440 time steps). At the end of the simulation,
you will need to empty all the queues before ending the program. (In other words, treat the poor
tourists who are still in line. :-)
Your program should allow the user to choose which scenario to run, prompt the user for specific
information as necessary (see below), then run the simulation and print the results.
User Input
Because MARS intends to expand its choice of destinations to other celestial bodies, it wishes to be
prepared in case its customers should become infected by different microbes at these other locations.
Therefore, MARS has requested that you make your program reusable for these other potential
scenarios by allowing the user to input data that may change given other situations. Accordingly, you
must prompt the user for the following information for use in running your simulation:
A random number seed (integer)
Which scenario to run (integer – 0 or 1)
Verbose or Normal output (see below for output) (integer – 0 for Normal, 1 for Verbose)
Number of time steps in simulation (integer)
Probability that a tourist arrives in any given time step (0.0 < floating point < 1.0)
Percentage of tourists infected by the microbe (0.0 < floating point < 1.0)
Minimum survival time of an infected tourist in time steps (integer)
Maximum survival time of an infected tourist (integer)
Time for first stage of cure, once administered (integer)
Time for second stage of cure, once administered (integer)
专业程序代写:
Additional input needed for Scenario 2:
Time needed to test for the microbe (integer)
Lower bound result for possibly infected individuals (Below this value, the tourist does not have the
microbe) (0.0 < floating point < 1.0)
Upper bound result for those not infected (Above this value, the tourist definitely has the microbe) (0.0
< floating point < 1.0)
So, for the Mars tourists, pertinent inputs would be:
Random number seed: make one up
Scenario Choice: (1 or 2)
Normal or Verbose output: (0 or 1)
Number of time steps in simulation:1440 (12 hours at 30 second time steps)
Probability that a tourist arrives in any given time step: 0.2
Percentage of tourists infected by the microbe: 0.05
Minimum survival time of an infected tourist: 20 (10 minutes for 30 second time steps)
Maximum survival time of an infected tourist: 30 (15 minutes for 30 second time steps)
Time steps for first stage of cure: 4
Time steps for second stage of cure: 2
When running simulation 2, the following inputs are also needed:
Time steps to test for microbe: 4
Lower Bound of test accuracy: 0.4
Upper Bound of test accuracy: 0.8
留学生程序代写,qq:928900200
Additional Requirements:
Since it may be tedious to enter all of these values during the debugging stage of the development, you
should allow for a filename to be entered as a command line argument. If a filename is contained on the
command line, that file will be used as input instead of prompting the user for input. The format and
order of input for this file must follow the above input specification.
In order to use the same information regarding tourist arrivals between the two simulations, before
starting the clock for the simulation, you should generate all tourist arrivals (including time of arrival,
whether they have the microbe, the result of the test and the time of death if they do have the microbe)
and put them in a separate “arrival” queue. Then for each time step, check to see if the next tourist
arrives during that time step, and if so, dequeue them and place them in the testing or treatment queue
as appropriate. If tourists are generated in this manner, the same seed value for the random number
generator should result in the same tourist data between the two simulations.
Output
Allow for your simulation to be run in either verbose mode (which is useful for debugging) or normal
mode. Verbose mode will print information at each time step, such as whether a tourist has just arrived,
the number of tourists in the queue(s), the current state of the test/treatment stations, the number of
infected tourists saved, the number of infected tourists that have died, and any other information you
deem appropriate.
At the end of the simulation, your program will print out the following simulation results:
For both Scenarios:
Total number of time steps for the simulation
Total number of tourists returning from Mars
Total number of returning tourists who were infected
Total number of cures administered
Total number of infected tourists saved
Total number of infected tourists who died before receiving treatment
Total number of infected tourists who died after beginning treatment
Additional output for Scenario 2:
The average of the test results returned for the tourists
If you find that any other information or statistics seem appropriate or necessary for a proper evaluation
and comparison of the two scenarios, you should print those out as well.
An Implementation Suggestion
Since Scenario_2 class will be similar to the Scenario_1 class, you may wish to have it inherit from
Scenario_1. Or you might decide to create a Scenario class from which both Scenario_1 and
Scenario_2 inherit.
Project Report Information & Discussion
Run both scenarios many times using different random seeds (at least 10) and plot the results on a
graph (plot Deaths per Number of Returning Tourists and/or some other metrics). Based upon the
results, draw a conclusion on which scenario is better (assuming one is) and explain why it is likely the
case. Also, exercise the scenarios using different input values and show how the data supports your
answers the following questions:
How significantly does the percentage of tourists infected affect the results (assuming no other input
values are changed)?
How does an increase in the probability of tourist arrival affect each scenario?
How does adjusting the lower and upper bounds of the test affect the results?
What if MARS develops a cheaper test, but it takes several time steps longer to get the result?
At what point does the death rate for the tourists rise significantly? (You may want to graph the results
using several random seed values)
If the MARS scientists can create a cure that works just a bit faster (one or two time steps, for example)
will it make the test portion of Scenario 2 unnecessary?
Finally, discuss at least one other method to handling returning tourists that you believe may be useful
for MARS to investigate based upon your findings and why this method may be worth coding (This is
called “Trying to get additional money from the customer”).
Submitting your assignment
Submit in Blackboard:
Source code for all classes
Output generated by executing the main() methods of classes
The project report discussed above
A page stating which parts of the assignment (if any) are incomplete or known to be incorrect.
Create a zip file of your files and submit it to the course Blackboard page.
On Blackboard:
Click on the Assignments section
Click on the Programming Assignment 4link
Scroll down to "Attach a File"
Click "Browse My Computer"
Select your Zip file
You can resubmit to Blackboard as many times as you like up to the deadline
版权声明:本文标题:编程题-星球旅行 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1702935309h436564.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论