You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: prompts.md
+114Lines changed: 114 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -299,3 +299,117 @@ class PP(CA):
299
299
300
300
### changes
301
301
302
+
## Add synchronous updating
303
+
Now we add the asyncrhonous updating, making sure the functionality is the vectorized equivalent of the asynchronous function.
304
+
305
+
### prompt
306
+
Implement the synchronous updating for the PP class as a vectorized (optimized) equivalent to the asynchronous updating. First, create a copy of the current grid. The reproduction rules can be either implemented by using the empty or prey cells as the anchor and looking for prey or predator neighbors that can reproduce into these anchor cells or by using the prey or predator cells as the anchor and looking for empty or prey cells that the anchor cells can reproduce into. Ensure that the probability of a cell being reproduced into increases as more neighboring cells are occupied by the relevant species. However, each prey and predator must only be able to reproduce into a single cell. The count_neighbors function can be utilized if deemed necessary. The rules for the deaths should be the same as the asynchronous updating, as they are already vectorized. Make sure the synchronous updating is an optimized and thus faster equivalent of the asynchronous updating.
307
+
308
+
### output
309
+
def update_sync(self) -> None:
310
+
"""Synchronous (vectorized) update.
311
+
312
+
Implements a vectorized equivalent of the random-sequential
313
+
asynchronous update. Each occupied cell (prey or predator) gets at
314
+
most one reproduction attempt: with probability `birth` it chooses a
315
+
random neighbor and, if that neighbor in the reference grid has the
316
+
required target state (empty for prey, prey for predator), it
317
+
becomes a candidate attempt. When multiple reproducers target the
318
+
same cell, one attempt is chosen uniformly at random to succeed.
319
+
Deaths are applied the same vectorized way as in the async update.
320
+
"""
321
+
322
+
rows, cols = self.grid.shape
323
+
grid_ref = self.grid.copy()
324
+
325
+
# Precompute neighbor shifts and arrays for indexing
0 commit comments