examples/example-1.rkt
#lang racket
;;; Example 1 - Processes

(require (planet williams/simulation/simulation))

;;; process (generator n) -> void?
;;;   n : exact-nonnegative-integer?
(define-process (generator n)
  (for ((i (in-range n)))
    (wait (random-exponential 4.0))
    (schedule #:now (customer i))))

;;; process (customer i)
;;;   i : exact-nonnegative-integer?
(define-process (customer i)
  (printf "~a: customer ~a enters~n" (current-simulation-time) i)
  (work (random-flat 2.0 10.0))
  (printf "~a: customer ~a leaves~n" (current-simulation-time) i))

;;; (run-simulation n ) -> void?
;;;   n : exact-nonnegative-integer?
(define (run-simulation n)
  (with-new-simulation-environment
   (schedule #:at 0.0 (generator n))
   (start-simulation)))

;;; Run the simulation for 10 customers.
(run-simulation 10)