11Logs
22================
33Amy Heather
4- 2025-03-10
4+ 2025-03-11
55
66- [ Set up] ( #set-up )
77- [ Simulation run with logs printed to the
@@ -167,58 +167,61 @@ print(log_contents, sep = "\n")
167167The patient arrives at 1.10422 and requests a nurse. There is one
168168available (` SERVE ` ) so the consultation begins (` Timeout ` ).
169169
170- ## [5] " 1.10422 | arrival: patient0 | activity: Seize | nurse, 1, 0 paths"
171- ## [6] " 1.10422 | resource: nurse | arrival: patient0 | SERVE"
170+ [5] " 1.10422 | arrival: patient0 | activity: Seize | nurse, 1, 0 paths"
171+ [6] " 1.10422 | resource: nurse | arrival: patient0 | SERVE"
172172 ...
173- ## [8 ] " 1.10422 | arrival: patient0 | activity: Timeout | function()"
173+ [10 ] " 1.10422 | arrival: patient0 | activity: Timeout | function()"
174174
175- The consultation finishes at 2.22258 , and the patient leaves:
175+ The consultation finishes at 2.26987 , and the patient leaves:
176176
177- ## [13 ] " 2.22258 | arrival: patient0 | activity: Release | nurse, 1"
178- ## [14 ] " 2.22258 | resource: nurse | arrival: patient0 | DEPART"
179- ## [15 ] " 2.22258 | task: Post-Release | : | "
177+ [14 ] " 2.26987 | arrival: patient0 | activity: Release | nurse, 1"
178+ [15 ] " 2.26987 | resource: nurse | arrival: patient0 | DEPART"
179+ [16 ] " 2.26987 | task: Post-Release | : | "
180180
181181#### Example B: ` patient2 `
182182
183- The patient arrives at 4.59487 , requests a nurse and enters a queue
183+ The patient arrives at 4.5594 , requests a nurse and enters a queue
184184(` ENQUEUE ` ).
185185
186- [17] " 4.59487 | arrival: patient2 | activity: Seize | nurse, 1, 0 paths"
187- [18] " 4.59487 | resource: nurse | arrival: patient2 | ENQUEUE"
186+ [13] " 1.94299 | source: patient | new: patient2 | 4.5594"
187+ ...
188+ [21] " 4.5594 | arrival: patient2 | activity: Seize | nurse, 1, 0 paths"
189+ [22] " 4.5594 | resource: nurse | arrival: patient2 | ENQUEUE"
188190
189191A nurse becomes available at 25.3823 (` SERVE ` ) so consultation begins
190192(` Timeout ` ).
191193
192- [35] " 25.3823 | resource: nurse | arrival: patient2 | SERVE"
193- [36] " 25.3823 | arrival: patient2 | activity: Timeout | function()"
194+ [39] " 25.4296 | resource: nurse | arrival: patient2 | SERVE"
195+ ...
196+ [42] " 25.4296 | arrival: patient2 | activity: Timeout | function()"
194197
195- However, there are no further entries as the simulation ends before the
196- consultation ends.
198+ However, there are no further entries for that patient as the simulation
199+ ends before the consultation ends.
197200
198201### Compare with recorded results
199202
200203The logs will align with the recorded results of each patient.
201204
202205``` r
203- verbose_run [[" arrivals" ]]
206+ arrange( verbose_run [[" arrivals" ]], start_time )
204207```
205208
206209 ## name start_time end_time activity_time resource replication serve_start
207210 ## 1 patient0 1.104219 2.269873 1.165654 nurse 0 1.104219
208211 ## 2 patient1 1.942991 25.429622 23.159748 nurse 0 2.269873
209- ## 3 patient6 21.796553 NA NA nurse 0 NA
210- ## 4 patient4 15.174872 NA NA nurse 0 NA
211- ## 5 patient3 11.936775 NA NA nurse 0 NA
212+ ## 3 patient2 4.559403 NA NA nurse 0 25.429622
213+ ## 4 patient3 11.936775 NA NA nurse 0 NA
214+ ## 5 patient4 15.174872 NA NA nurse 0 NA
212215 ## 6 patient5 20.914277 NA NA nurse 0 NA
213- ## 7 patient2 4.559403 NA NA nurse 0 25.429622
216+ ## 7 patient6 21.796553 NA NA nurse 0 NA
214217 ## serve_length wait_time wait_time_unseen
215218 ## 1 1.165654 0.0000000 NA
216219 ## 2 23.159748 0.3268822 NA
217- ## 3 NA NA 8.203447
218- ## 4 NA NA 14.825128
219- ## 5 NA NA 18.063225
220+ ## 3 6.096239 20.8702188 NA
221+ ## 4 NA NA 18.063225
222+ ## 5 NA NA 14.825128
220223 ## 6 NA NA 9.085723
221- ## 7 6.096239 20.8702188 NA
224+ ## 7 NA NA 8.203447
222225
223226## Customising the log messages
224227
@@ -237,18 +240,25 @@ distinct).
237240# Set the seed
238241set.seed(0L )
239242
243+ env <- simmer(" simulation" , verbose = FALSE )
244+
240245# Define the patient trajectory
241246patient <- trajectory(" appointment" ) %> %
242247 simmer :: log_(" 🚶 Arrives." ) %> %
243248 seize(" nurse" , 1L ) %> %
244- simmer :: log_( " 🩺 Nurse consultation begins. " ) %> %
245- timeout( function () {
249+ set_attribute( " nurse_serve_start " , function () now( env ) ) %> %
250+ set_attribute( " nurse_serve_length " , function () {
246251 rexp(n = 1L , rate = 1L / param [[" mean_n_consult_time" ]])
247252 }) %> %
253+ simmer :: log_(function () {
254+ paste0(" 🩺 Nurse consultation begins (length: " ,
255+ round(get_attribute(env , " nurse_serve_length" ), 5L ), " )" )
256+ }) %> %
257+ timeout(function () get_attribute(env , " nurse_serve_length" )) %> %
248258 release(" nurse" , 1L ) %> %
249259 simmer :: log_(" 🚪 Leaves." )
250260
251- env <- simmer( " simulation " , verbose = FALSE ) %> %
261+ env <- env %> %
252262 add_resource(" nurse" , param [[" number_of_nurses" ]]) %> %
253263 add_generator(" patient" , patient , function () {
254264 rexp(n = 1L , rate = 1L / param [[" patient_inter" ]])
@@ -257,17 +267,17 @@ env <- simmer("simulation", verbose = FALSE) %>%
257267```
258268
259269 ## 1.10422: patient0: 🚶 Arrives.
260- ## 1.10422: patient0: 🩺 Nurse consultation begins.
261- ## 1.97846 : patient1: 🚶 Arrives.
262- ## 2.22258 : patient0: 🚪 Leaves.
263- ## 2.22258 : patient1: 🩺 Nurse consultation begins.
264- ## 4.59487 : patient2: 🚶 Arrives.
265- ## 11.9722 : patient3: 🚶 Arrives.
266- ## 15.2103 : patient4: 🚶 Arrives.
267- ## 20.9497 : patient5: 🚶 Arrives.
268- ## 21.832 : patient6: 🚶 Arrives.
269- ## 25.3823 : patient1: 🚪 Leaves.
270- ## 25.3823 : patient2: 🩺 Nurse consultation begins.
270+ ## 1.10422: patient0: 🩺 Nurse consultation begins (length: 1.16565)
271+ ## 1.94299 : patient1: 🚶 Arrives.
272+ ## 2.26987 : patient0: 🚪 Leaves.
273+ ## 2.26987 : patient1: 🩺 Nurse consultation begins (length: 23.15975)
274+ ## 4.5594 : patient2: 🚶 Arrives.
275+ ## 11.9368 : patient3: 🚶 Arrives.
276+ ## 15.1749 : patient4: 🚶 Arrives.
277+ ## 20.9143 : patient5: 🚶 Arrives.
278+ ## 21.7966 : patient6: 🚶 Arrives.
279+ ## 25.4296 : patient1: 🚪 Leaves.
280+ ## 25.4296 : patient2: 🩺 Nurse consultation begins (length: 6.09624)
271281
272282## Calculate run time
273283
0 commit comments