定义家庭区域 - 乌龟?

时间:2013-12-30 00:44:39

标签: distance netlogo

我对netlogo很新。在我发布之前,我已经在这里搜索了每个问题。

我有以下代码发芽了一定数量的马匹:

  

问一些数字马补丁[草? =“是”]       [sprout-horses 1 [set color 25]]

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

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

据我所知,它与距离函数有关吗?

3 个答案:

答案 0 :(得分:2)

你可以在这里找到一个类似的问题,也有例子:

Spacing agents in NetLogo based on territory size

答案 1 :(得分:1)

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

我不确定你是如何定义草的?每个补丁的变量,但我已经分配了一些草补丁? = true而其他人是假的。 第二步是设置每匹马的家庭区域属性。如果最初你将它们远离彼此移动,它们将具有单独的区域。

我在这里列举了几个例子: 首先在两个步骤中使用 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

enter image description here

在此示例中,匹配仅在半径为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

enter image description here

如果使用更高的距离来查找空补丁,则会有完全分隔的区域。最后,您可以使用两个步骤的距离:

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] 

enter image description here

答案 2 :(得分:0)

我只是采取了另一种方式:

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

enter image description here

正如你所看到的那样,我一个接一个地使用补丁和条件,我可能会弄错,但是当我问所有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

enter image description here