如何 select 基于 Netlogo 中相同变量值的补丁

How to select patches based on the same variable value in Netlogo

当补丁的一个变量达到某个值(例如age = 75 )时,我将补丁重定向到另一个过程(称为retirement),我想在其中select所有共享相同变量值的补丁 Farm_ID 因此该过程适用于所有补丁。

我正在寻找一个意思是“与”相同的命令,我也考虑过使用 to-reportreport 程序来报告 pxcorpycor 的原始补丁,然后询问与 patch pxcor pycor 具有相同 ID_Farm 的其他补丁 但是我觉得我在使用 Netlogo 的本质上遗漏了一些东西(我是新手)。

to start-simulation
  reset-timer
  tick-advance 70
;; increase the farmer's age
 ask patches with [seed = 1] [set age age + 1]
 
  ask patches [
    if age = 75 [ retirement ]
  ]
;; other stuffs
end

to retirement
   ask patches with [ ID_Farm = ???]
;; procedure to change the variable ID_Farm depending on the closest patches with a different ID_Farm
end 

您需要 myself(参见 here),更具体地说,您需要使用 variable = [variable] of myself

请参阅下面的最小且可重现的示例:

to setup
  clear-all
  
  ask patches [
    ifelse (pxcor > 0)
      [set pcolor lime]
      [set pcolor orange]
  ]
end

to go
  ask one-of patches [
    type "I am the chosen patch. My color is " type (ifelse-value (pcolor = 25) ["orange"] (pcolor = 65) ["lime"] ["cyan"]) print ". I and all patches having my same color will become cyan."    
    operate-on-patches-with-my-same-color
  ]
end

to operate-on-patches-with-my-same-color
  ask patches with [pcolor = [pcolor] of myself] [
    set pcolor cyan
  ]
end

当您检查 NetLogo 词典中的 myself 条目时,请注意 selfmyself 之间的区别。一开始它可能会令人困惑,但随着您越来越习惯 NetLogo 的工作原理,它就会变得清晰。