Netlogo将一组补丁分配给一个品种的变量
问题描述:
我对netlogo很陌生,想知道如何设置一组补丁作为某个品种的自变量。举例来说,假设我有:Netlogo将一组补丁分配给一个品种的变量
breed [ buildings building ]
buildings-own [ my-patches ]
我希望能够有一个补丁集(比方说,一个矩形,由一些坐标,以便限制)分配给每个个体建筑的我,补丁场。我将如何做到这一点?
答
欢迎来到Stack Overflow和Netlogo!鉴于您的品种和buildings-own
如上,您可以简单地使用set
来指定patch-set
,你想要一个大厦的my-patches
变量举行。
to setup
ca
ask patches with [ pxcor mod 10 = 0 and pycor mod 10 = 0 ] [
sprout-buildings 1 [
set shape "square"
set heading 0
set size 1.5
set my-patches patches with [
pxcor > [pxcor] of myself - 3 and
pxcor < [pxcor] of myself + 3 and
pycor > [pycor] of myself - 3 and
pycor < [pycor] of myself + 3
]
ask my-patches [
set pcolor [color] of myself - 2
]
]
]
reset-ticks
end
答
你需要知道的第一件事是你不能有补丁品种。虽然你不会说这就是你想要的,但我只是想确保你知道这一点。
看看这段代码。这是一个完整的程序,创建一些乌龟(称为房地产经纪人),并为他们分配一些补丁。然后它将这些补丁变成与房地产经纪人相同的颜色。
breed [realtors realtor]
realtors-own [my-patches]
to setup
clear-all
create-realtors 10
[ setxy random-xcor random-ycor
set size 2
set shape "circle"
set my-patches n-of 5 patches in-radius 3
]
ask realtors [ask my-patches [set pcolor [color] of myself ] ]
reset-ticks
end
您可以通过创建'setup'按钮或在命令中心键入setup来运行它。
谢谢!有没有一种方法可以为每个建筑分配一个唯一的ID? – billybobetbo
不客气!这些建筑物都有一个独特的'who'标识符(尝试'询问建筑物[show who]'),它是根据它们创建的顺序分配的。但是,如果你想更精确地控制xy位置和位置特定的名称,我的答案[这里](https://stackoverflow.com/questions/45361848/netlogo-set-specific-setxy-patern-with-set-number乌龟/ 45362094#45362094)可能适合你。如果您试图表示真实世界的建筑物,您可能需要进入线下的GIS扩展(但这更加复杂并且使用shapefile来分配名称/值)。 –