我正在努力根据补丁的属性识别扩展的邻域。我需要能够首先识别出存在龟的补丁,然后确定4个邻居是否有海龟,然后是邻居的邻居是否有海龟等等......直到达到补丁的阈值。我非常感谢任何指导/帮助。
这是我现在的代码:
'集群'是代表乌龟补丁的代理集 '集群环'表示与原始补丁的距离(就相邻补丁的环而言) Cluster-ID是集群中心补丁的ID号。
ask clusters [if any? turtles-here
[ask neighbors4
[set pcolor orange - 3
set cluster? TRUE
set cluster-ID [cluster-ID] of myself
set cluster-ring 2
]]]
ask clusters with [cluster-ring = 2][if any? turtles-here
[ask neighbors4
[set pcolor orange - 5
set cluster? TRUE
set cluster-ID [cluster-ID] of myself
set cluster-ring [cluster-ring] of myself + 1
]]]
答案 0 :(得分:2)
我不确定您的设置是什么样的,但我认为这是您需要的一种方法。它的工作原理如下(一旦世界分散了海龟):
neighbors4
也存在海龟(此处的程序名称为cluster-node-find
)。在这个例子中,我称它们为节点,我随机选择从5开始。接下来,请求这些节点:
cluster?
设为true
cluster-ID
cluster-ring
值设置为0(因为它们是指环的“中心”)选择节点后,使用一个过程来扩展集群,每次调用它时外环会增加一个(我在这里称之为build-cluster
)。因此,请将cluster?
设置为true
且没有任何neighbors4
而没有乌龟的neighbors4
的任何补丁发送给:
cluster?
:true
设为cluster-ID
cluster-ring
cluster-ID
值设置为要求补丁的build-cluster
+ 1 反复运行setup
程序,观察群集向外生长,停留在龟存在的位置。
显然,您可能需要根据最初设置群集的方式对其进行修改,但可能会让您指出如何向外构建群集。请参阅下面的完整程序,了解其工作原理 - 使用patches-own [ cluster? cluster-ID cluster-ring ]
to setup
ca
ask patches [
set pcolor 103
set cluster? false
set cluster-ID -999
set cluster-ring -999
]
ask n-of ( round count patches * 0.75) patches [
sprout 1 [
set shape "circle"
set size 0.5
set color white
]
]
cluster-node-find
reset-ticks
end
to cluster-node-find
let potential-clusters n-of 5 patches with [
cluster? = false and
any? turtles-here and
not any? neighbors4 with [ not any? turtles-here ]
]
ask potential-clusters [
set pcolor red + 4
set cluster? true
set cluster-ID random 10000
set cluster-ring 0
ask turtles-here [
set color black
]
]
end
按钮调用此块:
build-cluster
然后,如果你希望看到它们长大到最后,请为此to build-cluster
let cluster-members patches with [
cluster? and
not any? neighbors4 with [ not any? turtles-here ]
]
ask cluster-members [
ask neighbors4 with [ cluster? = false and any? turtles-here ] [
set pcolor [pcolor] of myself - 0.25
set cluster? true
set cluster-ID [cluster-ID] of myself
set cluster-ring ( [cluster-ring] of myself + 1 )
]
]
tick
end
创建一个永久按钮:
let cluster-members patches with [
cluster? and
not any? neighbors4 with [ not any? turtles-here ]
]
修改强>
根据以下评论中的问题:
以下是输出:
build-cluster
在let cluster-members patches with [
cluster? and
any? neighbors4 with [ any? turtles-here ]
]
程序中。
如果您改为使用:
neighbors4
没有限制,群集需要通过其var el = $('body').find('div#my-div.main');
el.html('');
el.append($("<p>If $ax^2+bx+c=0$ with $a≠0$, then:$$x={-b±√{b^2-4ac}}/{2a}$$</p>"));
上存在龟的补丁扩展其前沿。因此,群集进一步扩展,唯一的差距将是不存在海龟的地方(假设海龟密度足够高):