问题描述
我正在尝试将代理商从道路网络的一个顶点移动到以下代码的另一个顶点.但是,我遇到了一个错误,说 MOVE-TO希望输入是代理,但没有提示.
I am trying to move my agents from one vertex of my road network to another one which the following code. However, I got an error, saying that MOVE-TO expected input to be an agent but got NOBODY instead.
如果已经定义了新位置,那么该代码作为 slocation 代理集的一部分,问题出在哪里?
If new location is already defined which this code as part of the agentset of slocation, where is the problem?
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
推荐答案
下面是一个完整的最小工作示例,它复制了代码,并添加了使其运行所需的设置和繁殖信息.
Here is a complete minimum working example copying your code and adding the setup and breed information required to make it run.
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]
.错误是因为它在链接邻居集中找不到任何代理.
This works fine. As I suggested in my comment, the most likely problem is that one of your citizens happened to start at a node without any link-neighbors. The way to check this is show count nodes with [not any? link-neighbors]
. The error is saying that it couldn't find any agents in the set of link-neighbors.
如果仅在此处标记道路的节点,则只需删除未标记道路的任何节点.如果还存在其他节点,则需要将公民限制在道路路口的节点上.
If the nodes are only there to mark roads, then simply delete any that aren't marking roads. If there are other nodes as well, then you need to restrict your citizens to nodes that are road waypoints.
这篇关于在节点中移动代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!