I have two types of turtles: shoppers and shops.
I want shoppers to go to the shop that is closest to them based on a real GIS road network. So, I need the shoppers to:
- calculate the distance between them and every shop using the gis road network;
- move to the closest shop using the gis road network and return to their starting point. Please help! Thanks!
Here is the link for the shapefile if it helps: https://wetransfer.com/downloads/af1a09969934851a98af90204531674f20220421103304/213277
extensions [gis
nw]
globals [road-dataset]
breed [Shoppers shopper]
breed [shops shop]
breed [nodes node]
to setup
ca
create-shoppers 500
ask shoppers [setxy random-xcor random-ycor set size 1 set color grey]
create-shops 100
ask shops [setxy random-xcor random-ycor set size 1 set shape "square" set color green]
set road-dataset gis:load-dataset "/Users/amik89/Documents/Roads.shp"
gis:set-world-envelope (gis:envelope-union-of (gis:envelope-of road-dataset))
gis:import-wms-drawing "https://ows.terrestris.de/osm/service?" "EPSG:4326" "OSM-WMS" 1
foreach gis:feature-list-of road-dataset[
i ->
foreach gis:vertex-lists-of i[
j ->
let first-node-point nobody
let previous-node-point nobody
foreach j [
k ->
let location gis:location-of k
if not empty? location [
ifelse any? nodes with [xcor = item 0 location and ycor = item 1 location]
[]
[
create-nodes 1[
set xcor item 0 location
set ycor item 1 location
set size 0.23
set shape "circle"
set color 23
set hidden? true
]
]
;to create links
let node-here (nodes with [xcor = item 0 location and ycor = item 1 location])
ifelse previous-node-point = nobody
[set first-node-point node-here]
[let who-node 0
let who-prev 0
ask node-here
[create-street-with previous-node-point
set who-node who]
ask previous-node-point[
set who-prev who
]
]
set previous-node-point one-of node-here
]]]]
reset-ticks
end