我正在使用与其他人一起编写的NetLogo代码(免费向公众开放)。我试着理解如何详细阐述龟移动的过程,最重要的是 - 如何在不失去与世界补丁相关的龟运动灵敏度的情况下,使其计算速度更快?
我认为大部分的计算时间用于计算龟运动每一步的距离 - 我只想测量从龟的起源到最后一个补丁的一个变量。 我已经解码了一些功能,但我仍然无法重现它们。我真的很感激任何帮助!
我理解程序可以完成的任务:
to move-turtles
ifelse perceptdist = 0
[ifelse patch-ahead 1 != nobody
[rt random moveangle lt random moveangle
let xcorhere [pxcor] of patch-here
let ycorhere [pycor] of patch-here
fd 1
let xcornext [pxcor] of patch-here
let ycornext [pycor] of patch-here
set dist sqrt (xcor * xcor + ycor * ycor)
set t_dispers (t_dispers + 1)
set energy (energy - (1 / efficiency))
let flightdistnow sqrt ((xcornext - xcorhere) * (xcornext - xcorhere) + (ycornext - ycorhere) * (ycornext - ycorhere))
set flightdist (flightdist + flightdistnow)
][]]
[let np patches in-radius perceptdist ; find the patch with the highest totalattract value within perception range
let bnp max-one-of np [totalattract]
let ah [totalattract] of patch-here
let xcorhere [pxcor] of patch-here
let ycorhere [pycor] of patch-here
let abnp [totalattract] of bnp
; -- why this ifelse condition is here ansd why they use these numbers?? ---
ifelse abnp - ah > 2 and random-float 1 < 0.1
[move-to bnp ; move to the patch with the highest attractivity value
let xbnp [pxcor] of bnp
let ybnp [pycor] of bnp
let flightdistnow sqrt ((xbnp - xcorhere) * (xbnp - xcorhere) + (ybnp - ycorhere) * (ybnp - ycorhere))
set t_dispers (t_dispers + flightdistnow)
set energy (energy - (flightdistnow / efficiency)) ; how the turtle decision to stay/move further is made - ratio of turtle energy/efficiency
set flightdist (flightdist + flightdistnow)
set dist sqrt (xcor * xcor + ycor * ycor)
[rt random moveangle lt random moveangle
set dist sqrt (xcor * xcor + ycor * ycor)
set t_dispers (t_dispers + 1)
set energy (energy - (1 / efficiency))
let xcorhere2 [pxcor] of patch-here
let ycorhere2 [pycor] of patch-here
fd 1
let xcornext2 [pxcor] of patch-here
let ycornext2[pycor] of patch-here
set dist sqrt (xcor * xcor + ycor * ycor)
let flightdistnow sqrt ((xcornext2 - xcorhere2) * (xcornext2 - xcorhere2) + (ycornext2 - ycorhere2) * (ycornext2 - ycorhere2))
set flightdist (flightdist + flightdistnow)
end