为Netlogo中的修补程序指定值

为Netlogo中的修补程序指定值,netlogo,Netlogo,我是Netlogo的绝对初学者,使用它来制作与考古学研究相关的模型。我试图模拟两个社区争夺资源,“资源”是不同颜色的斑块。我的问题是-如何为给定的补丁分配“值”?我希望一些补丁比其他补丁更“有价值”(例如蓝色补丁比红色补丁更好),我想知道如何为它们分配数值,将数字视为“物质价值尺度”?正如JenB在上文中所评论的,您可以通过在“补丁程序拥有代码的[]”部分,该部分位于“设置”部分之前的顶部。然后,您可以在“设置”部分声明这些补丁程序的初始值,并在“执行”部分声明读/写值 这里有一个过于简单的例子

我是Netlogo的绝对初学者,使用它来制作与考古学研究相关的模型。我试图模拟两个社区争夺资源,“资源”是不同颜色的斑块。我的问题是-如何为给定的补丁分配“值”?我希望一些补丁比其他补丁更“有价值”(例如蓝色补丁比红色补丁更好),我想知道如何为它们分配数值,将数字视为“物质价值尺度”?

正如JenB在上文中所评论的,您可以通过在“补丁程序拥有代码的[]”部分,该部分位于“设置”部分之前的顶部。然后,您可以在“设置”部分声明这些补丁程序的初始值,并在“执行”部分声明读/写值

这里有一个过于简单的例子

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

我希望这会有所帮助!

您看过NetLogo网站上的教程或NetLogo附带的模型库中的任何模型吗?每个补丁都有自己的变量集。有些是内置的(如
pcolor
用于颜色)还有一些是由建模者用
补丁自己的
声明创建的。非常感谢Wade和JenB!我曾尝试查看库中现有的模型,只是很难准确地理解它们背后和补丁自己背后的原理。Wade完美地解释了这一点!