I want to create a road network from Netlogo using a shapefile. My walkers are supposed to walk on roads to a specific goal. When I call the to go procedure I keep getting the error:
OF expected input to be an agent or agentset but got NOBODY instead.
error while walker 15 running OF
called by procedure GO
called by Button 'go'
My code so far is:
breed [nodes node]
breed [walkers walker]
walkers-own [
origin
myGoal
wlocation
]
to make-road-network
clear-links
let first-node nobody
let previous-node nobody
foreach gis:feature-list-of roads[ polyline ->
foreach gis:vertex-lists-of polyline [ segment ->
foreach segment [coordinate ->
let location gis:location-of coordinate
if not empty? location [
create-nodes 1 [
set color blue
set size 1
set xcor item 0 location
set ycor item 1 location
set hidden? true
if first-node = nobody [
set first-node self
]
if previous-node != nobody [
create-link-with previous-node
]
set previous-node self
]
]
]
set previous-node nobody
]
]
; connect adjacent polylines/roads
ask nodes [ create-links-with other nodes in-radius 0.001 ]
end
to go
ask walkers[
let new-location one-of [link-neighbors] of wlocation ; here I am getting the error
move-to new-location
set wlocation new-location
]
end
to setupWalkers [nWalkers]
sprout-walkers nWalkers [
set color 14
set size 3
set shape "person"
pen-down
set origin Spots
set wlocation one-of nodes
move-to wlocation
]
end
I followed the question (how to create moving turtles out of a shapefile in Netlogo) and used the code.
I could see two possible options for this error. The first possibility is that some nodes are not connected to any other nodes, but I don't know enough about the gis extension to comment on that.
The second possibility is that let new-location one-of [link-neighbors] of wlocation
gives you the link-neighbors of your walker (which returns nobody), instead of the link-neighbors of your wlocation. The easy fix is to use brackets in order to specify whose link-neighbors you are interested in:
let new-location one-of ([link-neighbors] of wlocation)