【问题标题】:In Netlogo, why are the blue patches not overtaking the orange patches? why is it pulsing?在 Netlogo 中,为什么蓝色补丁没有超过橙色补丁?为什么会跳动?
【发布时间】:2021-10-01 17:35:40
【问题描述】:

我在以前的帖子中已经解决了这个问题,但我遇到了一个新问题。我试图放弃恢复过程。一开始橙色和蓝色的流动很快,但一旦它们相互作用就没有胜利,只是在它们之间一遍又一遍地变化。在代码中,我确定如果一个补丁是橙色并且它看到至少 3 个蓝色,它应该变成蓝色,我没有确定如果一个蓝色补丁被橙色包围它会改变,但是它会发生。这个想法是,在设置时我有 3 种颜色,并带有一些滑块(如果 reforestado >= 3 [如果随机 100

此代码可以复制和粘贴,它应该可以工作,忽略出现的红色补丁。请设置世界的垂直界限。

为什么橙色不输蓝色?

提前致谢。

 patches-own
[bordear
abandono
reforestado
potrerizado
temperatura
humedad
dosel
]
breed [ potreros potrero ]
breed [ bordes borde ]
breed [ bosques bosque ]

to setup
  resize-world 0 90 0 60
  clear-all

  ask patches with [
    pxcor <= 30 and
    pxcor >= min-pxcor and
    pycor <= 60 and
    pycor >= min-pycor ] [
    set pcolor 35
    set temperatura 26.5
    set dosel 1
   set humedad 90.4
  ]
 ;Potrero
  ask patches with [
    pxcor <= 60 and
    pxcor >= 30 and
    pycor <= 60 and
    pycor >= min-pycor ] [
    set pcolor 44
    set temperatura 29
    set dosel 84.3
   set humedad 79.3;
  ]
  ;Borde
  ask patches with [
    pxcor <= 90 and
    pxcor >= 60 and
    pycor <= 60 and
    pycor >= min-pycor ] [
    set pcolor 66
   set temperatura 26.3
   set dosel 85.2
   set humedad 94 ;
  ]
  ;Bosque

 ;se establece la forma de la rana

 ; Se establecen las condiciones de las ranas, tamaño color y lugar de aparicion. La energia sera igual en todas las ranas en el set up.

   create-potreros 50

  [ set size 3        ;; easier to see
    set color yellow
setxy random xcor random ycor
move-to one-of patches with [pcolor = 35]
    set heading random 45 + 45
    set energia 50
 ]   ;; red = not carrying food

 ;Potrero



    reset-ticks
end

to go
  ask potreros [
    if energia < 50 [descansar-potrero]
    if energia >= 50 and energia <= 80 [move-potrero]
    if energia > 80 [ if ticks mod 50 = 0 [reproducirse]]
    set heading random 270
      fd 1
 set energia energia - 2
  morir]

  ask patches [ restauracion ]
  ask patches [ deforestacion ]
  ask patches [abandonacion]
  ask patches [borderizacion]


if ticks >= 500 [stop]
tick
end

to restauracion
  if pcolor = 44 or pcolor = 25 or pcolor = 35[
     set reforestado count neighbors with [pcolor = 66 or pcolor = 75] ]
  if reforestado >= 3 [if random 100 <= 100 [
    set pcolor 75
    set temperatura 24.4 + random 3
    set humedad 91 + random 9
    set dosel 82 + random 5 ]
  ]


end


to deforestacion
  if pcolor = 44 or pcolor = 25 or pcolor = 75 or pcolor = 66 [
     set potrerizado count neighbors with [pcolor = 35] ]
  if potrerizado >= 3 [if random 100 <= 0 [
    set pcolor 35
    set temperatura 22.7 + random 5
    set humedad 84.5 + random 10
    set dosel 0 + random 10]
  ]
end
to abandonacion
  if pcolor = 35 [
     set abandono count neighbors with [pcolor = 44 or pcolor = 25] ]
  if abandono >= 3 [if random 100 <= 50 [
    set pcolor 25
    set temperatura 24.6 + random 8
    set humedad 68 + random 14
    set dosel 79 + random 9]
  ]

end

to borderizacion
  if pcolor = 66 [
     set bordear count neighbors with [pcolor = 44] ]
  if bordear >= 3 [if random 100 <= 50 [
    set temperatura 24 + random 6
    set humedad 80 + random 20
    set dosel 80 + random 5]
]

end

to move-potrero
  ask neighbors in-radius 2
     [if temperatura >= 28.6 or temperatura <= 22.6 or dosel >= 5 or humedad <= 84
      [ set pcolor red
       ;facexy random 30 random 60
      ;fd 5
      ;set energia energia - 10]]
    ;[ask potreros [descansar-potrero]]
  ]]



end

to descansar-potrero
  ifelse pcolor = 35 [
    set energia energia + 6]
  [set energia energia + 1]

end

to reproducirse
  if energia > 80 [ if random 100 > 60 [set energia energia - 70
      hatch 1 [ rt random-float 360 fd 2
      set energia energia / 3]]]
end
  to morir
  if energia <= 1 [die]

end ```

【问题讨论】:

    标签: netlogo patch


    【解决方案1】:

    现在,一旦你的补丁将 abandono 设置为 to abandonacion 中的某个值,除非它们的 pcolor 返回到 35,否则它们永远不会重置它。所以,你有 所有 补丁评估if abandono &gt;=3... 代码。要快速修复以了解我的意思,请将您的 to abandonacion 块更改为:

    to abandonacion
      set abandono 0
      if pcolor = 35 [
        set abandono count neighbors with [pcolor = 44 or pcolor = 25] ]
      if abandono >= 3 [if random 100 <= 50 [
        set pcolor 25
        set temperatura 24.6 + random 8
        set humedad 68 + random 14
        set dosel 79 + random 9]
      ]
      
    end
    

    上面只是在评估abandano 计数之前将abandono 重置为0,以确保所有补丁都开始“新鲜”。还有其他方法可以解决这个问题,但您实际如何处理可能取决于您是否跟踪每个滴答声的abandono 补丁数量。

    【讨论】:

    • 嗨@Luke C,谢谢!对于答案。我认为我应该将每个补丁都设为 0。我正计划制作一个显示比例变化的图表,我不知道,但我不知道这个修复如何产生计数问题。我会及时通知你!
    猜你喜欢
    • 2013-01-07
    • 2011-04-04
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多