NetLogo:计算面片集的地理中心
我在NetLogo中为领土选择建模,海龟们在这里挑选一个领土中心开始补丁,然后根据补丁的价值从那里构建一个领土。海龟总是在获得一个新补丁后返回起始补丁,然后选择、移动到并获得下一个最有价值的补丁。在选择一个区域后,海龟知道它拥有哪些补丁,补丁也知道它们的主人 最终,一块领土的起始区域可能不会成为真正的地理中心。在海龟选择了它的领地后,我该如何要求它评估领地,确定地理中心,并计算起始斑块与领地真正中心的距离?注意:我不想强迫海龟将起始补丁保留在地理中心,他们可以自由选择任何他们想要的补丁。但我可能会强迫海龟们重新选择一个区域,如果没有一个非常接近的匹配,否则这些区域就不是很有效率 这里有一个例子,说明了领土的起始点黑星并不等于地理中心。下面是一些示例代码。有什么建议吗?提前谢谢!NetLogo:计算面片集的地理中心,netlogo,Netlogo,我在NetLogo中为领土选择建模,海龟们在这里挑选一个领土中心开始补丁,然后根据补丁的价值从那里构建一个领土。海龟总是在获得一个新补丁后返回起始补丁,然后选择、移动到并获得下一个最有价值的补丁。在选择一个区域后,海龟知道它拥有哪些补丁,补丁也知道它们的主人 最终,一块领土的起始区域可能不会成为真正的地理中心。在海龟选择了它的领地后,我该如何要求它评估领地,确定地理中心,并计算起始斑块与领地真正中心的距离?注意:我不想强迫海龟将起始补丁保留在地理中心,他们可以自由选择任何他们想要的补丁。但我可能
你能摆脱所有补丁的pxcor和pycor吗?比如:
to setup
ca
reset-ticks
let n 70
ask one-of patches [
set pcolor red
]
while [ ( count patches with [pcolor = red ] ) < n ] [
ask one-of patches with [ pcolor = red ] [
ask one-of neighbors4 [set pcolor red ]
]
]
let xmean mean [pxcor] of patches with [ pcolor = red ]
print xmean
let ymean mean [pycor] of patches with [ pcolor = red ]
print ymean
ask patch xmean ymean [ set pcolor blue
]
end
根据前面的答案,下面是我的想法。这在我的原始代码的最后一个过程中进行:
to assess-geographic-center
let xmean mean [pxcor] of patches with [ owner = myself ]
let ymean mean [pycor] of patches with [ owner = myself ]
ask patch xmean ymean [ set pcolor black ] ;; make the geographic center visible
let geographic-center patch xmean ymean
let distance-away distance geographic-center ;; the turtle is on its start-patch when assessing this distance
ifelse distance-away <= 5
[ set established true ] ;; turtle is happy if start-patch and geographic-center are approximately equal, territory "established"
[ move-to geographic-center ;; otherwise, turtle moves to geographic-center,
reposition ] ;; and follows a procedure "reposition" to makes this the new start-patch and repick the territory
end
取集合中补丁的平均pxcor和平均pycor?
to assess-geographic-center
let xmean mean [pxcor] of patches with [ owner = myself ]
let ymean mean [pycor] of patches with [ owner = myself ]
ask patch xmean ymean [ set pcolor black ] ;; make the geographic center visible
let geographic-center patch xmean ymean
let distance-away distance geographic-center ;; the turtle is on its start-patch when assessing this distance
ifelse distance-away <= 5
[ set established true ] ;; turtle is happy if start-patch and geographic-center are approximately equal, territory "established"
[ move-to geographic-center ;; otherwise, turtle moves to geographic-center,
reposition ] ;; and follows a procedure "reposition" to makes this the new start-patch and repick the territory
end