如何让海龟在设定的半径内搜索具有设定条件的补丁
How do I make turtles search for patches with set conditions in a set radius
我正在尝试编写海龟搜索功能,其中:
如果社交性 >= 0.5 且局部斑块密度 < 目标密度
然后在半径 Moves_per_tick 中搜索密度与目标密度之差小于当前密度与目标密度之差的补丁。
如果存在则移动到那个补丁。
如果 none 存在则随机移动长度 moves_per_tick
但我对 NetLogo 语言还不够熟悉,无法做到这一点。我看过几个类似的问题,但其中 none 个问题让我离目标足够近了。
我目前正在处理这段代码,它在很多方面都有问题:
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 之间的值。
目标密度是从别处输入的,是一个整数。
不要求任何人调试此代码,但至少让我知道我是否在正确的轨道上或建议我应该寻找的地方。谢谢!
这是我试图理解逻辑的最佳尝试。
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
]
]
使用上面的注释,我现在有了一个功能代码。如果您要为自己重新设计它,我建议您删除颜色更改(我只是用它来测试调用了每个函数)。 Target_density 固定在 运行 的开头,海龟拥有 s(固定在 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]]
我正在尝试编写海龟搜索功能,其中:
如果社交性 >= 0.5 且局部斑块密度 < 目标密度
然后在半径 Moves_per_tick 中搜索密度与目标密度之差小于当前密度与目标密度之差的补丁。
如果存在则移动到那个补丁。 如果 none 存在则随机移动长度 moves_per_tick
但我对 NetLogo 语言还不够熟悉,无法做到这一点。我看过几个类似的问题,但其中 none 个问题让我离目标足够近了。
我目前正在处理这段代码,它在很多方面都有问题:
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 之间的值。 目标密度是从别处输入的,是一个整数。
不要求任何人调试此代码,但至少让我知道我是否在正确的轨道上或建议我应该寻找的地方。谢谢!
这是我试图理解逻辑的最佳尝试。
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
]
]
使用上面的注释,我现在有了一个功能代码。如果您要为自己重新设计它,我建议您删除颜色更改(我只是用它来测试调用了每个函数)。 Target_density 固定在 运行 的开头,海龟拥有 s(固定在 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]]