NetLogo:让turtle从补丁集执行计算

NetLogo:让turtle从补丁集执行计算,netlogo,Netlogo,我正在努力掌握NetLogo的窍门,需要一些帮助。我让海龟们根据最“有价值”的补丁选择补丁。价值是由选择补丁的收益和成本决定的,所以我需要海龟们做一些数学计算。基本上,海龟需要: 确定可用修补程序的修补程序集(尚未拥有的修补程序) 确定每个可用补丁对我的好处。每个补丁都有0-1的好处。为了确定对我的好处,海龟应该计算可用补丁加上半径2内该补丁的相邻补丁的平均好处(以移动窗口的方式识别一组高效益补丁) 确定每个可用补丁的成本。现在,这是补丁与海龟的距离。(我的成本将包括该型号未来版本中的其他注意事

我正在努力掌握NetLogo的窍门,需要一些帮助。我让海龟们根据最“有价值”的补丁选择补丁。价值是由选择补丁的收益和成本决定的,所以我需要海龟们做一些数学计算。基本上,海龟需要:

  • 确定可用修补程序的修补程序集(尚未拥有的修补程序)
  • 确定每个可用补丁对我的好处。每个补丁都有0-1的好处。为了确定对我的好处,海龟应该计算可用补丁加上半径2内该补丁的相邻补丁的平均好处(以移动窗口的方式识别一组高效益补丁)
  • 确定每个可用补丁的成本。现在,这是补丁与海龟的距离。(我的成本将包括该型号未来版本中的其他注意事项。)
  • 计算哪一个补丁对我最有价值,作为对我的好处/成本 这是有效的(或者我认为是这样——这是我认为的吗?):

    patches-own [
        benefit
        owner ]
    
    to go 
        ask turtles [pick-patch]
    end
    
    to pick-patch
        move-to highest-value
    end
    
    to-report highest-value 
        let available-destinations patches with [owner = 0]  ;; I think this accomplishes step 1.
        report max-one-of available-destinations [(mean [benefit] of patches in-radius 2) / (distance myself + 1)]  ;; and I believe(?) this accomplishes step 2-4. (Note, "distance myself + 1" seems required since can't divide by 0.)        
    end
    
    to-report highest-value 
        let available-destinations patches with [owner = 0]  
        let benefit-to-me ...??  ;; code to assess "(mean [benefit] of patches in-radius 2)" for the patch-set of available-destinations?
        let cost-to-me ...??  ;; and code to assess "(distance myself + 1)" of available destinations?
        report max-one-of available-destinations (benefit-to-me / cost-to-me) ...??  ;; code to perform calculations based on benefit-to-me and cost-to-me?          
    end
    
    但是我想把收益和成本分开:

    patches-own [
        benefit
        owner ]
    
    to go 
        ask turtles [pick-patch]
    end
    
    to pick-patch
        move-to highest-value
    end
    
    to-report highest-value 
        let available-destinations patches with [owner = 0]  ;; I think this accomplishes step 1.
        report max-one-of available-destinations [(mean [benefit] of patches in-radius 2) / (distance myself + 1)]  ;; and I believe(?) this accomplishes step 2-4. (Note, "distance myself + 1" seems required since can't divide by 0.)        
    end
    
    to-report highest-value 
        let available-destinations patches with [owner = 0]  
        let benefit-to-me ...??  ;; code to assess "(mean [benefit] of patches in-radius 2)" for the patch-set of available-destinations?
        let cost-to-me ...??  ;; and code to assess "(distance myself + 1)" of available destinations?
        report max-one-of available-destinations (benefit-to-me / cost-to-me) ...??  ;; code to perform calculations based on benefit-to-me and cost-to-me?          
    end
    
    如何完成此代码以达到预期效果?我猜可能有多种方法可以实现这种类型的编码。考虑到海龟们会无数次地重复寻找“最高价值”,什么样的选择可能是跑得最快的呢?提前谢谢你


    试图修改代码:(下面是Luke的回答。)

    自己的补丁程序[
    利益
    所有者]
    设置
    询问补丁程序[设置所有者无人]
    结束
    外带
    询问海龟[挑选补丁]
    打上钩
    结束
    
    挑选补丁 似乎在“最高值”报告程序中使用
    距离我自己
    可能会有问题-除非引用的两个代理之间的距离实际上为0,否则不应该得到除以零的错误,因此,您的可用修补程序似乎包括问问题的海龟当前使用的修补程序。如果您使用海龟的
    who
    来指定所有权,请记住,几乎总是有
    turtle0
    左右的海龟将“拥有”所有带有“owner=0”的补丁。例如,在初始设置中,让补丁程序将其“owner”变量设置为-1或nobody来避免这种情况

    如果一个补丁的好处不是基于海龟本身,你可以简化一点,让你的报告者只是该补丁的“移动窗口值”,通过减少报告者的
    距离
    部分。这样,海龟就可以查询补丁的移动窗口值除以距离。快速示例:

    patches-own [
        benefit
        owner ]
    
    
    to setup
      ca
      reset-ticks
    
      ask patches [ 
        set owner nobody 
        set benefit random-float 1 
        set pcolor benefit + 54
      ]
    
      crt 5 [ setxy (random 30 - 15)(random 30 - 15)
        ask patch-here [ 
          set owner [who] of myself
          set pcolor [color] of myself
        ]
      ]
    
    end
    
    
    to go 
        ask turtles [
          pick-patch
        ]
        tick
    end
    
    
    to-report moving-window-value 
      report mean [benefit] of patches in-radius 2  
    end
    
    
    to pick-patch
    
      let available-destinations patches with [ owner = nobody ]
      let best-patch max-one-of available-destinations [ moving-window-value / (distance myself) ]
      if best-patch != nobody [
        move-to best-patch 
        ask patch-here [ 
          set owner [who] of myself
          set pcolor [color] of myself
        ]
      ]
    end
    

    至于成本和收益的分离,你可以,但如果成本只是距离,你不需要计算它,因为它已经是一个原始的。除非您使用其他坡度,如海拔、地形类型等,否则您可能不需要存储距离成本就可以离开。

    谢谢您的帮助。重新。“距离我自己+1”,我知道我不需要+1部分;谢谢对“owner=0”的调用很好,我也解决了这个问题。因此,这就引出了对我的利益和成本进行突破的主要部分。成本最终将不仅仅包括距离(编辑我的问题以显示这一点)。根据您的回答,我在问题的末尾尝试了新代码。这看起来能实现我的目标吗?(你觉得这还有什么问题吗?)再次感谢!将上面添加的代码应用到我所设置的框架中,就我所知,这对我的代码是有效的-干得好!你可能应该确保海龟们确实在检查世界上所有的补丁——手动将一个非常高的收益分配给远离所有海龟的补丁,并确保下一次海龟运动会支持该补丁。另一个问题是,按原样生成非连续的主范围,但这并不是这个问题的范围。