nkremerh / sugarscape

Development repository for the Digital Terraria Lab implementation of the Sugarscape agent-based societal simulation.
https://github.com/digital-terraria-lab/sugarscape
MIT License
7 stars 11 forks source link

Fixes #56 agent range is not what is expected for other agents and at the end of timestep #66

Closed colinhanrahan closed 3 months ago

colinhanrahan commented 3 months ago

56

Just for future reference, this will definitely increase runtime.

nkremerh commented 3 months ago

What if I told you this actually cut runtime in half?

I ran the same 100 seeds out to 500 timesteps (for ease of data collection) for the head of the current master branch and this branch using the benthamHalfLookahead decision model. Both branches produced 100% better outcomes from their starting populations (this number can be obtained by running make plots).

This branch, however, produced 10% lower population on average (1,000 for the master branch vs. 900 for this branch). Every other metric tracked was more or less the same.

Time for master branch:

real    13m56.042s
user   263m53.385s
sys       0m9.615s

Time for this branch:

real     7m49.831s
user   138m14.411s
sys       0m7.189s

Thoughts? Population size definitely contributes the most to runtime. A 10% difference in population leading to a nearly 50% reduction in runtime seems a bit extreme.

colinhanrahan commented 3 months ago

Comparing the two branches using Snakeviz on the same seed (and using benthamHalfLookaheadBinary), it seems like almost every function is getting its runtime halved. That's pretty odd. Maybe the 10% difference is actually causing that big of a difference? I'll investigate this more.

colinhanrahan commented 3 months ago
  • Updates agent initialization to find cellsInRange and neighborhood, matching child creation

This addition is redundant with sugarscape.py lines 144-146. The sugarscape.py lines should be kept and my addition will be removed because all agents need to be created first in order for neighborhoods to be correct on the first timestep.

colinhanrahan commented 3 months ago

I ran a test on both branches where I ended runs based on the number of agents (I ended at 500) instead of the number of timesteps. This PR is more time intensive as expected. If you want to mass test this, modify line 604 in sugarscape.py:

- while t <= timesteps and len(self.agents) > 0:
+ while t <= timesteps and len(self.agents) > 0 and len(self.agents) <= 500:
colinhanrahan commented 3 months ago

Note: one more findCellsInRange() should be added to catchDisease() for agents who already had their timestep but are catching a disease from another agent. I'll add it to the Kanban board.