From 78d27d9eec1efb9d0a24316c22b7299c56568030 Mon Sep 17 00:00:00 2001 From: charwick <1117120+charwick@users.noreply.github.com> Date: Sat, 19 Jun 2021 16:29:37 -0400 Subject: [PATCH] Fix bug in ordering of primitives --- helipad/model.py | 8 +++++--- sample-models/pricediscover.py | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/helipad/model.py b/helipad/model.py index d2ff731..6b30d0b 100644 --- a/helipad/model.py +++ b/helipad/model.py @@ -401,7 +401,7 @@ def reporter(model): return param.get(item) #Per-breed and per-good series and reporters #Don't put lambda functions in here, or the variable pairs will be reported the same, for some reason. - for breed, b in next(iter(self.primitives.values())).breeds.items(): + for breed, b in self.primitives[defPrim].breeds.items(): self.data.addReporter('utility-'+breed, self.data.agentReporter('utils', defPrim, breed=breed)) if self.visual is not None and self.visual.__class__.__name__=='TimeSeries': self.visual.plots['utility'].addSeries('utility-'+breed, breed.title()+' Utility', b.color) @@ -747,7 +747,8 @@ def debugConsole(self): #Return agents of a breed if string; return specific agent with ID otherwise def agent(self, var, primitive=None): - if primitive is None: primitive = next(iter(self.primitives)) + if primitive is None: + primitive = 'agent' if 'agent' in self.primitives else next(iter(self.primitives)) if isinstance(var, str): return [a for a in self.agents[primitive] if a.breed==var] else: @@ -758,7 +759,8 @@ def agent(self, var, primitive=None): #Returns summary statistics on an agent variable at a single point in time def summary(self, var, prim=None, breed=None): - if prim is None: primitive = next(iter(self.primitives)) + if prim is None: + prim = 'agent' if 'agent' in self.primitives else next(iter(self.primitives)) agents = self.agents[prim] if breed is None else self.agent(breed, prim) data = pandas.Series([getattr(a, var) for a in agents]) #Pandas gives us nice statistical functions stats = { diff --git a/sample-models/pricediscover.py b/sample-models/pricediscover.py index 414e22c..da3ab1a 100644 --- a/sample-models/pricediscover.py +++ b/sample-models/pricediscover.py @@ -17,7 +17,6 @@ heli.params['num_agent'].opts['step'] = 2 #Make sure we don't get stray agents heli.params['num_agent'].opts['low'] = 2 #Make sure we don't get stray agents - heli.addGood('shmoo','#11CC00', (1, 1000)) heli.addGood('soma', '#CC0000', lambda breed: (1, floor(exp(heli.param('ratio'))*1000)))