1个补丁中多只海龟的Netlogo植绒模型修改 [英] Netlogo flocking model modification for multiple turtles in 1 patch

查看:50
本文介绍了1个补丁中多只海龟的Netlogo植绒模型修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改 Flocking 模型代码示例,以表示鱼在遇到彼此时形成鱼群(群),然后使用其余代码的逻辑一起移动.不幸的是,坚持这一逻辑要求他们同时占据同一个补丁.问题出现在平均走向同学报告中:

I'm attempting to modify the Flocking model code example to represent fishes forming schools (flocks) when they encounter each other, then move together using the logic of the rest of the code. Unfortunately, adhering to that logic requires them to occupy the same patch at the same time. The problem arises during the average-heading-towards-schoolmates report:

to-report average-heading-towards-schoolmates  ;; turtle procedure

  let x-component mean [sin (towards myself + 180)] of schoolmates
  let y-component mean [cos (towards myself + 180)] of schoolmates
  ifelse x-component = 0 and y-component = 0
    [ report heading ]
    [ report atan x-component y-component ]
end

当最近的同学与向我自己"奔跑的海龟在同一个补丁上时,它会出错,因为没有朝向您的确切位置.我试过添加

When the nearest schoolmate is on the same patch as the turtle running "towards-myself" it gets an error because there is no heading toward your exact location. I've tried adding

set xcor xcor - 0.001

forward 0.001

在代码的前面,所以位置上会有一些差异,但这没有帮助.我希望它做的是,如果它无法决定标题,则调用搜索"协议.

To the front of the code so there would be some disparity in location but it didn't help. What I'd like it to do is if it can't decide on a heading then to invoke the "search" protocol.

任何解决这个难题的创意都将不胜感激!

Any creative ideas for solving this conundrum will be greatly appreciated!

推荐答案

当补丁相同时,您需要进行错误检查.对于您的模型,您需要考虑在代理位于同一补丁中的情况下该怎么做.在下面的代码中,我忽略了它们.

You need to do error-checking for when the patches are the same. For your model, you'll need to consider what to do in the situation when the agents are in the same patch. In the below code, I ignore them.

来自关于towards的文档:

注意:请求从一个代理到它自己的标题,或者一个代理在相同的位置,会导致运行时错误.

Note: asking for the heading from an agent to itself, or an agent on the same location, will cause a runtime error.

to-report average-heading-towards-schoolmates  ;; turtle procedure

  let my-schoolmates schoolmates with [patch-here != [patch-here] of myself]
  ifelse any? my-schoolmates
  [
    let x-component mean [sin (towards myself + 180)] of my-schoolmates
    let y-component mean [cos (towards myself + 180)] of my-schoolmates
    report atan x-component y-component 
  ]
  [report heading]
end

您可能想尝试将同一块上的海龟合并到您的航向计算中:

You may want to try incorporating turtles on the same patch into your heading calculation:

to-report average-heading-towards-schoolmates  ;; turtle procedure

  let x-component mean [ifelse-value patch-here != [patch-here] of myself [0] [sin (towards myself + 180)]] of schoolmates
  let y-component mean [ifelse-value patch-here != [patch-here] of myself [0][cos (towards myself + 180)]] of schoolmates
  ifelse x-component = 0 and y-component = 0
    [ report heading ]
    [ report atan x-component y-component ]
end

这篇关于1个补丁中多只海龟的Netlogo植绒模型修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆