0

I'm using SimEvent class of Simpy simulator to define some events (say a,b,c). Now I've a process which waits for events a,b and c as shown below.

yield waitevent, self, (a, b, c)

Once any of these events occur, the process will be reactivated. In my case the events can take place multiple times. i.e. Two or more processes can call a.signal() at the same simulation time. If, say event a occurs 3 times, how do I get that information? Does the eventsFired array have the same events repeated?

AIB
  • 5,894
  • 8
  • 30
  • 36

1 Answers1

1

An event can only be fired once in a given moment (i.e. before simulation time moves forward). If a.signal() is called multiple times, it will remain fired. There are a couple of ways to handle this:

yield waitevent, self, (a, b, c)
for ev in self.eventsFired:
    if ev == a:
        print 'a fired'
    elif ev == b:
        print 'b fired'
    elif ev == c:
        print 'c fired'
    else:
        print 'discontinuous event occured'

That's if you want it to respond independently to each event fired. If it doesn't matter, and all that has to happen is for the code to proceed, then the standard construct will do:

yield waitevent, self, (a, b, c)
print 'event fired was', self.eventsFired[0].name
  • If a is fired twice, how do I get that information? I want to differentiate the case in which a is triggered once, a is triggered twice etc. The code you mentioned differentiates between a and b, not between a occurring once and a occurring twice – AIB Dec 20 '13 at 10:02