Netlogo 海龟变量注册未按预期工作
我正在制作一个模型,计算所有海龟的每一次互动,并将它们显示在显示器上。 我的代码可以正常工作,除非没有达到预期效果。我得到了太多的变量注册 我对Netlogo有点缺乏经验。我已经用尽可能少和多的海龟测试了我的代码,但是变量注册似乎发生在所有海龟的每个刻度上,而不管它们的位置如何Netlogo 海龟变量注册未按预期工作,netlogo,Netlogo,我正在制作一个模型,计算所有海龟的每一次互动,并将它们显示在显示器上。 我的代码可以正常工作,除非没有达到预期效果。我得到了太多的变量注册 我对Netlogo有点缺乏经验。我已经用尽可能少和多的海龟测试了我的代码,但是变量注册似乎发生在所有海龟的每个刻度上,而不管它们的位置如何 to interact ask citizens with [alerted?] [ if any? citizens in-radius 3 with [panicked?] [ set
to interact
ask citizens with [alerted?] [
if any? citizens in-radius 3 with [panicked?]
[ set mood mood - 20
set total-contagions total-contagions + 1]
if any? citizens in-radius 3 with [calm?]
[ set mood mood + 10
set total-contagions total-contagions + 1]
if any? citizens in-radius 3 with [alerted?]
[ set mood mood - 1
set total-contagions total-contagions + 1]
]
ask citizens with [calm?] [
if any? citizens in-radius 3 with [alerted?]
[set mood mood - 5
set total-contagions total-contagions + 1 ]
if any? citizens in-radius 3 with [panicked?]
[set mood mood - 15
set total-contagions total-contagions + 1 ]
if any? citizens in-radius 3 with [calm?]
[set mood mood + 5
set total-contagions total-contagions + 1]
]
ask citizens with [panicked?] [
if any? citizens in-radius 3 with [panicked?]
[ set mood mood - 3
set total-contagions total-contagions + 1 ]
if any? citizens in-radius 3 with [alerted?]
[ set total-contagions total-contagions + 1 ]
if any? citizens in-radius 3 with [calm?]
[ set total-contagions total-contagions + 1 ]
]
end
我需要实现的是,在模拟过程中,每一次交互都算作一次,而不是多次。此外,我需要只在海龟彼此非常接近的时候才计算每一次互动。好的,问题是你增加了每个街区的传染。从评论中看你的例子,一个惊慌失措,一个冷静,一个警觉,三人会面。以警惕的海龟为例(代码的第一部分):
- 第一个测试:是的,附近有一个恐慌的人群,所以情绪会发生变化,传染病也会增加
- 第二个测试:是的,附近也很平静,所以情绪会发生变化,传染病再次增加
- 第三个测试:是的,附近(自身)有一个警报,所以传染再次增加
(如果有)?其他公民…
因为包括other
将自己排除在测试之外
第二个修正实际上是一个逻辑问题,而不是编码问题,您需要计算出您真正想要计算的数值。想象一下,在半径3内有一个警报公民和其他几个公民。如果这些亲密的公民中有些人感到恐慌,有些人感到平静,你希望发生什么?目前,情绪发生了两个变化,我想这就是你额外注册的地方。为了帮助理解这个问题,在这种情况下,我需要每个海龟的变量相互接触,以改变。假设有三只海龟,一只警惕,一只惊慌,一只平静,它们彼此接触。在“警惕”海龟的例子中,如果所有海龟同时相遇,我需要它的情绪降低10(-20+10)。在“惊慌失措”的海龟的情况下,它的情绪不会改变,因为其他两只海龟(冷静和警觉)不会影响它的情绪。当这三个变量同时出现时,我需要将“总传染”变量增加3。我希望这是有道理的。谢谢你的回答!虽然我没有完全解决我的问题,但它帮助我在可接受的水平上解决了这个问题,并继续我的模型的其余部分。祝您有个美好的一天。