为 Netlogo 中的补丁分配值

Assigning values to patches in Netlogo

我是 Netlogo 的初学者,我用它来制作与考古学研究相关的模型。我正在尝试模拟 2 个社区竞争资源,"resources" 是不同颜色的补丁。我的问题是 - 如何为给定的补丁分配 "value"?我希望一些补丁比其他补丁 "valuable" 多(例如蓝色补丁比红色补丁更好),我想知道如何为它们分配数值,将数字视为 "materialistic value scale"?

正如 JenB 在上面评论的那样,您可以通过在代码的 "patches-own []" 部分中声明变量来为每个补丁创建一个具有值的新变量,该变量位于 "setup" 之前的顶部部分。然后,您可以在 "setup" 部分中声明这些值的初始值,并在 "go" 部分中声明 read/write 值。

;;这是一个过于简单的例子

patches-own [ my-value ]  ;; Give every patch a place to store a new variable
                          ;; which we will name "my-value"
to setup
clear-all   

print "---------------- starting a new run ---------------" ;; if you want to see this  
;; do whatever you do
;; let's create some patches and set various patch colors ("pcolor")

  ask N-of 100 patches [set pcolor red]
  ask N-of 100 patches [set pcolor blue]

;; After they are created you should initialize the values of my-value
;;   or you could get sloppy and trust they will always initialize to zero

;; If there are lots of different colors there are nicer ways to do this
;; but if it's just red and blue we could simply do the following.  We will
;; give blue patches a value of 500 and red patches a value of 300

ask patches [
   if pcolor = blue [set my-value 500]
   if pcolor = red  [set my-value 300]
]
; ... whatever else you have in setup
reset-ticks   
end

;; Then your go section can just refer to these values the same way as you refer to
;; patch colors (pcolor). Say you just want a count of high values of "my-value"

to go
  if (ticks > 5) [   ;; or whatever your stopping condition is
    print "------- time has run out, stopping the run! ----"
    print " "
    stop
  ]    ;; just so this won't run forever

 ;... whatever

   type "the count of patches with my-values > 300 is now " 
   print count patches with [my-value > 300] 

;... whatever 
; For this example, let's change some random blue patch from blue to red
; and as we do that, set my-value to an appropriate value

  ask n-of 1 patches with [pcolor = blue][
    set pcolor red 
    set my-value 300
  ]

tick   
end

希望对您有所帮助!