让代理商跟随其邻居,但遇到了错误的“面对预期输入为代理商,但没有任何人。”
如果有任何这样的代理,我会尝试将每个代理转移到其相关代理(由高信任连接和我的视图中定义),否则将代理移至其邻居之一。但是,我遇到了“面对预期输入为代理商,但没有人没有。”而且我不知道该如何解决。我认为使用!=没有人可能导致错误。关于如何解决这个问题有什么建议吗?
这是我的代码:
breed [ persons a-person ]
undirected-link-breed [ connections connection ]
connections-own [ trust ]
persons-own [ neighbours ]
to setup
clear-all
create-persons 10
[ setxy random-xcor random-ycor ]
setup-connections
reset-ticks
end
to setup-connections
ask persons
[
create-connections-with other persons
[ set trust 0.6 ]
]
end
to go
setNeighbours
movePersons
tick
end
to setNeighbours
ask persons [ set neighbours other persons in-cone 4 360 ]
end
to movePersons
ask persons
[
let highlyRelatedPersons (turtle-set [other-end] of my-out-connections with [trust = 0.6]) in-cone 4 360
let relatedPersons (turtle-set [other-end] of my-out-connections with [trust = 0.6])
ifelse any? highlyRelatedPersons
[
face one-of highlyRelatedPersons
]
[
let weaklyRelatedNeighbour one-of neighbours with [not member? self highlyRelatedPersons] ;select one of my neighbours that is not a highlyRelatedPerson
ifelse weaklyRelatedNeighbour != nobody
[
face weaklyRelatedNeighbour
]
[
face one-of relatedPersons
]
]
]
end
I try to move each agents to its related agents (defined by high trust connection and in my view) if there are any such agents, and else move the agent to one of its neighbours. However, I get the error "FACE expected input to be an agent but got NOBODY instead." and I don't know how to solve it. I think the use != nobody might cause the error. Any suggestions on how to solve this?
This is my code:
breed [ persons a-person ]
undirected-link-breed [ connections connection ]
connections-own [ trust ]
persons-own [ neighbours ]
to setup
clear-all
create-persons 10
[ setxy random-xcor random-ycor ]
setup-connections
reset-ticks
end
to setup-connections
ask persons
[
create-connections-with other persons
[ set trust 0.6 ]
]
end
to go
setNeighbours
movePersons
tick
end
to setNeighbours
ask persons [ set neighbours other persons in-cone 4 360 ]
end
to movePersons
ask persons
[
let highlyRelatedPersons (turtle-set [other-end] of my-out-connections with [trust = 0.6]) in-cone 4 360
let relatedPersons (turtle-set [other-end] of my-out-connections with [trust = 0.6])
ifelse any? highlyRelatedPersons
[
face one-of highlyRelatedPersons
]
[
let weaklyRelatedNeighbour one-of neighbours with [not member? self highlyRelatedPersons] ;select one of my neighbours that is not a highlyRelatedPerson
ifelse weaklyRelatedNeighbour != nobody
[
face weaklyRelatedNeighbour
]
[
face one-of relatedPersons
]
]
]
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对导致错误的原因是正确的
高度汇总的Persons
是一个代理,虽然代理可以是空的,但代理永远不可能是。
高度列出的persons
但是,如果代理是空的,将是没有人,因此您可以使用ifelse(一个高度汇总的Persepersons!= nose)
> 。也就是说,只需通过使用
任何一个?
是否有?高度汇编的personson
您的代码也从未真正创建
高度列出的Personson
和相关人员
始终为空的任何链接。这意味着代码将始终在第一个IFELSE上返回false,然后转到第二个。通常,大多数海龟都会有他们可以面对的邻居,但是有时没有邻居,因此他们尝试面对一个相关人员
,这再次导致崩溃。You are correct in what is causing the error
highlyRelatedPersons
is an agentset and while an agentset can be empty, an agentset can never benobody
.one-of highlyRelatedPersons
however, will benobody
if the agentset is empty, so you could useifelse (one-of highlyRelatedPersons != nobody)
.That said, is easier to just check if the agentset is empty by using
any?
:ifelse any? highlyRelatedPersons
Your code also never actually creates any links for
highlyRelatedPersons
andrelatedPersons
is always empty. This means that the code will always return false on the first ifelse and move on to the second. Generally most turtles will have neighbours they can face, but sometimes there are none so they try toface one-of relatedPersons
, which again causes a crash sincerelatedPersons
is an empty agentset.