我正在编写一个海龟搜索函数,其中:
如果可社交性>= 0.5和局部斑块密度<目标密度
然后搜索半径内的Moves_per_tick,寻找一个密度与目标密度之差小于电流密度与目标密度之差的斑块。
如果一个人存在,那么移动到那个补丁。如果不存在,则进行长度为moves_per_tick的随机移动
但是,我还不太熟悉NetLogo语言来实现这一点。我看过几个类似的问题,但没有一个问题能让我更接近我的目标。
我目前正在处理这个代码,它在很多方面都被破坏了:
to start_search_personality
let LD density
let AT (Target_density * sociability)
let C_D (AT - LD)
if sociability >= 0.5
[
ifelse C_D >= 0
[
let P any? one-of patches with (patches in-radius moves_per_tick with [density] > LD)
if [density] of P > LD
[face p move-to p]]
[move-to patch-here]
]密度由斑块所拥有,并被定义为斑块中海龟的数量。海龟具有社交能力,这个值介于0到1之间。目标密度是从其他地方输入的,是整数。
没有要求任何人调试这段代码,但至少让我知道我是否在正确的轨道上,或者建议我应该在哪里查找。谢谢!
发布于 2016-05-12 14:51:49
这是我试图理解逻辑的最好尝试。
to start_search_personality
let density-here count turtles-here
if sociability >= 0.5 and density-here < target-density
[
let p patches in-radius moves_per_tick
ifelse any? p with [target-density < abs (density - target-density)]
[move-to one-of p with [target-density < abs (density - target-density)]]
[ ;;move in a random direction of length moves per tick
set heading (random 360)
fd moves_per_tick
]
]发布于 2016-05-12 19:57:55
使用上面的注释,我现在有了一个函数代码。如果您正在为自己重新定位,我建议删除颜色更改(我只是用来测试每个函数是否被调用)。Target_density是在运行开始时固定的,海龟自己的(固定在0到1之间),斑块本身的密度(在每个滴答上更新,并定义为补丁中海龟的数量)。最后的障碍是建立一个排名系统,因为这个代码对高target_densities很敏感。
to check_personality
move-to patch-here
let N max-one-of neighbors [density]
let ND max [density] of neighbors
let LD [density] of patch-here
let AT (Target_density * s)
let p patches in-radius moves_per_tick_baseline
let diff_1 (AT - LD) < (AT - ND)
let diff_2 (AT - LD) > (AT - ND)
let diff_3 (AT - LD) = (AT - ND)
ifelse s > 0.5
[if LD < AT[
if diff_1 [ set color white
ifelse density >= (0.90 * AT)
[move-to patch-here]
[ifelse any? p with [density > LD]
[move-to one-of p with [density > LD]]
[face N forward moves_per_tick_baseline]
]
]
if diff_2[ set color gray
move-to N
]
if diff_3
[if ND < LD
[
set color black
ifelse any? p with [density >= LD]
[move-to one-of p with [density >= LD]]
[face N forward moves_per_tick_baseline]
]
if ND > LD
[move-to patch-here face N move-to N]]
if ND = LD
[ifelse ND = 0
[set heading (random 360) forward moves_per_tick_baseline]
[set heading (random 360) forward moves_per_tick_baseline]
]
]
if LD >= AT [set color yellow set size 10]]https://stackoverflow.com/questions/37190032
复制相似问题