Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
- update eat function based on user identified bug in COmplexity Expl…
…orer Tutorial

- update Readme so batch run does not get an arugment error
- update run so data processing of batchrunner doe snot get a key error
  • Loading branch information
tpike3 committed Mar 25, 2023
commit 0812b2325055fb8cb221e1503a87e690f774cc99
2 changes: 1 addition & 1 deletion examples/sugarscape_g1mt/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ To run the model a single instance of the model:
To run the model with BatchRunner:

```
$ python run.py
$ python run.py -b
```

To run the model interactively:
Expand Down
2 changes: 1 addition & 1 deletion examples/sugarscape_g1mt/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def assess_results(results, single_agent):
plt.plot(results_df["Step"], results_df["Trader"])
plt.show()
else:
n = max(results_df["RunID"])
n = max(results_df["RunId"])
# Plot number of Traders
for i in range(n):
results_explore = results_df[results_df["RunId"] == i]
Expand Down
14 changes: 7 additions & 7 deletions examples/sugarscape_g1mt/sugarscape_g1mt/trader_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,23 +322,23 @@ def move(self):
self.model.grid.move_agent(self, final_candidate)

def eat(self):
"""
Function for trader to consume sugar and spice in grid cell
"""

# get sugar
sugar_patch = self.get_sugar(self.pos)
# eat sugar

if sugar_patch:
Copy link
Contributor

@rht rht Mar 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be:

if sugar_patch:
    self.sugar  += sugar_patch.amount
    sugar_patch.amount = 0
self.sugar -= metabolism_sugar

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I interpreted the matrix conversation that you didn't have a strong opinion either-- the way I changed it or the way you commented.

With how I changed it is just adding lines, although more verbose, vs rewriting the if statement

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think simplifying to not have else does definitely clarify the code that self.sugar -= metabolism_sugar happens in all branches of execution. The one that I don't have opinion is on the grouping collect sugar, eat sugar, collect spice, eat spice vs collect sugar & spice, eat sugar & spice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh...got it I will update and sync the tutorial as well.

self.sugar = self.sugar - self.metabolism_sugar + sugar_patch.amount
sugar_patch.amount = 0
else:
self.sugar -= self.metabolism_sugar

# get spice
# get_spice
spice_patch = self.get_spice(self.pos)
# eat spice

if spice_patch:
self.spice = self.spice - self.metabolism_spice + spice_patch.amount
spice_patch.amount = 0
else:
self.spice -= self.metabolism_spice

def maybe_die(self):
"""
Expand Down