Netlogo:观察者上下文问题
在为特定补丁运行两个完全相同的过程时,两者中的一个正在说明错误,因为“它不能在观察者上下文中运行,它是一个补丁/乌龟上下文”。
to start
ask patches with [seed = 1 AND age = retirement-age] [retirement]
ask patches with [seed = 1 AND age = death] [successor]
end
退休-age
是接口的输入。
死亡
是一个补丁属性,我尝试了start
过程,以及接口的输入。
使用其他程序中创建的列表,退休和死亡程序只是彼此之间的复制。结果只有不同,请参见下文:
to retirement
;;; other calculations same as successor procedure
ifelse (successor-result = 1) [set age 35 ] [set over-retirement 1]
end
to successor
;;; other calculations same as retirement procedure
ifelse (successor-result = 1) [set age 18] [dispatch-parcels]
end
运行退休过程不会造成错误,但是后继过程确实会产生错误。
我没有复制所有内容,因为我认为它没有有用因为两个过程完全相同。其他计算使用在观察者上下文中其他过程中创建的全局变量和列表。
此处是dispatch-parcels
从一开始就相关补丁程序的过程。
to dispatch-parcels
;; this regards the patches with seed = 1 that has been processed in the successor procedure. But doesn't work as for updating the age and death of the agent
set seed 0
set age 0
set death 0
;; if there is no successor, the parcels of the farm are distributed along the closest parcels : one farm can distribute its own parcels to multiple different farms
ask patches with [ ID-farm = [ID-farm] of myself]
;; for each parcel, finds the closest parcel and use the ID-farm as the new ID-farm, same for the region in case it changes.
[
set ID-farm ([ID-farm] of (min-one-of patches with [(ID-farm != 0) AND (ID-farm != [ID-farm] of myself)] [distance myself] ))
set region ([region] of (min-one-of patches with [(region != 0) AND (region != [region] of myself)] [distance myself] ))
]
end
我还尝试使用与退休
过程相同的最终命令行进行连续
过程,但我收到了相同的错误消息。因此,有关此后继
过程的某个地方应该有一些“隐藏”的东西。
关于可能的错误来源的任何洞察力,我应该更加关注什么?
感谢您的时间。
When running two exact same procedures for specific patches, one of the two is stating an error because "it cannot be run in observer context, it is a patches/turtles context only".
to start
ask patches with [seed = 1 AND age = retirement-age] [retirement]
ask patches with [seed = 1 AND age = death] [successor]
end
The retirement-age
is an input from the interface.
The death
is a patch property, I tried the start
procedure as well with an input from the interface.
The retirement and death procedure are just a copy-paste of each other, using lists created in other procedures. Only the result is different, see below :
to retirement
;;; other calculations same as successor procedure
ifelse (successor-result = 1) [set age 35 ] [set over-retirement 1]
end
to successor
;;; other calculations same as retirement procedure
ifelse (successor-result = 1) [set age 18] [dispatch-parcels]
end
Running the retirement procedure do not create error, but the successor procedure does create an error.
I did not copy-paste everything because I don't think it is useful as the two procedure are exactly the same. The other calculations use global variables and lists created in other procedures in the observer context.
Here-below is the dispatch-parcels
procedure that regards to concerned patches from the beginning.
to dispatch-parcels
;; this regards the patches with seed = 1 that has been processed in the successor procedure. But doesn't work as for updating the age and death of the agent
set seed 0
set age 0
set death 0
;; if there is no successor, the parcels of the farm are distributed along the closest parcels : one farm can distribute its own parcels to multiple different farms
ask patches with [ ID-farm = [ID-farm] of myself]
;; for each parcel, finds the closest parcel and use the ID-farm as the new ID-farm, same for the region in case it changes.
[
set ID-farm ([ID-farm] of (min-one-of patches with [(ID-farm != 0) AND (ID-farm != [ID-farm] of myself)] [distance myself] ))
set region ([region] of (min-one-of patches with [(region != 0) AND (region != [region] of myself)] [distance myself] ))
]
end
I also tried to the successor
procedure with the same final command line as from the retirement
procedure but I get the same error message. So there should be something "hidden" somewhere about this successor
procedure.
Any insight about the likely source of error, what I should more attention to ?
Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于弄清楚了什么问题。很明显,它变得不可见,我有点尴尬。
无论如何,我想分享我的答案,因为它可能会睁开像我这样疲倦的初学者的眼睛。
为了测试我的代码的这一部分,我创建了一个按钮以测试
observer
上下文中的后继过程,而我编写的命令是不可能的。就是这样。I finally figured out what was wrong. It was so obvious that it became invisible and I'm a bit embarrased.
I'd like to share my answer anyway because it might opened the eyes of tired beginners like me.
In order to test this part of my code, I created a button to only test the successor procedure, which was in
observer
context, which was not possible with the commands I wrote. That's just it.