@@ -140,7 +140,12 @@ 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 .agents_by_type [StoreAgent ] if agent .unique_id == unique_id ), 0
143+ (
144+ agent .price
145+ for agent in m .agents_by_type [StoreAgent ]
146+ if agent .unique_id == unique_id
147+ ),
148+ 0 ,
144149 )
145150
146151 @staticmethod
@@ -211,10 +216,10 @@ def step(self):
211216
212217 def recalculate_market_share (self ):
213218 # Reset market share for all stores directly
214- for store in self .agents_by_type [StoreAgent ]:
219+ for store in self .agents_by_type [StoreAgent ]:
215220 store .market_share = 0
216221
217- for consumer in self .agents_by_type [ConsumerAgent ]:
222+ for consumer in self .agents_by_type [ConsumerAgent ]:
218223 preferred_store = consumer .determine_preferred_store ()
219224 if preferred_store :
220225 preferred_store .market_share += 1
@@ -238,15 +243,17 @@ def export_data(self):
238243 def compute_average_price (self ):
239244 if len (self .store_agents ) == 0 :
240245 return 0
241- return np .mean ([agent .price for agent in self .agents_by_type [StoreAgent ]])
246+ return np .mean ([agent .price for agent in self .agents_by_type [StoreAgent ]])
242247
243248 # Function to compute the average market share for all store agents,
244249 def compute_average_market_share (self ):
245250 if not self .store_agents :
246251 return 0
247252
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 ])
253+ total_consumers = sum (
254+ agent .market_share for agent in self .agents_by_type [StoreAgent ]
255+ )
256+ average_market_share = total_consumers / len (self .agents_by_type [StoreAgent ])
250257 return average_market_share
251258
252259 def compute_price_variance (self ):
0 commit comments