首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为Net徽标中的修补程序分配值

问为Net徽标中的修补程序分配值
EN

Stack Overflow用户
提问于 2019-10-31 09:25:35
回答 1查看 482关注 0票数 0

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-02 21:54:43

正如上面JenB所评论的,您可以通过在代码的“修补程序本身[]”部分中声明变量,从而为每个修补程序创建一个新变量,该部分位于“安装”部分之前的顶部。然后,您可以在"setup“部分中声明这些值的初始值,在"go”部分中声明读/写值。

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

代码语言:javascript
复制
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

我希望这能帮上忙!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58640199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档