NetLogo:计算面片集的周长
我正在NetLogo中为领土选择建模,并希望我的海龟们在建立领土后计算其周长。我一直在想办法解决这个问题,但还没有找到一个好办法。有什么想法吗NetLogo:计算面片集的周长,netlogo,Netlogo,我正在NetLogo中为领土选择建模,并希望我的海龟们在建立领土后计算其周长。我一直在想办法解决这个问题,但还没有找到一个好办法。有什么想法吗 提前感谢您的建议 修改了我上次给你的答案: to setup ca ask patches with [pxcor > 0 ] [ set pcolor white ] crt 1 end to go ask turtles [ let blacklist patches with [ pcolor = b
提前感谢您的建议 修改了我上次给你的答案:
to setup
ca
ask patches with [pxcor > 0 ] [
set pcolor white
]
crt 1
end
to go
ask turtles [
let blacklist patches with [ pcolor = black ]
let northpatches patches with [ pycor > 0 ]
let northred ( northpatches with [ member? self blacklist = false ] )
ask northred [ set pcolor red ]
let border northred with [ any? neighbors4 with [ pcolor != red ] ]
ask border [
set pcolor blue
]
print count border
]
end
可以将边界/周界面片指定为具有非区域的邻居的任何区域面片。对您来说,它可能看起来像:
ask turtles [
print count territory with [ any? neighbors4 with [owner != myself ]
]
]
同样,没有您的设置,我无法测试它,因此您必须修改
编辑如下
要计算边界上面片的边缘,可以让它们计算属于另一只海龟的邻域4
。然后,他们可以把它们加到海龟的周长上。例如:
to assess-perimeter ;;; must be called by a turtle
print ("Assessing perimeter")
let current-turtle who
let temp-per-len 0
let border-patches patches with [ owner = current-turtle and any? neighbors4 with [ owner != current-turtle ] ]
show (word "I have " count border-patches " border patches")
ask border-patches [
;; One way to get each border patch to check each of its neighbors
let nobodies 4 - count neighbors4 ;; if any patches are on the edge of the world, returns the number of those edges
let non-territory-edges count neighbors4 with [ owner != current-turtle ]
let border-edges nobodies + non-territory-edges
set temp-per-len temp-per-len + border-edges
]
show (word "My perimeter length: " temp-per-len )
set perimeter-length temp-per-len
end
如果这是在所有海龟都选择了它们的整个活动范围之后,那么这个想法就是每只海龟评估其活动范围的边界。然后,它让每一个边界补丁计算其拥有不同所有者的邻居4
。我使用“temp per len”作为循环中的一个求和变量,然后用它来设置turtles自己的“周长”。完整型号代码,包括设置和定义。注意-您必须下载或复制代码,该模型太大,无法在HTML格式下正常运行
此外,我并没有真正计算以确保这项工作完美无瑕——我做了一个快速的版本并祈祷,但我认为这个想法是有意义的,希望能让你开始。谢谢卢克。自从你上周发帖以来,我一直在考虑这个问题。使用面片计数w/“neighers4 with[owner!=myelf]”的想法使周长计数接近,但并不精确。如果这些面片中有1个拥有>1个相邻面片,那么这仍然只算作1个周长单位(如果有意义的话)。例如,上面Territory 2文本框所指的补丁将是其中一个“Neighers4 with[owner!=我自己]”补丁,在周长距离上增加1个单位的周长,但实际上应该增加2个单位。我仍在尝试确定一种更精确的方法。啊,你试图将面片边界而不是面片作为周长的定义,对吗?我将编辑我的答案以提供可能的解决方案。
to assess-perimeter ;;; must be called by a turtle
print ("Assessing perimeter")
let current-turtle who
let temp-per-len 0
let border-patches patches with [ owner = current-turtle and any? neighbors4 with [ owner != current-turtle ] ]
show (word "I have " count border-patches " border patches")
ask border-patches [
;; One way to get each border patch to check each of its neighbors
let nobodies 4 - count neighbors4 ;; if any patches are on the edge of the world, returns the number of those edges
let non-territory-edges count neighbors4 with [ owner != current-turtle ]
let border-edges nobodies + non-territory-edges
set temp-per-len temp-per-len + border-edges
]
show (word "My perimeter length: " temp-per-len )
set perimeter-length temp-per-len
end