我在 NetLogo 中对领土选择进行建模,海龟选择一个领土中心(“开始补丁”),然后根据补丁的值从那里构建一个领土。海龟在获得新补丁后总是返回起始补丁,然后选择、移动到并获得下一个最有价值的补丁。选择领地后,乌龟知道它拥有哪些斑块,而斑块也知道它们的主人。
最终,一块领土的起点可能并不是真正的地理中心。海龟选择了它的领地后,我如何要求它评估领地、识别地理中心并计算起始块与领地真正中心的接近度? (注:我不想强迫海龟将起始补丁保留在地理中心——它们可以自由选择它们想要的任何补丁。但如果没有一个区域,我可能会强制海龟重新选择一个领土。势均力敌的比赛——否则这些地区的效率不是很高。)
以下是领土起始斑块(黑色星星)不等于地理中心的示例。下面是一些示例代码。有什么建议吗?
patches-own [
benefit ;; ranges 0.1-1 and represents food available in the patch
owner ] ;; patches are owned once selected for a territory
turtles-own [
start-patch ;; the selected center of the territory
sum-value ;; sum of values of patches in my territory
territory-list ;; list of patches I've selected
territory ;; agentset of patches I've selected
established ] ;; true/false, true when has settled in a final territory after assessing geographic center
globals [threshold = 25]
to setup
ask patches [ set owner nobody ]
end
to go
ask turtles [
pick-center
build-territory]
tick
end
to pick-center
if start-patch = 0
[move-to best-center ;; (calculated by a reporter elsewhere as moving windows for a cluster of high-benefit patches)
set start-patch patch-here
set owner self
set territory-list (list patch-here)
set territory (patches with [owner = myself])
]
to build-territory
ifelse sum-value < threshold
[ pick-patch ] ;; keeps picking patches for territory until I've met my threshold
[ assess-geographic-center] ;; once met threshold, assess real center of patch-set
end
to pick-patch
let _destination highest-value ;; (this is calculated by reporters elsewhere based on benefit / travel costs to a patch)
face _destination forward 1
if patch-here = _destination
[ claim-patch _destination ]
end
to claim-patch [_patch]
ask _patch [set owner myself]
set sum-value sum-value + (benefit / (distance start-patch))
set territory-list lput patch-here territory-list
set territory (patch-set territory _patch)
move-to start-patch
end
to assess-geographic-center
;; Once the territory is built, the turtle should identify the actual
;; geographic center of the patch-set it has selected...how to do this?
;; Once it knows the center, the turtle should compare the distance to the original start-patch.
;; If >10 patches away, it will move to that start-patch and start over with selecting a territory....
end
你能只得到所有补丁的平均 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