1

我对 Netlogo 很陌生,这是我在论坛上的第一篇文章。我需要创建在栖息地或领土上移动的动物代理组。领土可以重叠。更准确地说,我需要在不同地区移动的男性特工和在其他地区移动的几组女性特工。

这就是我到目前为止所做的。我只为一组女性和一组男性创建了一个领地。那不正是我需要的。

    globals [fragments] 
breed [preys prey] 
breed [femaletigers femaletiger] 
breed [kids kid] 
breed [maletigers maletiger] 

turtles-own 
[ 
  energy 
  age 
  gender 
  territory 
] 

to setup 
  clear-all 
  setup-fragments 
  ;setup-habitats 
  setup-turtles 
  reset-ticks 
end 

to setup-fragments 

  ask patches[set pcolor 67] 
  repeat 50 
  [ 
    ask one-of patches 
    [ 
      set pcolor brown 
      repeat 30 
      [ 
        let a random 360 
        let b random 5 
        ask patch-at-heading-and-distance a b 
        [ 
          ask neighbors [ set pcolor brown] 
          set pcolor brown 
        ] 
      ] 
    ] 
  ] 
end 

to setup-turtles 

  set-default-shape femaletigers "default" ; default shape (dreieck) 
  create-femaletigers 10 
  [ 

  set color red 
  set size 1.5 
  set energy 100 
  set age random 20 
  set gender "female" 
  set territory patches-in-territory patch 10 6 15 
  move-to one-of territory with [pcolor = 67 ] ; tigers start in territory but not on fragmented areas 
  ] 

  set-default-shape maletigers "default" ; default shape (dreieck) 
  create-maletigers 10 
  [ 
  set color blue 
  set size 1.5 
  set energy random 100 
  set age random 20 
  set gender "male" 
  set territory patches-in-territory patch 40 15 10 
  move-to one-of territory with [pcolor = 67 ] ; tigers start in territory but not on fragmented areas 

  ] 


  set-default-shape preys "circle" 
  create-preys 100 
  [ 
  move-to one-of patches with [pcolor = 67] ;preys don't start in fragmented areas 
  set color 114 
  set size 0.75 
  ] 
end 

to-report patches-in-territory [Center rd] 
  let ptr [] 
  ask Center [set ptr patches in-radius 20] 
  report ptr 
end 

我很感激任何帮助。玛丽亚

4

2 回答 2

2

欢迎来到堆栈溢出。在这里发帖时,一般来说,通过将代码限制在演示问题所需的最低限度,您会得到更好的服务(请参阅此处的 MCVE 指南);例如,您可以删除您的to-reportprey品种等,以使您要解决的问题非常明显。

我没有完全遵循您的代码,因为我不确定您的一些总体目标 - 相反,我给出了一个替代示例,希望能说明一种方法来完成您所追求的目标。我将展示一个示例,在这个例子中女性可以重叠的区域,在这个例子中男性不能重叠的区域。使用这些变量和设置:

breed [ femaletigers femaletiger ]
breed [ maletigers maletiger ]

turtles-own [ territory ]
patches-own [ maleclaimed? ]

to setup
  ca  
  ask patches [ 
    set maleclaimed? false
  ]

  create-maletigers 3 [
    set shape "triangle"
    set size 1.5
    move-to one-of patches with [ maleclaimed? = false ]
    pd
    set territory patches in-radius 5 with [ maleclaimed? = false ]
    ask territory [ 
      set maleclaimed? true
    ]
  ]

  create-femaletigers 3 [
    set shape "square"
    setxy random-xcor random-ycor
    pd
    set territory patches in-radius 3 
    hatch 1 + random 3 [
      rt random 360
      fd 1
    ]
  ]

  reset-ticks
end

在设置中,patches-own布尔值指示一个补丁是否已被雄性认领 - 将其设置为 false 以启动,以便雄性在设置其领土时可以检查补丁是否已被认领。老虎然后像你一样建立他们的领地,除了雄性不会从另一个雄性那里选择领地。雌性建立了自己的领地,然后hatch还有一些雌性将分享“母亲”的领土。

要在它们的领地内移动,只需限制海龟,使它们只能移动到它们的领地之一——这是一种方法:

to go  
  ask turtles [
    let target one-of territory in-radius 1.5
    if target != nobody [
      face target
      fd 1
    ]
  ]
  tick
end

如果您想确认海龟是否停留在某个区域内,请运行以下命令:

to territory-check

  ask turtles [
    let col color + 2 + random 3
    ask territory [
      set pcolor col
    ]
  ]    

end
于 2017-09-04T21:27:55.693 回答
0

再次感谢。当老虎繁殖并且我希望他们的孩子创造一个新的领地并且领地不应该重叠时是什么情况?

to move-male

  ask maletigers [
   let target1 one-of territory in-radius 2
   if target1 != nobody [
    face target1
    fd 1]]

end

to reproduce-tiger

  if age >= 48 and any?  maletigers-on  patch-here and pcolor = 67 [
    hatch random 1 + random (5 - 1) [
    set gender one-of [ "male" "female" ]   
    set breed kids
    fd random-float 2 ]]

end

to search-territory-male 

 ask maletigers with [ territory = nobody ] [
    if maleclaimed? = false  [
     set territory patches in-radius 18 with [ maleclaimed? = false ]
     ask territory [ set maleclaimed? true ]]]

end
于 2017-09-20T13:36:33.277 回答