我有有限的编程经验(机械工程专业的学生,所以有点matlab和labview的经验),而且我对NetLogo非常陌生,所以如果这个问题很基本或者我的代码质量很差,我很抱歉。
根据给定的概率函数,我需要让我的海龟移动到两个可能相邻的斑块中的一个。我需要输入到概率函数中的两个补丁是两个相邻的斑块,它们具有最低的嵌套气味值。我已经能够拉出两个最低的鸟巢气味值,但我无法弄清楚它们是哪些补丁,以及如何将这些坐标放入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基本上,我在这里所做的(尝试)是通过增加嵌套气味来排序一个最远的补丁列表,并且我已经提取了两个最低的嵌套气味值,以便将这些值输入到我的概率函数中(这两个值用于是否移动,如果要移动两个补丁中的哪个)。我不知道如何正确地提取从a1和a2值中提取的补丁的补丁坐标。
谢谢你的帮助,
布拉德
发布于 2016-02-07 11:41:17
好吧,你让生活变得更复杂了。您可以使用min-n-of选择变量的最小值的两个补丁(或海龟)。在字典里查一下,了解详情。
在找到了这两个候选项之后,最好的选择是使用rnd扩展来选择目的地,因为它有一个按权重进行随机选择的基元。最后,由于您使用变量的一个函数作为权重(而不是变量值本身),因此需要一种方法来构造该权重。最好的选择是把它分开-你也可以有第二个变量的权重值,但这只是扩散变量。
这是一个完整的工作模式。请将整个过程复制到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
endhttps://stackoverflow.com/questions/35251333
复制相似问题