How to avoid individual patch updates

泄露秘密 提交于 2019-12-11 03:21:55

问题


I am modeling diffusion in my model, but I think I am getting a calculation artifact due to NetLogo sequentially updating individual patches. I will not be using the diffuse command (due to inaccurate diffusion). However, much like how this command works, I would like to update all the calculations of the patches simultaneously, rather than sequentially. I have a slight recollection of seeing some sample code that used values at the beginning of the tick, however I can´t seem to find it now.

Specifically, I need help programming a way to store patch values at the turn of each tick, and then carry out a simultaneous calculation based on these stored values.


回答1:


Great question. As you indicate, basically you want to calculate the new value of the variable in one ask block, but store it in a separate variable, and then update the actual value of the variable in a second ask block, like so:

turtles-own [
  value
  new-value
]

...
to go
  ask patches [
    ;; Change this line to however you want the diffusion to work
    set new-value 0.5 * value + sum [  0.5 * value / 4 ] of neighbors4
  ]
  ask patches [
    set value new-value
  ]
end

This way all patches calculate their updated values from the same information, and then actually update the values themselves simultaneously.



来源:https://stackoverflow.com/questions/25976846/how-to-avoid-individual-patch-updates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!