@@ -140,7 +140,7 @@ def get_store_price_lambda(unique_id):
140140 """Return a lambda function that gets the
141141 price of a store by its unique ID."""
142142 return lambda m : next (
143- (agent .price for agent in m .store_agents if agent .unique_id == unique_id ), 0
143+ (agent .price for agent in m .agents_by_type [ StoreAgent ] if agent .unique_id == unique_id ), 0
144144 )
145145
146146 @staticmethod
@@ -150,7 +150,7 @@ def get_market_share_lambda(unique_id):
150150 return lambda m : next (
151151 (
152152 agent .market_share
153- for agent in m .store_agents
153+ for agent in m .agents_by_type [ StoreAgent ]
154154 if agent .unique_id == unique_id
155155 ),
156156 0 ,
@@ -163,7 +163,7 @@ def get_revenue_lambda(unique_id):
163163 return lambda m : next (
164164 (
165165 agent .market_share * agent .price
166- for agent in m .store_agents
166+ for agent in m .agents_by_type [ StoreAgent ]
167167 if agent .unique_id == unique_id
168168 ),
169169 0 ,
@@ -211,10 +211,10 @@ def step(self):
211211
212212 def recalculate_market_share (self ):
213213 # Reset market share for all stores directly
214- for store in self .store_agents :
214+ for store in self .agents_by_type [ StoreAgent ] :
215215 store .market_share = 0
216216
217- for consumer in self .consumer_agents :
217+ for consumer in self .agents_by_type [ ConsumerAgent ] :
218218 preferred_store = consumer .determine_preferred_store ()
219219 if preferred_store :
220220 preferred_store .market_share += 1
@@ -238,16 +238,16 @@ def export_data(self):
238238 def compute_average_price (self ):
239239 if len (self .store_agents ) == 0 :
240240 return 0
241- return np .mean ([agent .price for agent in self .store_agents ])
241+ return np .mean ([agent .price for agent in self .agents_by_type [ StoreAgent ] ])
242242
243243 # Function to compute the average market share for all store agents,
244244 def compute_average_market_share (self ):
245245 if not self .store_agents :
246246 return 0
247247
248- total_consumers = sum (agent .market_share for agent in self .store_agents )
249- average_market_share = total_consumers / len (self .store_agents )
248+ total_consumers = sum (agent .market_share for agent in self .agents_by_type [ StoreAgent ] )
249+ average_market_share = total_consumers / len ( self .agents_by_type [ StoreAgent ] )
250250 return average_market_share
251251
252252 def compute_price_variance (self ):
253- return np .var ([agent .price for agent in self .store_agents ])
253+ return np .var ([agent .price for agent in self .agents_by_type [ StoreAgent ] ])
0 commit comments