3737def get_num_rich_agents (model ):
3838 """list of rich agents"""
3939
40- rich_agents = [a for a in model .schedule . agents if a .savings > model .rich_threshold ]
40+ rich_agents = [a for a in model .agents if a .savings > model .rich_threshold ]
4141 # return number of rich agents
4242 return len (rich_agents )
4343
4444
4545def get_num_poor_agents (model ):
4646 """list of poor agents"""
4747
48- poor_agents = [a for a in model .schedule . agents if a .loans > 10 ]
48+ poor_agents = [a for a in model .agents if a .loans > 10 ]
4949 # return number of poor agents
5050 return len (poor_agents )
5151
@@ -54,9 +54,7 @@ def get_num_mid_agents(model):
5454 """list of middle class agents"""
5555
5656 mid_agents = [
57- a
58- for a in model .schedule .agents
59- if a .loans < 10 and a .savings < model .rich_threshold
57+ a for a in model .agents if a .loans < 10 and a .savings < model .rich_threshold
6058 ]
6159 # return number of middle class agents
6260 return len (mid_agents )
@@ -65,15 +63,15 @@ def get_num_mid_agents(model):
6563def get_total_savings (model ):
6664 """list of amounts of all agents' savings"""
6765
68- agent_savings = [a .savings for a in model .schedule . agents ]
66+ agent_savings = [a .savings for a in model .agents ]
6967 # return the sum of agents' savings
7068 return np .sum (agent_savings )
7169
7270
7371def get_total_wallets (model ):
7472 """list of amounts of all agents' wallets"""
7573
76- agent_wallets = [a .wallet for a in model .schedule . agents ]
74+ agent_wallets = [a .wallet for a in model .agents ]
7775 # return the sum of all agents' wallets
7876 return np .sum (agent_wallets )
7977
@@ -91,7 +89,7 @@ def get_total_money(model):
9189def get_total_loans (model ):
9290 """list of amounts of all agents' loans"""
9391
94- agent_loans = [a .loans for a in model .schedule . agents ]
92+ agent_loans = [a .loans for a in model .agents ]
9593 # return sum of all agents' loans
9694 return np .sum (agent_loans )
9795
@@ -129,7 +127,7 @@ def __init__(
129127 self .height = height
130128 self .width = width
131129 self .init_people = init_people
132- self . schedule = mesa . time . RandomActivation ( self )
130+
133131 self .grid = mesa .space .MultiGrid (self .width , self .height , torus = True )
134132 # rich_threshold is the amount of savings a person needs to be considered "rich"
135133 self .rich_threshold = rich_threshold
@@ -150,8 +148,8 @@ def __init__(
150148 agent_reporters = {"Wealth" : "wealth" },
151149 )
152150
153- # create a single bank for the model
154- self .bank = Bank (1 , self , self .reserve_percent )
151+ # create a single bank object for the model
152+ self .bank = Bank (self , self .reserve_percent )
155153
156154 # create people for the model according to number of people set by user
157155 for i in range (self .init_people ):
@@ -162,16 +160,14 @@ def __init__(
162160 p = Person (i , (x , y ), self , True , self .bank , self .rich_threshold )
163161 # place the Person object on the grid at coordinates (x, y)
164162 self .grid .place_agent (p , (x , y ))
165- # add the Person object to the model schedule
166- self .schedule .add (p )
167163
168164 self .running = True
169165
170166 def step (self ):
171167 # collect data
172168 self .datacollector .collect (self )
173169 # tell all the agents in the model to run their step function
174- self .schedule . step ( )
170+ self .agents . shuffle (). do ( "step" )
175171
176172 def run_model (self ):
177173 for i in range (self .run_time ):
0 commit comments