Python仿真代写|CS代写|计算机代写

Python Simulation - Assignment


In this assignment, you will write a simulation of a train unloading dock. Trains arrive at the station as a Poisson process on average once every 10 hours. Each train takes between 3.5 and 4.5 hours, uniformly at random, to unload. If the loading dock is busy, then trains wait in a first-come, first-served queue outside the loading dock for the currently unloading train to finish. Negligible time passes between the departure of one train, and the entry of the next train (if any) into the loading dock---unless the entering train has no crew (see below).

There are a number of complications. Each train has a crew that, by union regulations, cannot work more than 12 hours at a time. When a train arrives at the station, the crew’s remaining work time is uniformly distributed at random between 6 and 11 hours. When a crew abandons their train at the end of their shift, they are said to have “hogged out”. A train whose crew has hogged out cannot be moved, and so if a hogged-out train is at the front of the queue and the train in front finishes unloading, it cannot be moved into the loading dock until a replacement crew arrives (crews from other trains cannot be used). Furthermore, a train that is already in the loading dock cannot be unloaded in the absence of its crew, so once the crew hogs out, unloading must stop temporarily until the next crew arrives for that train. This means that the unloading dock can be lie unused even if there is a train in it, and even if it is empty and a (hogged-out) train is at the front of the queue; in both of these cases we say the loading dock is “hogged-out”. More specifically, the loading dock is hogged out if there are any trains in the queue but the loading dock is not actively unloading. (A bit of thought should convince you that trains in the queue behind the one at the front do not affect the hogged-out status of the unloading dock.) In other words, the loading dock can only be called “idle” if no trains are present.


Once a train’s crew has hogged out, the arrival of a replacement crew takes between 2.5 and 3.5 hours, uniformly at random. However, due to union regulations, the new crew’s 12-hour clock starts ticking as soon as they are called in for replacement (i.e., at the instant the previous crew hogged out); i.e., their 2.5-3.5 hour travel time counts as part of their 12-hour shift.

You will simulate this system for 1 million (1,000,000) hours (plus the time it takes for all remaining trains to depart), and output the following statistics at the end:

1. Total number of trains served.

2. The population average and maximum of the time-in-system over trains.

3. The percentage of time the loading dock spent busy, idle, and hogged-out. Do these add to

100%? Why or why not?

4. Time average and maximum number of trains in the queue.

5. A histogram of the number of trains that hogged out 0, 1, 2, etc times.

咨询 Alpha 小助手,获取更多课业帮助。