Netlogo 中的 LevelSpace:“滴答计数器尚未启动”错误,但滴答确实已重置

问题描述 投票:0回答:1

我从 NetLogo 中的 LevelSpace 扩展开始。 我的代码有两个版本:一个没有执行我想要的操作,但不会抛出任何错误:另一个按预期执行,但仅针对第一个刻度,而不是抛出 刻度计数器尚未启动。使用重置刻度线。 观察者运行由按钮“go”调用的过程 GO 调用的 TICK 时出错。

这是两段代码(注意这段代码调用的netlogo应用程序绝对没有错误)。

A)不做我想做的事,但至少运行: ` 建立 LS:重置 加州 ls:create-interactive-models number_worlds "FlockingModified.nlogo" ls:询问 ls:模型 [ 设置 ] 重置刻度 结束

去 全部清除 ls:询问 ls:模型 [ 去 ] let number_centroids [计数质心] ls:of ls:models 让 x_centroids [ListXCentroids] ls:of ls:models 让 y_centroids [ListYCentroids] ls:of ls:models 让 header_centroids [ListHeadingCentroids] ls:of ls:models

foreach ls:models[
    i -> let id_world i
    let number_centroid item id_world number_centroids
    let xcoords item id_world x_centroids
    let ycoords item id_world y_centroids
    let headings item id_world heading_centroids
    loop [
        if number_centroid = 0 [stop]
        create-turtles 1 [
            set color 15 + 10 * id_world
            setxy last xcoords last ycoords
            set heading last headings
    ]
    ;this is a home made pop, equivalent to java pop
    set xcoords but-last xcoords
    set ycoords but-last ycoords
    set headings but-last headings
    set number_centroid number_centroid - 1
]

tick

结束

问题是它不会改变id_world。 我尝试了循环版本。模型是通过

let models ls:models
获得的。

loop[
    if empty? models [stop]
    let id_world last models
    let number_centroid item id_world number_centroids
    let xcoords item id_world x_centroids
    let ycoords item id_world y_centroids
    let headings item id_world heading_centroids
    loop [
        if number_centroid = 0 [stop]
        create-turtles 1 [
            set color 15 + 10 * id_world
            last xcoords last ycoords
            set heading last headings
        ]
        ;this is a home made pop, equivalent to java pop
        set xcoords but-last xcoords
        set ycoords but-last ycoords
        set headings but-last headings
        set number_centroid number_centroid - 1
    ]
    ;;it never gets to here
    set models but-last models
]

然后我有 while 版本,它会抛出错误,但达到了我的预期:

let models ls:models
while [not empty? models] [
    let id_world last models
    let number_centroid item id_world number_centroids
    let xcoords item id_world x_centroids
    let ycoords item id_world y_centroids
    let headings item id_world heading_centroids
    while[number_centroid > 0] [
        create-turtles 1 [
            set color 15 + 10 * id_world
            setxy last xcoords last ycoords
            set heading last headings
        ]
        ;this is a home made pop, equivalent to java pop
        set xcoords but-last xcoords
        set ycoords but-last ycoords
        set headings but-last headings
        set number_centroid number_centroid - 1
    ]
    set models but-last models
]
netlogo
1个回答
0
投票

clear-all
还包括
clear-ticks
,它会撤消您的
reset-ticks
,因此在您的
go
中调用它会导致此错误。如果您想要清除某些内容,则必须使用单独的清除命令,例如
clear-turtles
clear-patches
clear-globals

© www.soinside.com 2019 - 2024. All rights reserved.