diff --git a/examples/sugarscape_g1mt/sugarscape_g1mt/model.py b/examples/sugarscape_g1mt/sugarscape_g1mt/model.py index 1e3dbb607..42288b8b3 100644 --- a/examples/sugarscape_g1mt/sugarscape_g1mt/model.py +++ b/examples/sugarscape_g1mt/sugarscape_g1mt/model.py @@ -187,6 +187,13 @@ def step(self): # collect model level data self.datacollector.collect(self) + # Need to remove excess data + # Create local variable to store trade data + agent_trades = self.datacollector._agent_records[self.schedule.steps] + # Get rid of all None to reduce data storage needs + agent_trades = [agent for agent in agent_trades if agent[2] is not None] + # Reassign the dictionary value with lean trade data + self.datacollector._agent_records[self.schedule.steps] = agent_trades def run_model(self, step_count=1000): for i in range(step_count): diff --git a/examples/sugarscape_g1mt/sugarscape_g1mt/trader_agents.py b/examples/sugarscape_g1mt/sugarscape_g1mt/trader_agents.py index 477a0308a..5717761e7 100644 --- a/examples/sugarscape_g1mt/sugarscape_g1mt/trader_agents.py +++ b/examples/sugarscape_g1mt/sugarscape_g1mt/trader_agents.py @@ -140,16 +140,21 @@ def is_starved(self): return (self.sugar <= 0) or (self.spice <= 0) - def calculate_MRS(self): - """ - Helper function for self.trade() - - Determines what trader agent is needs and can give up - """ - - return (self.spice / self.metabolism_spice) / ( - self.sugar / self.metabolism_sugar - ) + def calculate_MRS(self, sugar= None, spice = None): + ''' + Helper function for + - self.trade() + - self.maybe_self_spice() + + Determines what trader agent needs and can give up + ''' + if sugar == None: + sugar = self.sugar + if spice == None: + spice = self.spice + + return (spice/self.metabolism_spice) / ( + sugar/self.metabolism_sugar) def calculate_sell_spice_amount(self, price): """ @@ -205,8 +210,8 @@ def maybe_sell_spice(self, other, price, welfare_self, welfare_other): welfare_self < self.calculate_welfare(self_sugar, self_spice) ) and (welfare_other < other.calculate_welfare(other_sugar, other_spice)) - # trade criteria #2 is their mrs crossing - mrs_not_crossing = self.calculate_MRS() > other.calculate_MRS() + #trade criteria #2 is their mrs crossing with potential trade + mrs_not_crossing = self.calculate_MRS(self_sugar, self_spice) > other.calculate_MRS(other_sugar, other_spice) if not (both_agents_better_off and mrs_not_crossing): return False