NetLogo:让乌龟设定目的地,并一直朝它走,直到到达为止

NetLogo:让乌龟设定目的地,并一直朝它走,直到到达为止,netlogo,Netlogo,目标:我试图让一只海龟选择一个目的地,然后继续朝它走,直到到达目的地。在这一点上,海龟回到它原来的地方,选择另一个目的地,走向它,重复 问题:当乌龟朝目标走去时,选定的目标有时会改变。我需要一些方法告诉乌龟保持原来的目的地直到它到达它 详细信息:这是我的相关代码。海龟们正在建造领地。他们有一个区域中心点(“起始点”),从中他们选择一个目的地步行前往并申领。目的地基于具有“最高价值”的修补程序,其中价值应为修补程序的利益(“对我的利益”)除以距起始修补程序的距离(“对我的成本”)。然而,我认为海龟

目标:我试图让一只海龟选择一个目的地,然后继续朝它走,直到到达目的地。在这一点上,海龟回到它原来的地方,选择另一个目的地,走向它,重复

问题:当乌龟朝目标走去时,选定的目标有时会改变。我需要一些方法告诉乌龟保持原来的目的地直到它到达它

详细信息:这是我的相关代码。海龟们正在建造领地。他们有一个区域中心点(“起始点”),从中他们选择一个目的地步行前往并申领。目的地基于具有“最高价值”的修补程序,其中价值应为修补程序的利益(“对我的利益”)除以距起始修补程序的距离(“对我的成本”)。然而,我认为海龟们在走路时会不断地重新评估我的成本。他们不应该这样做——站在起始补丁上时必须评估最高值

我如何解决这个问题,让海龟在站在起始补丁上时评估最高值,设置目标,并向目标移动直到到达

patches-own
[
  owner  ;; once part of a territory, owner becomes the turtle.
  benefit  ;; i.e., food available in a patch; used to assess "highest-value" to the turtle.
]

turtles-own
[
  start-patch  ;; the territory center; turtle returns here after reaching destination.
  destination  ;; the patch turtle wants to claim for its territory. 
  territory  ;; the patches the turtle owns.
]

to go
   tick
   ask turtles
    [
     pick-patch
    ]
end

to pick-patch
     set destination highest-value  ;; calculated in reporters, below.
     ifelse destination != nobody [
       ask destination [set pcolor red]  ;; reveals that destination changes occasionally before original destination is reached.
       travel]  
     [give-up]  ;; (will reposition start-patch to a new site if no destinations available.)
end

to travel
     face destination forward 1   ;; **should** keep original destination, but it doesn't.
     if patch-here = destination
       [update-territory  
        move-to start-patch ]  ;; return to the start-patch, and should only NOW assess new destination.             
end

to update-territory
     set owner self ;; and so on....
end

;;;---Reporters for highest-value:---

to-report highest-value    ;; this appears to be changing while turtle moves...how fix this?
     let available-destinations edge-patches      
     report max-one-of available-destinations [benefit-to-me / cost-to-me]         
end

to-report benefit-to-me
     report mean [benefit] of patches in-radius 1  ;; i.e., moving window to find high-benefit cluster
end

to-report cost-to-me
     report distance myself
end

to-report edge-patches
     report (patch-set [neighbors4] of territory) with [owner = nobody]
end
(注意:与“前进1”不同,我意识到我可以使用“移动到”。然而,我最终会设置障碍物,海龟需要向目的地走去检查障碍物。)

更新:我认为这个问题可以在“我的成本”报告中解决?我试着做了这样的改变:

to-report cost-to-me
     report distance [start-patch] of myself
end
这能实现我的目标吗?这将消除“我自己的距离”部分,使成本保持不变。我的另一个想法是,“选择补丁”或“旅行”可能需要类似于“ifelse补丁在这里!=目的地[forward 1…]”的东西,但这似乎也不起作用

我尝试了下面推荐的“while”循环(谢谢!),这似乎引入了一系列新的奇怪行为。如果我走那条路,我不知道该如何编码。像这样的东西不起作用(它们只是停止移动):

我是新来的;提前感谢您的帮助


第二次更新:我认为我在上一次更新中所做的更改(报告我自己的距离[start patch])修复了我的部分问题(假设该行有意义?),但留下了一个问题。如果具有最高值的补丁之间存在平局,海龟仍然会在中途将目标切换到其选定的补丁。因此,它仍然回到了最初的问题,即设置海龟并保留一个目的地,直到到达为止。有没有办法解决这个问题

你说得对-每次海龟运行
拾取补丁
,它都会将destination设置为
最高值
。然后,它将向前移动一个并检查是否已到达。在这一点上,无论它是否到达了目的地,其他海龟(如果有)都有机会运行
pick patch
。一旦所有其他海龟都这样做了,您的原始海龟将再次将其目的地设置为新评估的最高值。因此,由于
最高值
取决于距离,并且海龟的空间坐标随着移动而变化,因此其他一些斑块可能会从海龟的新位置获得
最高值

一种可以实现您所追求的目标的方法是在
时使用
,这样您的海龟就可以在程序中保持,直到达到您指定的任何标准为止。举一个非常简单的例子:

to move-until
  ask turtles [
    let start-patch patch-here
    let destination patch-ahead 10
    while [ distance destination > 1 ] [
      fd 1
    ]
  ]
end

显然,您必须修改它以满足您的需要,但它应该让您开始。

使用
时的困难在于它会在滴答声中一路移动。既然海龟返回到起始补丁,为什么不简单地添加一个条件,即它只在到达起始补丁时选择一个目的地呢?因此,代码如下所示:

to go
   tick
   ask turtles
   [ if patch-here = start-patch [pick-patch]
   ]
end

听起来你的海龟们仍然在每一步检查最高值的补丁。因此,您需要一种方法让它们只设置一次目的地(正如@JenB所说),这就是while循环所做的——海龟在到达目的地之前不会“退出”while循环。然而,如果你更喜欢使用
if
的话,就把你的程序分解一下——正如@JenB的回答。同意——我的想法是,家庭范围的选择(正如我从用户早期的模型中理解的那样)是独立于其他海龟的,因此蜱虫在这方面并不重要。但是,是的,这是更好的答案!
to go
   tick
   ask turtles
   [ if patch-here = start-patch [pick-patch]
   ]
end