(require (planet "simulation-with-graphics.ss" ("williams" "simulation.plt" 1 0))) (require (planet "random-distributions.ss" ("williams" "science.plt"))) ;;;demo material-handling model (define conv-length 10) (define conv-set #f) (define conv #f) (define next-conv #f) (define wrap-exit #f) (define buffer-exit #f) (define-process (generator n) ;;; (let ((next-proc (list wrap buffer))) (let ((next-proc (list (make-wrap 5) buffer))) (do ((i 0 (+ i 1)))((= i n) (void)) (wait 5.0) (wait (random-exponential 1.0)) (schedule now (material-handle next-proc i))))) (define-process (material-handle next-proc i) (with-resource (conv) (printf"~a: unit ~a enters~n" (current-simulation-time) i) (set-insert! conv-set self) (work (random-flat 2.0 3.0)) (with-resource (next-conv) (apply (car next-proc) (list (cdr next-proc) i))) (set-remove! conv-set self))) ;;simple wrapping sub-process, no internal state (define (wrap next-proc i) (work 30.0) (printf"~a: unit ~a wrapped~n" (current-simulation-time) i) (with-resource (wrap-exit) (apply (car next-proc) (list (cdr next-proc) i)))) ;;creates a wrapping sub-process with internal state to model wrapping material (define (make-wrap restock-level) (let ((inventory restock-level)) (define (inv-adj n) (set! inventory (- inventory 1)) (if (eq? inventory 0) (begin (printf "restocking on unit ~a~n" n) (set! inventory restock-level) (wait 2.0)))) (lambda (next-proc i) (begin (work 30.0) (printf"~a: unit ~a wrapped~n" (current-simulation-time) i) (inv-adj i) (with-resource (wrap-exit) (apply (car next-proc) (list (cdr next-proc) i))))))) ;;sub-process for modelling end of the line (define (buffer next-proc i) (work 1.0) (printf "~a: unit ~a buffered~n" (current-simulation-time) i) (with-resource (buffer-exit) (work 1.0))) (define (initialize) (set! conv (make-resource conv-length)) (set! next-conv (make-resource 1)) (set! wrap-exit (make-resource 1)) (set! buffer-exit (make-resource 1)) (set! conv-set (make-set)) (accumulate (variable-history (set-variable-n conv-set)))) (define (run-sim n) (with-new-simulation-environment (initialize) (schedule (at 0.0) (generator n)) (start-simulation) (printf "~n-- Conveyor Utilization Statistics --~n") (printf "Mean No. of units = ~a~n" (variable-mean (set-variable-n conv-set))) (printf "Variance = ~a~n" (variable-variance (set-variable-n conv-set))) (printf "Maximum No. of units = ~a~n" (variable-maximum (set-variable-n conv-set))) (printf "Minimum No. of units = ~a~n" (variable-minimum (set-variable-n conv-set))) (printf "~a~n" (history-plot (variable-history (set-variable-n conv-set)) "Conveyor Utilization History"))))