提问人:user22570245 提问时间:11/5/2023 最后编辑:user22570245 更新时间:11/7/2023 访问量:63
如何从列表中只选择一个要运行的项目?
How to choose only one of the item to run from a list?
问:
我正在研究一个模型来模拟开发模型。现在,我的代码中返回了一个棘手的问题:
to develop
grow-population
ask patches with [pcolor = grey][ask neighbors [set potential (potential + one-of [1 -1])]]
ask patches [ set new-potential (potential + sum [potential] of neighbors4) / 5 + one-of [1 -1] ]
ask patches [ set potential new-potential
set development_patch patches with
[potential > threshold and urban? = 0 and fitness = 1 and population > 5]
if any? development_patch
[let selected_patch one-of development_patch
ask selected_patch [set urban? 1
set land-use "Urban"
set pcolor blue
]
]
]
tick
end
我随机选择了一个项目来运行,但结果显示它运行了一堆项目。那么,我应该如何让其中一个补丁(selected_patch)在每个刻度中改变颜色?谢谢。
答:
2赞
LeirsW
11/6/2023
#1
您的问题源于在通话中选择您的项目。这意味着每个补丁都会选择一个必须变为蓝色的补丁。将语句移到括号外可以解决您的问题ask patches[...]
ask patches [
set potential new-potential
set development_patch patches with [potential > threshold and urban? = 0 and fitness = 1 and population > 5]
]
if any? development_patch [
let selected_patch one-of development_patch
ask selected_patch [
set urban? 1
set land-use "Urban"
set pcolor blue
]
]
评论
0赞
user22570245
11/6/2023
嗨,莱尔斯,感谢您的回复。奇怪的是,我按照你说的做了,出现了另一个问题“蜱虫不能在补丁/上下文中使用,因为蜱虫是观察者”。我该如何解决这个问题?
0赞
LeirsW
11/6/2023
@user22570245 development_patch是一个变量?从你的代码外观来看,它假设它应该是一个变量,但如果它是一个特定于补丁的变量,Netlogo 会认为开发过程是一个不能有patches-own
global
tick
0赞
user22570245
11/7/2023
嗨,Leirs,是的,所有变量都是补丁自己的。我删除了全局变量的development_patch,然后它起作用了!
0赞
user22570245
11/7/2023
嗨,Leirs,我想设置一个排序 paches 的首选顺序,在上面之前添加新代码,如下所示: ask patches with [pcolor = grey][ask neighbors [set neighbors [set potential (potential + one-of [1 -1])]] ask patches [ set new-potential (potential + sum [potential] of neighbors4) / 5 + one-of [1 -1] ] .因此,有了这个,“潜力”现在有一个顺序,如果 neighbor4 中有一个灰色的 pcolor,这意味着这是首选项,并且潜在值会更高。我的目的是先用蓝色填充 pcolor,如果它与灰色相邻,然后是其他颜色。你能帮我怎么做吗?
0赞
LeirsW
11/7/2023
我不完全确定你在这里的目标是什么。您想将多个补丁染成蓝色吗?
评论