NetLogo:如何根据补丁变量从相邻补丁中提取坐标

NetLogo: How to pull coordinates from neighboring patches based on patch-variable

我的编程经验有限(机械工程专业的学生,​​所以有一点 matlab 和 labview 的经验)并且是 NetLogo 的新手,所以如果这个问题很基础或者我的代码质量很差,我提前道歉。

我需要让我的海龟根据给定的概率函数移动到 2 个可能的相邻块中的 1 个。我需要输入到概率函数的两个补丁是巢气味值最低的两个相邻补丁。我已经能够提取两个最低的 nest-scent 值,但我无法弄清楚如何实际找出这些补丁是哪些补丁,以及如何将这些坐标放入 ifelse 语句中以根据上述概率函数。我有以下代码显然不起作用:

    to move
  set farthest-patch sort-by < [nest-scent] of neighbors
  let a1x pxcor of item 0 farthest-patch
  let a1y pycor of item 0 farthest-patch
  let a2x pxcor of item 1 farthest-patch
  let a2y pycor of item 1 farthest-patch
  let a1 item 0 farthest-patch
  let a2 item 1 farthest-patch
  let x (((a1 + a2) / 100 ) - 1)
  let probability-move 0.5 * (1 + ((exp(x) - exp( - x)) / (exp(x) + exp( - x))))
  ifelse random-float 1 < probability-move
  [set to-move 1]
  [set to-move 0]
  let a1-probability (a1 / (a1 + a2))
  ifelse random-float 1 < a1-probability
    [set destination [a1x a1y]]
    [set destination [a2x a2y]]
    ifelse count turtles-here >= 20
    [set full 1]
    [set full 0]
  if [a1x a21] = full
  [set destination [a2x a2y]]
  if [a2x a2y] = full
  [set destination [a1x a1y]]
  if [a2x a2y] and [a1x a1y] = full
  [set to-move 0]
  ifelse to-move = 1
  [move-to destination]
  [stop]
end

基本上我在这里(尝试)做的是通过增加巢香来对最远的补丁列表进行排序,并且我已经提取了两个最低的巢香值,以便将这些值输入到我的概率函数中(是否移动,以及是否将两个补丁中的哪一个移动到 select)。我不确定如何正确提取 a1 和 a2 值所取自的补丁的补丁坐标。

感谢您的帮助,

布拉德

好吧,你让生活变得更复杂了。您可以 select 具有变量最小值的两个补丁(或海龟) min-n-of。查字典了解详情。

找到两个候选者后,最好的选择是使用 rnd 扩展来选择目的地,因为它有一个按重量随机 selection 的原语。最后,由于您使用变量的函数作为权重(而不是变量值本身),因此您需要一种构造该权重的方法。最好的选择是把它分开——你也可以有第二个变量和权重值,但这只会增加变量。

这是一个完整的工作模型。请将整个东西复制到 NetLogo 的一个新实例中并尝试理解它是如何工作的,而不是仅仅将相关位复制到您的代码中,因为 min-n-of,使用代理集和将变量传递给过程是 NetLogo 的重要方面,您需要了解。我还设置了着色等,所以你可以看到它所做的选择。

extensions [rnd]

patches-own [ nest-scent ]

to setup
  clear-all
  create-turtles 1 [ set color red ]
  ask patches
  [ set nest-scent random 100
    set plabel nest-scent
  ]
  reset-ticks
end

to go
  ask one-of turtles [ move ]
  tick
end

to move
  set pcolor blue
  let targets min-n-of 2 neighbors [ nest-scent ]
  let destination rnd:weighted-one-of targets [ calc-weight nest-scent ]
  move-to destination
end

to-report calc-weight [ XX ]
  let weight 0.5 * (1 + ((exp(XX) - exp( - XX)) / (exp(XX) + exp( - XX))))
  report weight
end