Move agents in nodes

2019-08-03 23:44发布

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.

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

1条回答
小情绪 Triste *
2楼-- · 2019-08-04 00:14

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

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.

查看更多
登录 后发表回答