(require (planet williams/simulation/simulation-with-graphics))
(define n-attendants 2)
(define attendant #f)
(define (generator n)
(for ((i (in-range n)))
(wait (random-exponential 4.0))
(schedule #:now (customer i))))
(define-process (customer i)
(work (random-flat 2.0 10.0))))
(define (run-simulation n1 n2)
(let ((avg-queue-length (make-variable)))
(tally (variable-statistics avg-queue-length))
(tally (variable-history avg-queue-length))
(for ((i (in-range n1)))
(set! attendant (make-resource n-attendants))
(schedule #:at 0.0 (generator n2))
(variable-mean (resource-queue-variable-n attendant)))))
(printf "--- Closed Loop Example ---~n")
(printf "Number of attendants = ~a~n" n-attendants)
(printf "Number of experiments = ~a~n"
(printf "Minimum average queue length = ~a~n"
(printf "Maximum average queue length = ~a~n"
(printf "Mean average queue length = ~a~n"
(printf "Variance = ~a~n"
(print (history-plot (variable-history avg-queue-length)
"Average Queue Length"))
(run-simulation 1000 1000)