Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is this recursive statement wrong?
    primarykey
    data
    text
    <p>This is a bank simulation that takes into account 20 different serving lines with a single queue, customers arrive following an exponential rate and they are served during a time that follows a normal probability distribution with mean 40 and standard deviation 20. </p> <p>Things were working just fine till I decided to exclude the negative values given by the normal distribution using this method: </p> <pre><code>def getNormal(self): normal = normalvariate(40,20) if (normal&gt;=1): return normal else: getNormal(self) </code></pre> <p>Which has caused the program to give me this screen every now and then: <a href="http://yfrog.com/2qrecursionp" rel="nofollow noreferrer">SCREEN</a></p> <p>Am I screwing up the recursive call? I don't get why it wouldn't work. I have changed the getNormal() method to:</p> <pre><code>def getNormal(self): normal = normalvariate(40,20) while (normal &lt;=1): normal = normalvariate (40,20) return normal </code></pre> <p>But I'm curious on why the previous recursive statement gets busted.</p> <p>This is the complete source code, in case you're interested.</p> <pre><code>""" bank21: One counter with impatient customers """ from SimPy.SimulationTrace import * from random import * ## Model components ------------------------ class Source(Process): """ Source generates customers randomly """ def generate(self,number): for i in range(number): c = Customer(name = "Customer%02d"%(i,)) activate(c,c.visit(tiempoDeUso=15.0)) validateTime=now() if validateTime&lt;=600: interval = getLambda(self) t = expovariate(interval) yield hold,self,t #esta es la rata de generación else: detenerGeneracion=999 yield hold,self,detenerGeneracion class Customer(Process): """ Customer arrives, is served and leaves """ def visit(self,tiempoDeUso=0): arrive = now() # arrival time print "%8.3f %s: Here I am "%(now(),self.name) yield (request,self,counter),(hold,self,maxWaitTime) wait = now()-arrive # waiting time if self.acquired(counter): print "%8.3f %s: Waited %6.3f"%(now(),self.name,wait) tiempoDeUso=getNormal(self) yield hold,self,tiempoDeUso yield release,self,counter print "%8.3f %s: Completed"%(now(),self.name) else: print "%8.3f %s: Waited %6.3f. I am off"%(now(),self.name,wait) ## Experiment data ------------------------- maxTime = 60*10.5 # minutes maxWaitTime = 12.0 # minutes. maximum time to wait ## Model ---------------------------------- def model(): global counter #seed(98989) counter = Resource(name="Las maquinas",capacity=20) initialize() source = Source('Source') firstArrival= expovariate(20.0/60.0) #chequear el expovariate activate(source, source.generate(number=99999),at=firstArrival) simulate(until=maxTime) def getNormal(self): normal = normalvariate(40,20) if (normal&gt;=1): return normal else: getNormal(self) def getLambda (self): actualTime=now() if (actualTime &lt;=60): return 20.0/60.0 if (actualTime&gt;60)and (actualTime&lt;=120): return 25.0/60.0 if (actualTime&gt;120)and (actualTime&lt;=180): return 40.0/60.0 if (actualTime&gt;180)and (actualTime&lt;=240): return 30.0/60.0 if (actualTime&gt;240)and (actualTime&lt;=300): return 35.0/60.0 if (actualTime&gt;300)and (actualTime&lt;=360): return 42.0/60.0 if (actualTime&gt;360)and (actualTime&lt;=420): return 50.0/60.0 if (actualTime&gt;420)and (actualTime&lt;=480): return 55.0/60.0 if (actualTime&gt;480)and (actualTime&lt;=540): return 45.0/60.0 if (actualTime&gt;540)and (actualTime&lt;=600): return 10.0/60.0 ## Experiment ---------------------------------- model() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload