What I want to know if there is some ... elegant? tidy? code-efficient? way to have an event appended to the list. For instance, here's my approach:
class Agent():
def __init__(self, env):
self.env = env
self.history = [] # to append event times
# this event will be triggered somewhere else in the simulation
self.externalEvent = env.event()
# this one is triggered inside this agent
self.internalEvent = env.event()
def internalProcess(self):
yield self.env.timeout(1) # time the process needs
self.internalEvent.succed() # mark as succesfull
self.history.append([self.env.now, "Internal Event"]) # log event
def simulate(self):
'''The main process of this agent'''
# wait for the external event to happen
yield self.externalEvent
self.history.append([self.env.now, "External Event"]) # log event
# run the internal process
yield self.env.process(self.internalProcess())
Basically I append to a list when the event is successful.
But I'm learning more about simpy and I wonder If maybe I should add a callback to each event and have the callback be a function that appends to the history. Or maybe use the method trigger in some clever way. IDK, I feel I'm a noobie approaching problems with a noobie approach .