Skip to content

Commit 6ffee80

Browse files
authored
Resolve FIXME in sugarscape_g1mt/agents.py via zip (mesa#3062)
1 parent cd16579 commit 6ffee80

File tree

1 file changed

+5
-7
lines changed
  • mesa/examples/advanced/sugarscape_g1mt

1 file changed

+5
-7
lines changed

mesa/examples/advanced/sugarscape_g1mt/agents.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,13 @@ def move(self):
239239

240240
# find the highest welfare in welfares
241241
max_welfare = max(welfares)
242-
# get the index of max welfare cells
243-
# fixme: rewrite using enumerate and single loop
244-
candidate_indices = [
245-
i for i in range(len(welfares)) if math.isclose(welfares[i], max_welfare)
242+
# Get cells with the highest welfare
243+
candidates = [
244+
cell
245+
for cell, welfare in zip(neighboring_cells, welfares)
246+
if math.isclose(welfare, max_welfare)
246247
]
247248

248-
# convert index to positions of those cells
249-
candidates = [neighboring_cells[i] for i in candidate_indices]
250-
251249
min_dist = min(get_distance(self.cell, cell) for cell in candidates)
252250

253251
final_candidates = [

0 commit comments

Comments
 (0)