如何避免个别补丁更新 [英] How to avoid individual patch updates

查看:103
本文介绍了如何避免个别补丁更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在模型中对扩散进行建模,但是由于NetLogo会顺序更新各个补丁,因此我认为我得到了一个计算工件.我将不会使用 diffuse 命令(由于扩散不准确).但是,就像此命令的工作原理一样,我想同时而不是顺序更新所有补丁的计算.我稍微想起了一些示例代码,这些示例代码在刻度的开头使用了值,但是现在看来似乎找不到了.

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.

推荐答案

好问题.正如您所指出的,基本上,您想在一个ask块中计算变量的新值,但将其存储在单独的变量中,然后在第二个ask块中更新变量的实际值,如下所示:

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.

这篇关于如何避免个别补丁更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆