Skip to content

Commit 300c8d4

Browse files
committed
fix tutorial 7
1 parent 661ed3b commit 300c8d4

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

docs/Reference/distributions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ The Erlang Distribution
219219
-----------------------
220220

221221
An Erlang distribution with parameters :math:`\lambda` and :math:`n` is the sum of :math:`n` Exponential distributions with parameter :math:`\lambda`.
222-
Write an Erlang distribution with :math:`\lambda = 9` and :math:`\n = 4` as follows::
222+
Write an Erlang distribution with :math:`\lambda = 9` and :math:`n = 4` as follows::
223223

224224
ciw.dists.Erlang(rate=9, num_phases=4)
225225

docs/Tutorial-II/tutorial_vii.rst

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,33 +67,39 @@ Now we should see that no customer of Class 0 ever reached Node 3; and no custom
6767
>>> set([r.node for r in recs if r.customer_class==1]) == visited_by_children
6868
True
6969

70-
Now say we'd like to find the average waiting time at the reception, baby specialist's clinic, and children's specialist's clinic. We'll simulate for 24 hours, using 3 hour warm-up and 3 hour cool-down, for 16 trials. Let's collect the average waiting times at each node every time::
71-
72-
>>> average_waits_1 = []
73-
>>> average_waits_2 = []
74-
>>> average_waits_3 = []
75-
>>> for trial in range(16):
76-
... ciw.seed(trial)
77-
... Q = ciw.Simulation(N)
78-
... Q.simulate_until_max_time(30)
79-
... recs = Q.get_all_records()
80-
... waits1 = [r.waiting_time for r in recs if r.node==1 and r.arrival_date > 3 and r.arrival_date < 27]
81-
... waits2 = [r.waiting_time for r in recs if r.node==2 and r.arrival_date > 3 and r.arrival_date < 27]
82-
... waits3 = [r.waiting_time for r in recs if r.node==3 and r.arrival_date > 3 and r.arrival_date < 27]
83-
... average_waits_1.append(sum(waits1) / len(waits1))
84-
... average_waits_2.append(sum(waits2) / len(waits2))
85-
... average_waits_3.append(sum(waits3) / len(waits3))
70+
Now say we'd like to find the average waiting time at the reception, baby specialist's clinic, and children's specialist's clinic. We'll simulate for 24 hours, using 3 hour warm-up and 3 hour cool-down, for 16 trials. Let's collect the average waiting times for each class at each node every time::
71+
72+
>>> average_waits_1_babies = []
73+
>>> average_waits_1_children = []
74+
>>> average_waits_2 = []
75+
>>> average_waits_3 = []
76+
>>> for trial in range(16):
77+
... ciw.seed(trial)
78+
... Q = ciw.Simulation(N)
79+
... Q.simulate_until_max_time(30)
80+
... recs = Q.get_all_records()
81+
... waits1_babies = [r.waiting_time for r in recs if r.node==1 and r.arrival_date > 3 and r.arrival_date < 27 and r.customer_class == 0]
82+
... waits1_children = [r.waiting_time for r in recs if r.node==1 and r.arrival_date > 3 and r.arrival_date < 27 and r.customer_class == 1]
83+
... waits2 = [r.waiting_time for r in recs if r.node==2 and r.arrival_date > 3 and r.arrival_date < 27]
84+
... waits3 = [r.waiting_time for r in recs if r.node==3 and r.arrival_date > 3 and r.arrival_date < 27]
85+
... average_waits_1_babies.append(sum(waits1_babies) / len(waits1_babies))
86+
... average_waits_1_children.append(sum(waits1_children) / len(waits1_children))
87+
... average_waits_2.append(sum(waits2) / len(waits2))
88+
... average_waits_3.append(sum(waits3) / len(waits3))
8689

8790
Now we can find the average wait over the trials::
8891

89-
>>> sum(average_waits_1) / len(average_waits_1)
90-
0.274301...
92+
>>> sum(average_waits_1_babies) / len(average_waits_1_babies)
93+
0.298488...
9194

92-
>>> sum(average_waits_2) / len(average_waits_2)
93-
0.268752...
95+
>>> sum(average_waits_1_children) / len(average_waits_1_children)
96+
0.261834...
9497

95-
>>> sum(average_waits_3) / len(average_waits_3)
96-
0.284763...
98+
>>> sum(average_waits_2) / len(average_waits_2)
99+
0.268752...
97100

98-
These results imply that on average babies wait 0.6 of an hour, around 36 minutes for an appointment.
101+
>>> sum(average_waits_3) / len(average_waits_3)
102+
0.284763...
103+
104+
These results imply that on average babies wait 0.298488 + 0.268752 = 0.567 of an hour, around 34 minutes for an appointment.
99105
This could then be used as a baseline measure against which to compare potential reconfigurations of the clinic.

0 commit comments

Comments
 (0)