我正在尝试编写一个乌龟搜索功能,其中:
如果社交性> = 0.5且局部斑块密度<1。目标密度
然后在半径内搜索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之间的值。 目标密度是从其他地方输入的,并且是整数。
不要求任何人调试此代码,但至少让我知道我是否在正确的轨道上或建议我应该在哪里寻找。谢谢!
答案 0 :(得分:2)
这是我尝试理解逻辑的最佳尝试。
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
]
]
答案 1 :(得分:0)
使用上面的评论我现在有一个功能代码。如果你为自己重新设计它,我建议删除颜色变化(我刚刚用来测试每个函数被调用)。 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]]