DelayedEvent
agent-based modeling, abm, events, bptk, bptk-py, python, business prototyping
DelayedEvent
DelayedEvent Constructor
DelayedEvent(name, sender_id, receiver_id, delay, data=None)
An Event that is not delivered in the next round but after a given number of timesteps.
Use it whenever the thing an agent triggers takes time to arrive: an order that ships in three days, a message that needs a round trip, a decision that takes effect next quarter. Sending a plain Event and counting the rounds yourself is the alternative, and it puts the bookkeeping in your agent rather than in the scheduler.
The scheduler holds the event until its delay has elapsed and then delivers it exactly like any other event — the receiving agent’s handle_event sees no difference.
Parameters
name – String. The name of the event. Agents dispatch on this, so it is what the receiver matches against.
sender_id – Integer. The id of the agent sending the event.
receiver_id – Integer. The id of the agent the event is addressed to.
delay – Integer. The number of timesteps (
dt) to wait before delivering the event. A delay of 1 is the same as a plainEvent.data – Dict (Default=None). Whatever the receiver needs to act on the event.
Everything else — name, sender_id, receiver_id and data — behaves as on Event.
Example
from BPTK_Py import Agent, DelayedEvent
class Retailer(Agent):
def initialize(self):
self.agent_type = "retailer"
self.state = "active"
def handle_event(self, event):
if event.name == "order":
# The goods take three timesteps to arrive
self.model.enqueue_event(
DelayedEvent(
name="delivery",
sender_id=self.id,
receiver_id=event.sender_id,
delay=3,
data={"quantity": event.data["quantity"]},
)
)The Beer Distribution Game in the model library uses this to model shipping and order lead times, which is where the game’s dynamics come from.