8.5: A Queuing Problem: Ship Unloading in a Harbor

advertisement
8.5: A Queuing Problem: Ship Unloading in a Harbor
Consider a small harbor with unloading facilities for ships. Only one ship can be unloaded
at a time. Ships arrive for unloading of cargo at the harbor, and the time between
successive arrivals of ships varies from 15 to 145 min. The time needed for unloading a
ship varies from 45 to 90 min. On average 100 ships are unloaded before the harbor is
closed for a certain time for inspection and repair.
The waiting time of a ship is the time between its arrival and the start of unloading.
The harbor time of a ship is the sum of the waiting time and the unloading time. If a
ship arrives after the previous ship has been unloaded, the docking facilities are idle for
some time.
We define an episode as the period of time that lasts from the opening of the harbor until 100 ships are unloaded. For the owners of the docking facilities the following
questions are of vital importance:
• What are the average and maximum harbor times during an episode?
• What are the average and maximum waiting times during an episode?
• What is the fraction of time of an episode in which the docking facilities are idle?
(a) To answer these questions, simulate the activity in the harbor for 100 episodes. Summarize the results in a table showing the average harbor time, the maximum harbor time,
the average waiting time, the maximum waiting time, and the fraction of the total episode
time in which the facilities are idle for each of the first ten episodes, and the averages and
standard deviations of these numbers over all 100 episodes.
Hints: The simulation algorithm for a single episode may be summarized as follows:
• The time between(i) between the successive arrivals of the ships i and i − 1 is a
random number distributed uniformly in the interval 15 ≤ between(i) ≤ 145 (time
measured in minutes). For i = 1 (first ship), between(1) is the arrival time after the
harbor has opened.
• The unload time unload(i) for ship i is a random number distributed uniformly in
the interval 45 ≤ unload(i) ≤ 90.
• Matlab hint: The arrays between and unload, in which the times between(i) and
unload(i) are stored, can be generated by the single commands
rand(1,100);between=15+130*ans;
rand(1,100);unload=45+45*ans;
• Define the arrival times iteratively as arrival(i) = arrival(i − 1) + between(i). In
Matlab, the array arrival can be generated by the single command
arrival=cumsum(between);
1
• Initialize the arrays wait time, idle time, and the auxiliary array f inish time
(f inish time(i) is the time when the unloading of ship i is finished). In Matlab
syntax:
finish_time(1)=arrival(1)+unload(1);
wait_time(1)=0;
idle_time(1)=arrival(1);
• Proceed iteratively from i = 2 to i = 100 in a loop. In Matlab syntax, a single
iteration step could be as follows:
timediff=arrive(i)-finish(i-1);
if timediff>=0,
idle_time(i)=timediff;
wait_time(i)=0;
else
idle_time(i)=0;
wait_time(i)=-timediff;
end finish_time(i)=arrival(i)+wait_time(i)+unload(i);
With these arrays all quantities asked for can be computed for a single episode. An
outer loop over 100 episodes then allows to compute averages. In Matlab, the mean and
standard deviation of an array X is calculated through the commands mean(X) and
std(X), respectively.
(b) Suppose the owners of the docking facilities are concerned with the quality and
consider to hire additional labor or to acquire better equipment so that the unloading
time is reduced to between 35 and 75 min per ship. Perform the same simulation as in
(a) for this case and comment on the changes in the data.
(c) The owners argue that the improvement of (b) will cause more ships to use their
facilities. Thus perform the same simulation as in (a) when the unloading times are
reduced to between 35 and 75 min and the between–arrival times are reduced to between
10 and 120 min.
(d) Suppose now that the owners are not satisfied with the assumption that the times
between the arrivals of ships and the unloading times are uniformly distributed between 15
and 145 min and 45 and 90 min, respectively. So they collect experimental data and find
out that the distributions are indeed non–uniform. The data collected are summarized
in the following table. Repeat the simulation of (a) with these non–uniform distributions
incorporated.
2
Time between
arrivals
15–25
25–35
35–45
45–55
55–65
65–75
75–85
85–95
95–105
105–115
115–125
125–135
135–145
Number of
occurrences
11
35
42
61
108
193
240
207
150
85
44
21
3
Unloading time Number of
occurences
45–50
50–55
55–60
60–65
65–70
70–75
75–80
80–85
85–90
20
54
114
103
156
223
250
171
109
Hint: The difference to (a)–(c) is that now the between–arrival times and the unloading–
times are computed in a different manner. We describe the procedure for the between–
arrival times:
For each of the thirteen time intervals of 10 min (15 ≤ t ≤ 25, 25 ≤ t ≤ 35, . . .,
135 ≤ t ≤ 145), the probability pi of occurrence is the number of occurrences divided by
1200 (the total number of occurrences). For example, the probability that a ship arrives
between 15 and 25 min after the previous ship has arrived is p1 = 11/1200 ≈ 0.0092. Let
p = (p1 , . . . , p13 ) be the vector of probabilities. Define the cumulative distribution vector
P
c = (c0 , c1 , . . . , c13 ) by c0 = 0 and ci = ij=1 pj if i > 0. Choose a random number, x,
uniformly distributed in the interval 0 ≤ x ≤ 1. If x is in the interval ci−1 ≤ x ≤ ci , then
define the time associated with x, t(x), by linear interpolation of x through the points
(ci−1 , ti−1 ) and (ci , ti ), i.e.
t(x) = ti−1 + (x − ci−1 )
ti − ti−1
,
ci − ci−1
where t0 = 15, t1 = 25, . . ., t13 = 145 are time–interval boundaries. In Matlab, the
between–arrival times can be computed all at a time through the following commands:
between_interval_times=15:10:145;
between_prob=[11 35 42 61 108 193 240 207 150 85 44 21 3]/1200;
between_cum_distr=[0 cumsum(between_prob)];
rand(1,100);
between=interp1(between_cum_distr,between_interval_times,ans);
Analogously proceed for the unloading times. The remainder of the simulation is as in
(a).
3
(e) Think about other questions which might be asked, and how they can be answered
by simulations. For example, the number of ships per episode may be increased, or the
docking facilities are expanded so that two ships can be unloaded at a time.
8.6: Craps
There are two bets in the popular casino game craps: pass and don’t pass (both are
even–money bets). A shooter continues to roll two dice. The outcomes of throwing the
dice decides whether the pass bet or the no pass bet wins or loses as follows:
• Roll a 12 (boxcar) on the first roll: both pass bet and no pass bet lose.
• Roll a 7 or 11 on the first roll: pass bet wins, no pass bet loses.
• Roll a 2 or 3 on the first roll: pass bet loses, no pass bet wins.
• Roll a 4, 5, 6, 8, 9 or 10 on the first roll: in this case these numbers become the
point. The shooter continues to roll the dice until either the point occurs again or
a 7 occurs. If a point occurs, the pass bet wins, and if a 7 occurs, the no pass bet
wins.
(a) Run a simulation of 1000 craps games. Plot the fraction of the number of times the
pass bet wins and the fraction of the number of times the no pass bet wins as function
of the number of games n, where n = 10, 20, . . . , 1000. Does this fraction converge, i.e.,
approximate the probability that the pass bet or the no pass bet wins? Who is the true
winner of the game?
(b) Now assume that one of the dice is not homogeneous (or the shooter has a special
rolling technique) so that rolling a 3 is more probable than rolling one of the other numbers.
Let p be the probability of rolling a 3. For simplicity assume that the probabilities of
rolling 1, 2, 4, 5, and 6 are equal, i.e. given by (1 − p)/5. The probabilities of the other
dice are equally distributed as in (a). Choose, say, 10 equally distributed values for p in
the interval 1/6 ≤ p ≤ 0.9. For each of these values run 1000 simulations of craps and
compute approximate values for the probabilities that the pass bet wins and that the no
pass bet wins, respectively. Plot these probabilities versus p. Comment.
You may experiment with other probability distributions.
4
Download