(require (planet williams/simulation/simulation-with-graphics))
(require (planet williams/science/random-distributions))
(define n-attendants 2)
(define attendant #f)
(define-process (generator n)
(do ((i 0 (+ i 1)))
((= i n) (void))
(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))
(do ((i 1 (+ i 1)))
((> i n1) (void))
(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)