Netlogo:测量海龟到每个补丁的距离,并由此进行计算
新的Netlogo用户在这里,我感觉很卡住。我正试着给海龟们做模型,为它们的家庭范围挑选补丁。目前,所有的补丁都有食物收益0.1或1.0,海龟通过寻找下一个最近的收益为1.0的补丁来选择补丁添加到它的家庭范围。在选择高效益补丁的过程中,它会自动添加任何与效益0.1交叉的补丁。对于这种行为,此代码似乎工作正常 但是,我希望海龟做一些不同的事情,而不仅仅是选择值为1.0的下一个最近的补丁。相反:Netlogo:测量海龟到每个补丁的距离,并由此进行计算,netlogo,Netlogo,新的Netlogo用户在这里,我感觉很卡住。我正试着给海龟们做模型,为它们的家庭范围挑选补丁。目前,所有的补丁都有食物收益0.1或1.0,海龟通过寻找下一个最近的收益为1.0的补丁来选择补丁添加到它的家庭范围。在选择高效益补丁的过程中,它会自动添加任何与效益0.1交叉的补丁。对于这种行为,此代码似乎工作正常 但是,我希望海龟做一些不同的事情,而不仅仅是选择值为1.0的下一个最近的补丁。相反: 我想让海龟观察景观中的所有斑块,并计算从其活动范围中心到景观中每个斑块的距离 然后,它应该计算出对海龟的
;;------------------------------------Run model-----------------------------
;; benefit is the food benefit on a patch, either 0.1 or 1.0
;; sum-v is the total food benefits acquired by the turtle as it picks patches for its home range
;; threshold-v is the total benefits required in order to satisfy home range requirements.
;; patches are used? = true once picked, so turtle can only pick unused patches.
;; start-patch is the origin (center) of the home range, from which turtle picks patches.
to go
ask turtles
[pick-territory]
tick
end
to pick-territory
ifelse sum-v < threshold-v ;; if the turtle's sum-v is less than threshold-v, then keep picking
[
;--This line works:---
set destination min-one-of patches with [ benefit >= 1 and used? = false ][ distance myself ]
;; This line appears to work so that turtle decides which is next-closest high-benefit, unused patch from its home range center.
;--BUT...this is what I want to do:---
;; Calculate distance to all patches from start-patch (turtle's home range origin).
;; Calculate "value-to-me" as the benefit (of patch) divided by distance to that patch from turtle's start-patch.
;; Set destination to highest value-to-me patch.
;; I've tried all sorts of things to do this, to no avail.
;; For example, the following code doesn't work...
let value-to-me [benefit / distance myself]
set destination max-one-of value-to-me
;; So I'm hoping for help with all this.
;--After it sets its destination, the turtle does the following:
face destination
forward 1 ;; move forward 1 and do all these things....
set memory lput patch-here memory ;; turtle adds patch to memory of home range as it moves across it
if patch-here = destination
[
set sum-v sum-v + benefit ;; monitors total sum-v acquired as the sum of all benefits from patches
set patches-picked patches-picked + 1 ;; counts the # of patches picked for home range
set used? true ;; changes patch to used? true so knows it's no longer available
let this-turtle self
set owner this-turtle ;; adds the turtle's name to the patch so the patch knows who owns it
move-to start-patch ;; return to origin and find a new available destination patch
]
if patch-here != destination ;; meanwhile, if the patch isn't the destination (turtle moves across it to get there), then do the following:
[
if used? = false ;; if it's an available patch...still add it to the home range, add +1 to patches-picked, add its benefits to sum-v, etc.
[ set sum-v sum-v + benefit
set patches-picked patches-picked + 1
set used? true
let this-turtle self
set owner this-turtle
]
]
]
[stop] ;; stop if sum-v => threshold-v.
end
------------------------------------运行模式-----------------------------
;; 好处是贴片上的食物好处,0.1或1.0
;; sum-v是海龟在为自己的活动范围挑选补丁时获得的食物总收益
;; threshold-v是满足home range要求所需的总收益。
;; 是否使用了修补程序?=一旦拾取,则为true,因此海龟只能拾取未使用的补丁。
;; “起始面片”是“主范围”的原点(中心),海龟从中拾取面片。
外带
问海龟
[选择区域]
打上钩
结束
择地
ifelse和v=1和used?=false][distance Own]设置其中一个修补程序的目标最小值
这条线似乎起作用了,所以乌龟决定哪一个是距离它的家牧场中心最近的高收益、未使用的补丁。
但是……这就是我想做的:---
;;计算从起始面片到所有面片的距离(海龟的原点)。
;计算“对我的价值”为(补丁的)好处除以从海龟的起始补丁到该补丁的距离。
;;将目标设置为“我的补丁”的最高值。
我试过各种方法来做这件事,但都没有用。
;例如,以下代码不起作用。。。
让我珍惜[让自己受益/远离自己]
将目标最大值设置为“我”
所以我希望能在这方面得到帮助。
--海龟在设定了目的地后,会执行以下操作:
面向目的地
向前走;向前走,做所有这些事情。。。。
在此处设置内存lput patch memory;;海龟在移动时将补丁添加到主范围的内存中
如果这里的补丁=目的地
[
设置sum-v sum-v+效益;;将获得的sum-v总额作为补丁所有效益的总和进行监控
设置拾取的面片数拾取的面片数+1;;计算为主范围拾取的面片数
设置used?true;;将修补程序更改为used?true,以便知道它不再可用
让这只乌龟自己
设置此乌龟的所有者;;将乌龟的名称添加到修补程序中,以便修补程序知道谁拥有它
移动到开始修补程序;;返回原点并找到新的可用目标修补程序
]
如果patch here!=destination;;同时,如果patch不是目的地(turtle穿过它到达目的地),则执行以下操作:
[
如果使用?=false;;如果它是一个可用补丁…仍然将其添加到主范围,将+1添加到拾取的补丁,将其优点添加到sum-v,等等。
[设置sum-v sum-v+福利
设置拾取的面片拾取的面片+1
用过吗?对
让这只乌龟自己
把这只乌龟交给主人
]
]
]
[停止];;如果sum-v=>threshold-v,则停止。
结束
海龟可以移动到一个补丁的最大值[好处/距离我自己]
。(但一定要考虑你选择的拓扑,因为它会影响距离)。这正是我需要的,谢谢艾伦!(现在看来很明显!)再次感谢你。