[plt-scheme] Simulation : coupling sub-processes

From: Williams, M. Douglas (M.DOUGLAS.WILLIAMS at saic.com)
Date: Sat Mar 11 13:52:25 EST 2006

Attached is your code reformatted - it looks like some carriage returns got
misplaced in the e-mail.  It does run, but with the arrival values (about
every six units) and processing time taking at least 30 units, it pretty
quickly reaches 100% utilization of the conveyer.  But I assume you are
interested in how to construct the flow within the model and the numbers
will be fixed later.

One simple thing is that you don't need the conv-set.  It just matches what
the resource is doing and you can just use (resource-satisfied-variable-n
conv).  [You can define a variable equal to it if you don't want to type it
a lot.]

If the flow is always the same - as it seems to be in the example, you can
just schedule the next one in the series to occur - either using now or with
a specified delay or explicitly modeling another conveyer, etc.

If the number of sub-processes is fixed, you might consider an array of
processes.  You can also look at the Jackson Network model (jackson.ss) in
the examples.  This has a probabilistic model of how a process goes through
its subprocesses using arrays to represent the transitions.

If the number of sub-processes is variable, use a list.

>From the e-mail, I gather you want some way to model alternative flows
without drastically changing the model each time, as opposed to having a set
flow and just changing numeric parameters.

If you send me a description of the system you are wanting to model, I can
take a quick cut at it.  In particular, is the set of subprocesses fixed?
Is there a single queue at the conveyer or are there multiple queues
(between stations, etc) with multiple conveyers?

And thanks for the interest in using the packages.

Doug

> -----Original Message-----
> From: plt-scheme-bounces at list.cs.brown.edu [mailto:plt-scheme-
> bounces at list.cs.brown.edu] On Behalf Of Kimberly Clark/Mike Messinides
> Sent: Saturday, March 11, 2006 6:17 AM
> To: plt-scheme at list.cs.brown.edu
> Subject: [plt-scheme] Simulation : coupling sub-processes
> 
> Thanks to all who helped with my simulation.plt
> problem (planet was downloading a truncated file).
> 
> I've been experimenting with the simulation package in
> preparation for creating a material handling model. I
> want to be able to couple many simple sub-processes
> together and then model the composite behavior. Each
> sub-process will be very simple, but I want to be able
> to easily re-arrange and modify the sub-processes. I
> started with the examples provided in the simulation
> package and have arrived at the following demo of my
> approach. Basically I have one process (in the
> simulation package sense), with multiple sub-processes
> which are just functions. Each function takes as an
> argument a list of functions which represent
> downstream sub-processes.
> 
> Since I'm new to Scheme and the simulation package,
> I'm not sure if this approach is making good use of
> the capabilities of the language and the simulation
> package. I'd appreciate any comments on whether this
> looks like a good way to set up a model.
> 
> (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"))))
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrap-model.ss
Type: application/octet-stream
Size: 3111 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20060311/78b5f11c/attachment.obj>

Posted on the users mailing list.