我尝试创建一个以num-nodes
和clique-size
为主要变量的群集(或村庄)社交网络结构。在我的代码中,我创建了num-nodes / clique-size
个节点,这些节点是集群中的初始节点。之后,我要求这些节点孵化靠近它们的其他节点。但是,由于要求所有节点同时进行填充,因此节点总数将超过num-nodes
变量。因此,我需要节点以顺序方式孵化。我怎样才能做到这一点?我的代码目前看起来像这样:
to create-new-nodes [n]
clear-all
ask patches [ set pcolor white ]
create-nodes n [
set color red
set shape "circle"
]
reset-ticks
end
to setup
clear-all
ask patches [ set pcolor white ]
setup-clusters
reset-ticks
end
to setup-clusters
create-new-nodes (num-nodes / clique-size)
ask nodes [set leader 1]
ring-layout
ask nodes [set groupid groupid + who]
while [count nodes < num-nodes] [
ask turtles with [leader = 1] [ hatch 1 ]]
end
我该怎么办?如果谁&gt; = num-nodes,有没有办法建立[stop]函数?或者,还有更好的方法?
要明确:我希望节点根据它们拥有的groupid顺序孵化。因此,首先一个节点将在组0中孵化,然后在组1中孵化,等等。直到没有更多的乌龟可以孵化,因为count nodes = num-nodes
。这使得它与我的其他问题略有不同。
我将我的代码改写为此,但我收到了错误:
;;ticker is a global variable
to setup-clusters
create-new-nodes (num-nodes / clique-size)
ask nodes [set leader 1]
ring-layout
ask nodes [set groupid groupid + who]
loop [
if count nodes >= num-nodes [stop]
ask n-of 1 nodes with [groupid = ticker] [ hatch 1 [set group-membership groupid ]]
ifelse ticker = (num-nodes / clique-size)
[set ticker 0]
[set ticker ticker + 1]
]
谢谢!