Skip to content

Commit

Permalink
Revert "fix: Use new API to loop over agents_by_type"
Browse files Browse the repository at this point in the history
This reverts commit ef2b5e7.
  • Loading branch information
rht committed Jan 24, 2024
1 parent b547ee3 commit cf38477
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions examples/sugarscape_g1mt/sugarscape_g1mt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ def __init__(
model_reporters={
"Trader": lambda m: m.schedule.get_type_count(Trader),
"Trade Volume": lambda m: sum(
len(a.trade_partners) for a in m.schedule.agents_by_type[Trader]
len(a.trade_partners)
for a in m.schedule.agents_by_type[Trader].values()
),
"Price": lambda m: geometric_mean(
flatten([a.prices for a in m.schedule.agents_by_type[Trader]])
flatten(
[a.prices for a in m.schedule.agents_by_type[Trader].values()]
)
),
},
agent_reporters={"Trade Network": lambda a: get_trade(a)},
Expand Down Expand Up @@ -140,7 +143,7 @@ def randomize_traders(self):
puts traders in randomized list for step function
"""

traders_shuffle = list(self.schedule.agents_by_type[Trader])
traders_shuffle = list(self.schedule.agents_by_type[Trader].values())
self.random.shuffle(traders_shuffle)

return traders_shuffle
Expand All @@ -151,7 +154,7 @@ def step(self):
and then randomly activates traders
"""
# step Resource agents
for resource in self.schedule.agents_by_type[Resource]:
for resource in self.schedule.agents_by_type[Resource].values():
resource.step()

# step trader agents
Expand Down
2 changes: 1 addition & 1 deletion examples/wolf_sheep/wolf_sheep/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_type_count(
if type_class not in self.agents_by_type:
return 0
count = 0
for agent in self.agents_by_type[type_class]:
for agent in self.agents_by_type[type_class].values():
if filter_func is None or filter_func(agent):
count += 1
return count

0 comments on commit cf38477

Please sign in to comment.