【问题标题】:Define home area-turtles?定义家庭区域 - 海龟?
【发布时间】:2013-12-30 00:44:39
【问题描述】:

我对 netlogo 很陌生。在发布之前,我已经在这里搜索了所有问题。

我有以下代码,它会发芽给定数量的马:

用 [grass? =“是”] [发芽马 1 [设置颜色 25]]

人们可以使用滑块更改马匹的数量,但我希望每匹马都有自己的面积/范围/半径。

他们只能在这个半径/区域内移动,他们不能相遇。

根据我的阅读,它与距离函数有关吗?

【问题讨论】:

  • 如果您需要使用新芽,您可以使用“询问 n-of Number-horses 补丁与 [Grass? = “yes” 而不是任何? Horses with [distance 我自己

标签: distance netlogo


【解决方案1】:

您可以在这里找到类似的问题,其中也有示例:

Spacing agents in NetLogo based on territory size

【讨论】:

    【解决方案2】:

    有几种方法可以为每匹马分配一个领土区域,但我知道的所有方法都有两个步骤,第一步是为了确保马的初始家乡区域彼此分开,所以我们需要只在与另一个有马的补丁有一定距离的补丁中创建马,我没有按照你要求补丁发芽马的方法,而是在不询问补丁的情况下创建它们。

    我不知道你是如何定义草的?每个补丁的变量,但我已经分配了一些草补丁? =真,其他假。 第二步是设置每匹马的家乡属性。如果最初您将它们彼此远离,它们将拥有不同的领土。

    我在这里举了几个例子: 首先在两个步骤中使用in-radius

    Breed [Horses horse]
    Horses-own [home-area]
    patches-own [grass?]
    globals [Zone-Radius]
    to setup
      clear-all
      reset-ticks
      set Zone-Radius 2
      ask patches 
      [ 
        ifelse pxcor mod 5 = 3  
        [  set Grass? true  ]
        [  set Grass? false  ]
      ]
      create-horses Number-horses  
      [ Move-to one-of patches with [Grass? and not any? other horses in-radius (Zone-Radius + 1)]
        set home-area patches in-radius Zone-Radius
        set color 25  
      ]
    end 
    
    to go
    
      ask horses [
        ifelse member? patch-ahead 1 home-area 
        [rt random 10 fd 1 ] ; move if next patch is in their zone
        [rt random 180]
      ]
      tick
    end
    

    在此示例中,马只在其半径 2 的区域中移动。但您可以根据您的模型要求进行更改。

    在第二种方法中,您可以在第一步中使用距离(找到与当前补丁有足够距离的空补丁),在第二步中使用半径(为每匹马分配家庭区域)。

    Move-to one-of patches with [Grass? and not any? other horses with [distance myself < (Zone-Radius + 1)]]
        set home-area patches in-radius Zone-Radius
    

    如果您使用更远的距离来寻找空补丁,您将拥有完全分离的区域。最后,您可以在两个步骤中使用距离:

    Move-to one-of patches with [Grass? and not any? other horses with [distance myself < (Zone-Radius + 1)]]
    
        set home-area patches with [distance myself < Zone-Radius] 
    

    【讨论】:

    • 顺便说一句,我用'让我的谁问家区[set pcolor my-who]'来设置每匹马的家区的pcolor不同:)
    • 感谢您非常详细的回复,请问可以这样做吗? '移动到 [让步] 的补丁之一? =“没有”还是森林? =“是”或公园? =“是”而不是任何? other horses in-radius (Zone-Radius + 1)] set home-area patch in-radius Zone-Radius set color 25' 我仍然有海龟被这些补丁发芽,因为它们只能在具有某些变量的补丁上发芽。我已经输入了代码,但海龟似乎只是在左右移动?感谢您的帮助
    • 可以,我会为此添加一个示例。
    【解决方案3】:

    我只是用另一种方式做到了:

    Breed [Horses horse]
    Horses-own [home-area]
    patches-own [  concession? forest? parks?]
    globals [Zone-Radius]
    to setup
      clear-all
      reset-ticks
      set Zone-Radius 2
    
      ask n-of 500 patches [ set concession? "No" ]
      ask n-of 500 patches[ set forest? "Yes" ]
      ask n-of 500 patches[ set parks? "Yes"]
    
    
    
      let i 0
       while [i < Number-horses] 
       [ 
       ask one-of patches with [(concession? = "No" or forest? = "YES" or parks? = "YES" ) and (not any? horses in-radius (Zone-Radius + 2) )]
         [
           sprout-horses 1 [
           set home-area patches with [distance myself < Zone-Radius]
           let w who
           ask home-area [set pcolor red]
           set color 25  ]
         ]
         set i (i + 1)
         ]
    end 
    
    to go
    
      ask horses [
        ifelse member? patch-ahead 1 home-area [rt random 10 fd 1 ] [rt random 180]
      ]
      tick
    end
    

    如您所见,我使用了while和条件来逐个询问补丁,我可能会弄错,但是当我询问所有n-of Number-of-horses patches with [YourCondition][...]时,我得到了错误的结果并且马之间的距离无效,也许它们是被创建的所有同时,因此在创建一匹马时附近没有马!?我对这些概念不熟悉,可能是错误的。

    这是要求补丁立即创建马匹的代码和视图:

    Breed [Horses horse]
    Horses-own [home-area]
    patches-own [  concession? forest? parks?]
    globals [Zone-Radius]
    to setup
      clear-all
      reset-ticks
      set Zone-Radius 2
    
      ask n-of 500 patches [ set concession? "No" ]
      ask n-of 500 patches[ set forest? "Yes" ]
      ask n-of 500 patches[ set parks? "Yes"]
    
    
    
    
    
       ask n-of number-horses patches with [(concession? = "No" or forest? = "YES" or parks? = "YES" ) and (not any? horses in-radius (Zone-Radius + 2) )]
         [
           sprout-horses 1 [
           set home-area patches with [distance myself < Zone-Radius]
           let w who
           ask home-area [set pcolor red]
           set color 25  ]
         ]
    
    
    end 
    
    to go
    
      ask horses [
        ifelse member? patch-ahead 1 home-area [rt random 10 fd 1 ] [rt random 180]
      ]
      tick
    end
    

    【讨论】:

    • 首先,非常感谢您的帮助。非常感谢。不过,我还有最后一个问题,我正在使用 shapefile 和属性表中的列标题定义我的补丁自己的变量,如下所示:' gis:apply-coverage parks-dataset "PARK" parks? gis:set-drawing-color 104 gis:draw parks-dataset 1 ' 我想我必须换掉你代码中写着:'询问 n-of 500 个补丁 [设置让步? “不” ]?谢谢
    • 欢迎您,是的,您不需要代码的那些部分,因为我需要一些补丁来匹配我需要该代码的条件,但是在您的代码中,您的补丁已经具有属性: )
    • 这似乎正在工作,感谢您的帮助。我只是想知道你能解释一下'(Zone-Radius + 2)'的作用吗?为什么我们将 2 添加到区域半径?谢谢一百万
    • 还有什么是'ifelse成员? patch-ahead 1 home-area ' 到底是做什么的?谢谢一百万
    • 它确保海龟向它移动的下一个补丁是我们定义的 HomeArea 补丁的成员
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多