我试图将我的代理从我的道路网络的一个顶点移动到另一个代码的另一个顶点。但是,我遇到了一个错误,说搬到预期输入为代理人,但没有任何人。
如果新位置已经定义了哪个代码作为 slocation 的代理的一部分,问题在哪里?
to go
ask citizens [start-movement]
move
end
to start-movement
let nearest-node min-one-of nodes [distance myself]
set slocation nearest-node
move-to slocation
end
to move
ask citizens
[let new-location one-of [link-neighbors] of slocation
move-to new-location
set slocation new-location]
end
这是一个完整的最低工作示例,复制您的代码并添加使其运行所需的设置和繁殖信息。
breed [ citizens citizen ]
citizens-own [slocation]
breed [ nodes node ]
to setup
clear-all
create-nodes 20 [ set color blue setxy random-xcor random-ycor ]
ask nodes [ create-links-with n-of 2 other nodes ]
create-citizens 1 [ set size 3 set color red ]
end
to go
ask citizens [start-movement]
move
end
to start-movement
let nearest-node min-one-of nodes [distance myself]
set slocation nearest-node
move-to slocation
end
to move
ask citizens
[ let new-location one-of [link-neighbors] of slocation
move-to new-location
set slocation new-location
]
end
这很好。正如我在评论中提出的那样,最有可能的问题是您的一个公民碰巧从没有任何链接近脑的节点开始。检查此问题的方法是show count nodes with [not any? link-neighbors]
。错误是说它在链接近骨头集中找不到任何代理。
如果节点仅在那里标记道路,则只需删除任何没有标记道路的任何。如果还有其他节点,那么您需要将您的公民限制在路上的节点。