让代理商跟随其邻居,但遇到了错误的“面对预期输入为代理商,但没有任何人。”

发布于 2025-02-04 08:43:33 字数 1323 浏览 3 评论 0原文

如果有任何这样的代理,我会尝试将每个代理转移到其相关代理(由高信任连接和我的视图中定义),否则将代理移至其邻居之一。但是,我遇到了“面对预期输入为代理商,但没有人没有。”而且我不知道该如何解决。我认为使用!=没有人可能导致错误。关于如何解决这个问题有什么建议吗?

这是我的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

来世叙缘 2025-02-11 08:43:33

您对导致错误的原因是正确的
高度汇总的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 be nobody. one-of highlyRelatedPersons however, will be nobody if the agentset is empty, so you could use ifelse (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 and relatedPersons 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 to face one-of relatedPersons, which again causes a crash since relatedPersons is an empty agentset.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文