【问题标题】:NetLogo - how to sort patches top-bottom onlyNetLogo - 如何仅对补丁进行上下排序
【发布时间】:2015-07-30 10:23:51
【问题描述】:

我有一个指定为“水”的补丁字段(所有补丁,在 y 轴上低于 0 点,除了最后一个“底部”)。水面之上是空气:

set water-top 0
set water patches with [ pycor < 0 and pycor > min-pycor ]
set air patches with [ pycor > water-top ]

他们有一个属性:

patches-own [ heat ]

我希望“水”仅从上到下排序。 模型应该从“空气”中获取一些“热量”,并自上而下通过“水”分布,这意味着顶层获得的热量更多,而底层获得的热量更少。

  ask air [ set heat 1 ]
  ask water [ set heat 0 ]
  foreach sort water [  ;; *Sort top-to-bottom needed here*
    ask ? [
      *some heat distributing code*
    ]
  ]

感谢您的帮助。我在手册中找不到任何内容,只是需要使用排序依据。

【问题讨论】:

  • 您发布的代码有什么问题?在我看来是正确的。 sort 确实从上到下排序。
  • 另一种方法可能是使用pycor 进行计算,或者使用pycor 一次循环一行。这是否适合你的情况,我不能说,因为你没有告诉我们你在做什么。

标签: patch netlogo


【解决方案1】:

您似乎正在使用 pycor 作为高度代理,并且您希望热量向下移动?补丁是世界的固定部分——它们不能移动。因此,出于您的目的,它们已经处于正确的排序顺序。你真正想要的是类似的东西(我对你的代码也做了一些小的改动,以便水顶产生效果并且水一直存在到底部和空气中,并添加了颜色,这样你就可以看到改变的目的

set water-top 0
set water patches with [ pycor <= water-top and pycor >= min-pycor ]
set air patches with [ pycor > water-top ]

ask air
[ set color white
  set heat 1
]

ask water
[ set color blue
  set heat calculate-heat (water-top - pycor)
]

to calculate-heat depth
  ; code that converts depth into heat
end

上面的代码将在单个滴答中完成热量分配。如果您希望热量随着时间的推移实际上向下移动,那么您需要将时间投入到您的模型中,并且您需要让补丁以适当的顺序执行某些操作的代码是:

foreach sort-on [- pycor] water
  [ ask ? [ do-something that looks at heat of above patch] ]

以便首先完成最高的 pycor 补丁

【讨论】:

  • 谢谢,这正是我想要的。我会尝试一下。如果成功,我将标记为已回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-06
  • 1970-01-01
  • 1970-01-01
  • 2019-04-10
  • 1970-01-01
相关资源
最近更新 更多