Debian Codegraph @

docs/source/Tutorials/bankprograms_OO/bank22_OO.py

raw symbols SCIP
1 """ bank22_OO: An interruption by a phone call """
2 from SimPy.Simulation import Simulation, Process, hold
3
4 ## Model components ------------------------
5
6 class Customer(Process):
7 """ Customer arrives, looks around and leaves """
8
9 def visit(self, timeInBank, onphone):
10 print("%7.4f %s: Here I am" % (self.sim.now(), self.name))
11 yield hold, self, timeInBank
12 if self.interrupted():
13 timeleft = self.interruptLeft
14 self.interruptReset()
15 print("%7.4f %s: Excuse me" % (self.sim.now(), self.name))
16 print("%7.4f %s: Hello! I'll call back" % (self.sim.now(), self.name))
17 yield hold, self, onphone
18 print("%7.4f %s: Sorry, where were we?" % (self.sim.now(), self.name))
19 yield hold, self, timeleft
20 print("%7.4f %s: I must leave" % (self.sim.now(), self.name))
21
22
23 class Call(Process):
24 """ Cellphone call arrives and interrupts """
25
26 def ring(self, klaus, timeOfCall):
27 yield hold, self, timeOfCall
28 print("%7.4f Ringgg!" % (self.sim.now()))
29 self.interrupt(klaus)
30
31 ## Model -----------------------------------
32
33 class BankModel(Simulation):
34 def run(self):
35 """ PEM """
36 klaus = Customer(name="Klaus", sim=self)
37 self.activate(klaus, klaus.visit(timeInBank, onphone))
38 call = Call(sim=self)
39 self.activate(call, call.ring(klaus, timeOfCall))
40 self.simulate(until=maxTime)
41
42 ## Experiment data -------------------------
43
44 timeInBank = 20.0
45 timeOfCall = 9.0
46 onphone = 3.0
47 maxTime = 100.0
48
49 ## Experiment -----------------------------
50 mymodel = BankModel()
51 mymodel.run()
52