NetLogo:在一个时间段内避免在一个补丁上有太多的甲虫? [英] NetLogo: avoid to have too many beetles on one patch in one time step?

查看:284
本文介绍了NetLogo:在一个时间段内避免在一个补丁上有太多的甲虫?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对我的海龟和我的补丁之间的关系实施一些规则。我的补丁变量是:




  • n_min - 如果有足够的海龟,将pcolor更改为粉红色,将补丁上的黄色海龟改为橙色

  • n_max - 如果有太多的海龟,将pcolor设置为棕色,让所有的海龟避免这个补丁



<我的海龟状态是:黄色(移动) - >橙色(逗留) - >红色(infest)
补丁状态是:
绿色(n_min <然后一个补丁上的橙色海龟数量)
粉红色(橙色海龟数量> n_min和< n_max)
brown(no turtles)



我的问题是如何避免如果他们都同时移动,那么在一个补丁上有更多的n_max海龟,因此被定位到同一个补丁?我如何包括如果你看到有一些橙色/红色,只是继续移动找到另一个补丁?另外,如果我的补丁已经是粉红色,并且n_min!= n_max要求海龟直接将其颜色更改为红色?



非常感谢你!



我的工作示例:

 全局变量[
可用补丁
]


patches-own [
nmax;每片最多的海龟,并改变颜色
nmin;最小数量的海龟更换补丁颜色
n.yellow;在黄色
n.orange的补丁上有多少只海龟一个补丁有多少个橙色(停留)海龟?
]

设置
清除所有
重置ticks
设置补丁
设置-turtles
结束

设置补丁
询问n个n_patches补丁[
set pcolor green
set nmin n_min;可以有多少橙色海龟将贴片设置为粉红色?
set nmax n_max;最大数量的橙色甲虫把补丁变成棕色
]
end

to-turtles
crt n_turtles [
set color yellow
]
end


tick
问海龟用[color = yellow] [;只移动黄龟
move-turtles
]
问补丁[;如果n.orange = nmin,将所有龟变成红色,并将补丁变成粉红色
设置n.orange计数龟 - 这里用[color = orange]
]
end

移动龟龟
;如果颜色=黄色;和n.yellow nmin
; ifelse计数其他海龟 -
;移动到[pcolor = green和n.orange <= nmin]
的一个补丁;如果[n.orange <= nmin]的patch-here [
;设置颜色橙色;不再移动了但是,n.orange应该总是小于nmin!
; ]
设置可用补丁补丁,[pcolor = green和count turtles - 这里用[color = orange] 2]; agentet
ifelse(count other turtles-on available-patch< = nmin);如何在这里更改代码nmin?
[移动到一个可用补丁
设置颜色橙色
请求补丁 - 这里[
设置n.orange计数海龟 - 这里与[color = orange]
]
]
[fd 2]


end

结果:



绿色补丁上的一只乌龟已将其颜色更改为橙​​色,但是我想要2只乌龟(nmin)找到绿色补丁并变成橙色。另外,黄色的海龟在下一步的步骤只是通过[fd 2]移动,ifelse条件不是每个步骤重新运行。



解决方案

这段代码应该可以满足我的需要 - 每个补丁只保留一定数量的海龟,对于每个贴片的特定颜色(nmin,nmax)的龟数量为粉红色和棕色。

  patches-own [
nmax;每片最多的海龟,并改变颜色
nmin;最小数量的龟改变补丁颜色
n.orange;一个补丁有多少个橙色(停留)海龟?
n.red;如何mony侵袭的海龟在补丁?
]

设置
清除所有
安装补丁
设置海龟
重置蜱
结束

设置补丁
请求n个n_patches修补程序[pcolor = black] [
set pcolor green
set nmin n_min;可以有多少橙色海龟将贴片设置为粉红色?
set nmax n_max;最大数量的橙色甲虫把补丁变成棕色
]
end

to-turtles
crt n_turtles [
set color yellow
]
end


;通过时间步长添加海龟和补丁,查看效果
如果ticks mod 5 = 0 [
询问n个1个补丁[pcolor = black] [
set pcolor green
set nmin n_min;可以有多少橙色海龟将贴片设置为粉红色?
set nmax n_max;最大数量的橙色甲虫将补丁变成棕色
]
]

如果ticks mod 3 = 0 [
crt 1 [
设置颜色黄色
]
]

询问海龟与[color = yellow] [;只移动黄龟
move-turtles
]
tick
end

to move-turtles
;指定目标
允许可用补丁(具有[(pcolor = pink和count turtles-here< nmax))的补丁;或
(pcolor = green和count turtles-这里< nmin)]
;只选一个补丁,nmin与self有关

ifelse any?可用补丁;如果有<= nmin,则不工作,那么有nmin + 1
[移动到一个可用补丁
如果pcolor = green [
设置颜色橙色
set n.orange(n.orange + 1)
infest.patch;如果有足够的海龟,将补丁变成粉红色,将海龟变成红色
]
如果pcolor = pink [
设置颜色红色
设置n.red(计数海龟 - 这里与[color = red])
kill.patch
]
]
[fd 1]
end

to infest.patch;如果n.orange = nmin的这个特定补丁
如果n.orange = nmin [
set pcolor pink;补丁
问海龟 - 这里用[color = orange] [
设置颜色红色];海龟
]
end

to kill.patch
如果n.red = nmax [;当这个补丁上的红色turteles是= nmax
set pcolor brown
;问海龟 - 这里用[color = red] [
; $]
]
end


I would like to implement certain rules into relationship between my turtles and my patches. My Patches variables are:

  • n_min - if there is enough turtles, change pcolor to pink, change yellow turtles on patch to orange
  • n_max - if there is too many turtles, set pcolor to brown, let all turtles to avoid this patch

My turtles states are: yellow (move) -> orange (stay) -> red (infest) Patches states are: green (n_min< then number of orange turtles on one patch) pink (number of orange turtles is > n_min and < n_max) brown (no turtles)

My problem is how can I avoid to have more then n_max turtles on one patch if they are all moving at the same time and thus are targeted to same patch? How can I include the condition that "if you see that there are some turtles of color orange/red, just keep moving to find another patch? " Also, if my patch is already pink, and n_min != n_max to ask turtles to directly change its color to red?

Thank you a lot !

my not working example:

globals [
  available-patch
]


patches-own [
  nmax   ; maximum nuber of turtles per patch, and change color
  nmin   ; minimum number of turtles to change patch color
  n.yellow  ; how many turtles are on the patch with yellow
  n.orange  ; how many orange (staying) turtles are on 1 patch?
]

to setup
  clear-all
  reset-ticks
  setup-patches
  setup-turtles
end

to setup-patches
  ask n-of n_patches patches [
    set pcolor green
    set nmin n_min     ; how many orange turtles can be there to set the patch to pink? 
    set nmax n_max     ; max number of orange beetles to turn the patch to brown
  ]
end

to setup-turtles
  crt n_turtles [
    set color yellow
  ]
end

to go
  tick
  ask turtles with [color = yellow ] [   ; move only yellow turtles
    move-turtles
  ]
  ask patches [  ; if n.orange = nmin, turn all turtles to red and turn patch to pink
    set n.orange count turtles-here with [color = orange]
  ] 
end

to move-turtles
   ;  if color = yellow ;and n.yellow < nmin 
   ;ifelse count other turtles-on
;   move-to one-of patches with [pcolor = green and n.orange <= nmin]
;   if [n.orange <= nmin] of patch-here [
;     set color orange  ; not to move anymore. However, the n.orange should be always less then nmin !!
;   ]
   set available-patch patches with [pcolor = green and count turtles-here with [color = orange] < 2] ; agentset 
   ifelse (count other turtles-on available-patch <= nmin) ; how to change the code for nmin here?
     [ move-to one-of available-patch                         
       set color orange
       ask patch-here [
         set n.orange count turtles-here with [color = orange]
       ]
     ]
     [ fd 2 ]


end

Result:

one turtle on the green patch has changed its color to orange, but I wanted 2 turtles (nmin) to find green patch and become orange. Also, the yellow turtles move next time steps just by [fd 2], the "ifelse" condition is not re-run each time step.

解决方案

This code should meet my needs - keep only certain number of turtles per patch, and depending on number of turtles of certain color (nmin, nmax) per patch turn patch to pink and to brown.

patches-own [
  nmax   ; maximum nuber of turtles per patch, and change color
  nmin   ; minimum number of turtles to change patch color
  n.orange  ; how many orange (staying) turtles are on 1 patch?
  n.red     ; how mony infesting turtles are on the patch??
]

to setup
  clear-all 
  setup-patches
  setup-turtles
  reset-ticks
end

to setup-patches
  ask n-of n_patches patches with [pcolor = black][
    set pcolor green
    set nmin n_min     ; how many orange turtles can be there to set the patch to pink? 
    set nmax n_max     ; max number of orange beetles to turn the patch to brown
  ]
end

to setup-turtles
  crt n_turtles [
    set color yellow
  ]
end

to go 
   ; add turtles and patches by time steps, to see the effect 
  if ticks mod 5 = 0 [
    ask n-of 1 patches with [pcolor = black][
       set pcolor green
       set nmin n_min     ; how many orange turtles can be there to set the patch to pink? 
       set nmax n_max     ; max number of orange beetles to turn the patch to brown
     ]
    ]

  if ticks mod 3 = 0 [
    crt 1 [
      set color yellow
    ]
  ] 

  ask turtles with [color = yellow ] [   ; move only yellow turtles
    move-turtles
  ]
  tick 
end

to move-turtles       
    ; specify the target
    let available-patches (patches with [(pcolor = pink and count turtles-here < nmax) or   ; 
                                         (pcolor = green and count turtles-here < nmin)] )
    ; select only one patch, nmin is related to "self"

   ifelse any? available-patches ; don't work if there is <= nmin, then there are nmin + 1
     [ move-to one-of available-patches
       if pcolor = green [
         set color orange
         set n.orange (n.orange + 1)
         infest.patch   ; if there is enough turtles, turn patch to pink, turn turtles to red
       ]
       if pcolor = pink [
         set color red
         set n.red (count turtles-here with [color = red])
         kill.patch
       ]
       ]
     [ fd 1 ]
end

to infest.patch   ; change color of patch only if there is n.orange = nmin of this specific patch 
  if n.orange = nmin [
     set pcolor pink  ; patch
     ask turtles-here with [color = orange] [
        set color red ]; turtles
  ]
end

to kill.patch
  if n.red = nmax [      ; turn patch brown when red turteles on this patch are = nmax
    set pcolor brown
;    ask turtles-here with [color = red] [
;      die ]
  ]
end

这篇关于NetLogo:在一个时间段内避免在一个补丁上有太多的甲虫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆