在 Netlogo 中使用刻度
Using Ticks in Netlogo
我想先说明一个事实,即我从未真正学会如何使用 Netlogo 正确编码,我所做的一切都是通过反复试验和在我遇到问题时在这里提出问题。所以如果这是一个愚蠢的问题,我深表歉意!
我目前正在研究一个模型,其中每个刻度等于一天。我有一个特定的动作,我想在特定的刻度(当刻度 = 60、425、790、1155、1520、1855 等时)发生。
我试过这个:
if ticks = [60 425 790 1155 1520 1885]
[
create-hatchlings Hatchling-Release
[ set color 57
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set birth-tick -60]
create-m-hatchlings Hatchling-Release
[ set color 107
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set m-birth-tick -60]
]
使用此代码,什么也不会发生。我能够让事件在正确的时间发生的唯一方法是为每个数字单独编写它,如下所示:
if ticks = 60
[
create-hatchlings Hatchling-Release
[ set color 57
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set birth-tick -60]
create-m-hatchlings Hatchling-Release
[ set color 107
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set m-birth-tick -60]
]
if ticks = 425
[
create-hatchlings Hatchling-Release
[ set color 57
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set birth-tick -60]
create-m-hatchlings Hatchling-Release
[ set color 107
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set m-birth-tick -60]
]
但我最终不得不这样做数百次。有没有更好的写法?
使用member?
检查刻度值是否出现在您的列表中:
if member? ticks [60 425 790 1155 1520 1885]
[
; do something
]
另一方面 - 如果您想在每年的第 60 天做某事,请使用模数 (mod
):
if ticks mod 365 = 60
[
; do something
]
所以你不需要列表。
我想先说明一个事实,即我从未真正学会如何使用 Netlogo 正确编码,我所做的一切都是通过反复试验和在我遇到问题时在这里提出问题。所以如果这是一个愚蠢的问题,我深表歉意!
我目前正在研究一个模型,其中每个刻度等于一天。我有一个特定的动作,我想在特定的刻度(当刻度 = 60、425、790、1155、1520、1855 等时)发生。
我试过这个:
if ticks = [60 425 790 1155 1520 1885]
[
create-hatchlings Hatchling-Release
[ set color 57
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set birth-tick -60]
create-m-hatchlings Hatchling-Release
[ set color 107
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set m-birth-tick -60]
]
使用此代码,什么也不会发生。我能够让事件在正确的时间发生的唯一方法是为每个数字单独编写它,如下所示:
if ticks = 60
[
create-hatchlings Hatchling-Release
[ set color 57
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set birth-tick -60]
create-m-hatchlings Hatchling-Release
[ set color 107
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set m-birth-tick -60]
]
if ticks = 425
[
create-hatchlings Hatchling-Release
[ set color 57
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set birth-tick -60]
create-m-hatchlings Hatchling-Release
[ set color 107
set size 1.5
move-to one-of patches with [ pcolor = cyan ]
set m-birth-tick -60]
]
但我最终不得不这样做数百次。有没有更好的写法?
使用member?
检查刻度值是否出现在您的列表中:
if member? ticks [60 425 790 1155 1520 1885]
[
; do something
]
另一方面 - 如果您想在每年的第 60 天做某事,请使用模数 (mod
):
if ticks mod 365 = 60
[
; do something
]
所以你不需要列表。