NetLogo - 如何仅从上到下对补丁进行排序
NetLogo - how to sort patches top-bottom only
我有一个补丁字段指定为 "water"(所有补丁,在 y 轴上低于 0 点,最后一个 "bottom" 除外)。水上面是空气:
set water-top 0
set water patches with [ pycor < 0 and pycor > min-pycor ]
set air patches with [ pycor > water-top ]
他们有一个属性:
patches-own [ heat ]
我希望 "water" 仅从上到下排序。
该模型应该从 "air" 中获取一些 "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*
]
]
感谢您的帮助。我在手册中找不到任何内容,只是需要使用排序方式。
您似乎正在使用 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 补丁
我有一个补丁字段指定为 "water"(所有补丁,在 y 轴上低于 0 点,最后一个 "bottom" 除外)。水上面是空气:
set water-top 0
set water patches with [ pycor < 0 and pycor > min-pycor ]
set air patches with [ pycor > water-top ]
他们有一个属性:
patches-own [ heat ]
我希望 "water" 仅从上到下排序。 该模型应该从 "air" 中获取一些 "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*
]
]
感谢您的帮助。我在手册中找不到任何内容,只是需要使用排序方式。
您似乎正在使用 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 补丁