我正在Netlogo中创建一个检查模型,每个检查员负责n个补丁。也就是说,我需要在每个检查员专属的区域划分世界。
我试过了 设定范围(世界宽度*世界高度/检查员)^ 0.5
但是它们的射程高于预期,它允许一名检查员“入侵”其他检查员的区域,这是不可取的。
答案 0 :(得分:3)
这种方法可能过于复杂,但可能会做你需要的 - 它将世界分成甚至垂直的领域。""请注意,只有当世界的最小xcor为0,并且世界宽度可以被inspectors
的数量整除时,它才能正常工作 - 否则一个检查员的检查区域将与所有其他。例如,使用此设置:
breed [ inspectors inspector ]
inspectors-own [ my-territory ]
to setup
ca
resize-world 0 29 0 29
create-inspectors ninspectors [
set my-territory nobody
]
split
reset-ticks
end
制作列表以存储最小和最大xcor
值,然后使用这些值来分区补丁以将区域指定给不同的检查员。评论中有更多解释:
to split
; get a count of the inspectors
let n count inspectors
; get section widths
let n-xcor ( max-pxcor - min-pxcor ) / n
; build lists to define min-maxes of sections
let n-min ( range min-pxcor max-pxcor n-xcor )
let n-max lput ( max-pxcor + 1 ) n-min
set n-max but-first n-max
; Foreach of the min-max pairs, set patches within
; the min-max boundary be set to the territory of one
; of the inspectors that currently has no territory
( foreach n-min n-max [
[ _min _max ] ->
set _min ceiling _min
set _max ceiling _max
let cur_inspector one-of inspectors with [ my-territory = nobody ]
ask patches with [ pxcor >= _min and pxcor < _max ] [
ask cur_inspector [
ifelse my-territory = nobody [
set my-territory myself
] [
set my-territory ( patch-set my-territory myself )
]
]
set pcolor ( [color] of cur_inspector ) - 2
]
])
; Move inspectors to their territory
ask inspectors [
setxy ( mean [pxcor] of my-territory ) ( mean [pycor] of my-territory )
show my-territory
pd
]
end
要检查它是否正常工作,您可以让检查员四处游荡:
to go
ask inspectors [
face one-of neighbors with [ member? self [my-territory] of myself ]
fd 1
]
tick
end