agent-based simulation: performance issue: Python vs NetLogo & Repast

后端 未结 4 676
滥情空心
滥情空心 2021-02-03 10:17

I\'m replicating a small piece of Sugarscape agent simulation model in Python 3. I found the performance of my code is ~3 times slower than that of NetLogo. Is it likely the pro

4条回答
  •  抹茶落季
    2021-02-03 10:57

    I'm going to guess that the way that neighborhood is implemented in NetLogo is different from the double loop you have. Specifically, I think they pre-calculate a neighborhood vector like

    n = [ [0,1],[0,-1],[1,0],[-1,0]....]
    

    (you would need a different one for vision=1,2,...) and then use just one loop over n instead of a nested loop like you are doing. This eliminates the need for the multiplications.

    I don't think this will get you 3X speedup.

提交回复
热议问题