Hello,

Following is an excerpt from a DEV textbook:

0 :0
The following data yield the arrival times and service
times that each customer will require, for the first 13
customers at a single server system. Upon arrival, a
customer either enters service if the server is free or
joins the waiting line. When the server completes work on
a customer, the next one in line(i.e., the one who has
been waiting the longest) enters service
)

arv=: 12 31  63  95  99 154 198 221 304 346 411 455 537
srv=: 40 32  55  48  18  50  47  18  28  54  40  72  12

0 :0
(a) Determine the departure times of these 13 customers
(b) Repeat (a) when there are two servers and a customer can
be served by either one
(c) Repeat (a) under the new assumption that when the server
completes a service, the next customer to enter services
is the one who has been waiting the least time
)

I read somewhere that APL was often used for simulations. What is the
recommended way of solving such problems above in J? I could build a
Queue
object and do the standard loop-pop-and-process-one like in other
languages but I believe there exist more J-like ways.

p.s. quick and dirty solution for (a) in J:
ndpt=:(([: {. [) >. [: {. ]) (0 ,~ +) [: {: [
dpt=:[: }. [: {."1@:(ndpt/\.)&.|. 0 0 , ]
dpt arv ,. srv
However, that one is hard to change for requirement (b) and (c).
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to