Here's a simple version using a single process and two resources.<br><br>;;; Noels' e-mail:<br>;;; I am trying to define the following producer/consumer process using<br>;;; the simulation package:<br>;;;<br>;;; There is a queue of resources of type A.<br>
;;;<br>;;; Process X takes an A and produces a B (which contains the A). The B<br>;;; is placed in a queue of fixed size<br>;;;<br>;;; Process Y takes a B, returns the A its queue and throws away the B.<br>;;;<br>;;; If any queue is empty a process that needs a resource of that type<br>
;;; must wait. If any queue is full a process that creates a resource of<br>;;; that type must wait.<br>;;;<br>;;; I can't work out how to model this. If I model the As and Bs as<br>;;; resources, I have the problem that "It is an error to attempt to<br>
;;; release more units than the process has allocated."<br>;;; (<a href="http://planet.plt-scheme.org/package-source/williams/simulation.plt/">http://planet.plt-scheme.org/package-source/williams/simulation.plt/</a><br>
;;; 2/2/html/simulation-Z-H-8.html#node_sec_7.2.2).<br>;;; Since X takes A and never releases them, and Y releases As but never<br>;;; takes them, this is a problem.<br>;;;<br>;;; If I schedule As and Bs as events how do I enforce the resource limits?<br>
;;;<br>;;; This kind of simulation is simple in a message passing thread system<br>;;; but I don't see how it fits into the simulation package's model.<br>;;;<br>;;; Also: the documentation for the simulation package would benefit from<br>
;;; an introductory section that lays out the model used by the package.<br>;;;<br>;;; Doug's Response:<br>;;; I'm not sure what A and B are in you example, but I assume A is something<br>;;; that is required by both processes - like a work cell or jig - and that<br>
;;; B is something only required by Y. Also, I'm assuming that X and Y can<br>;;; be done at independent speeds.<br>;;;<br>;;; Let's assume a 'widget' represents the end product/result of X and Y using<br>
;;; an A and a B.<br><br>(require (planet "simulation-with-graphics.ss"<br> ("williams" "simulation.plt")))<br>(require (planet "random-distributions.ss"<br> ("williams" "science.plt")))<br>
<br>(define n 0)<br>(define A #f)<br>(define B #f)<br><br>(define (scheduler)<br> (do ((i 1 (+ i 1)))<br> ((> i n) ())<br> (wait (random-exponential 1.5))<br> (schedule now (widget i))))<br><br>(define-process (widget i)<br>
;; Allocate an A for X and Y<br> (with-resource (A)<br> (printf "~a: Widget ~a acquires an A~n" (current-simulation-time) i)<br> (work (random-flat 4.0 8.0)) ; X<br> ;; Allocate a B for Y<br> (with-resource (B)<br>
(printf "~a: Widget ~a acquires a B~n" (current-simulation-time) i)<br> (work (random-flat 8.0 20.0)) ; Y<br> (printf "~a: Widget ~a releases its B~n" (current-simulation-time) i))<br> (printf "~a: Widget ~a releases its A~n" (current-simulation-time) i)))<br>
<br>(define (run-simulation n-widgets n-As n-Bs)<br> (with-new-simulation-environment<br> (set! n n-widgets)<br> (set! A (make-resource n-As))<br> (set! B (make-resource n-Bs))<br> (schedule (at 0.0) (scheduler))<br>
(start-simulation)))<br><br>(run-simulation 20 4 2)<br><br><br><div class="gmail_quote">On Mon, Jun 23, 2008 at 11:52 AM, Noel Welsh <<a href="mailto:noelwelsh@gmail.com">noelwelsh@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On Mon, Jun 23, 2008 at 4:53 PM, Doug Williams<br>
<<a href="mailto:m.douglas.williams@gmail.com">m.douglas.williams@gmail.com</a>> wrote:<br>
> I'll reload 3.72 on one of my machines and send you a quick solution. I'll<br>
> still having problems with V4.0 (and V4.0.1) and haven't gotten the<br>
> simulation and inference collections ported yet.<br>
<br>
</div>Don't worry about it too much. My problem is so simple that it might<br>
be easier to just implement it directly.<br>
<font color="#888888"><br>
N.<br>
</font></blockquote></div><br>