Skip to content

Commit

Permalink
Fix bug in ordering of primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
charwick committed Jun 19, 2021
1 parent bc0da53 commit 78d27d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 5 additions & 3 deletions helipad/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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 = {
Expand Down
1 change: 0 additions & 1 deletion sample-models/pricediscover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down

0 comments on commit 78d27d9

Please sign in to comment.