Skip to content

Commit

Permalink
DiscreteEventScheduler: Clean up docstring a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutH authored Nov 29, 2023
1 parent 1643c62 commit adbf7de
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions mesa/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit adbf7de

Please sign in to comment.