From 76229a5424e473b1ca0d08124a84fe7a4a65f526 Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Wed, 29 Nov 2023 10:47:14 +0100 Subject: [PATCH] DiscreteEventScheduler: Clean up docstring a bit --- mesa/time.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/mesa/time.py b/mesa/time.py index 159b807de80..ca54bab7a70 100644 --- a/mesa/time.py +++ b/mesa/time.py @@ -385,11 +385,8 @@ def schedule_event(self, time: TimeT, agent: Agent) -> None: raise ValueError( f"Scheduled time ({time}) must be >= the current time ({self.time})" ) - event = ( - time, - self.model.random.random(), - agent, - ) # Add a random value for secondary sorting + # Create an event, sorted first on time, secondary on a random value + event = (time, self.model.random.random(), agent) heapq.heappush(self.event_queue, event) def schedule_in(self, delay: TimeT, agent: Agent) -> None: @@ -404,10 +401,8 @@ def step(self) -> None: end_time = self.time + self.time_step while self.event_queue and self.event_queue[0][0] <= end_time: - # Get the next event - time, _, agent = heapq.heappop( - self.event_queue - ) # Ignore the random value during unpacking + # Get the next event (ignore the random value during unpacking) + time, _, agent = heapq.heappop(self.event_queue) # Advance time to the event's time self.time = time