Fadhlin Azmi
Fadhlin Azmi

Reputation: 1

I can't moving the turtle

I'm just starting in netlogo to create an agent-based model. I've got 2 shapefiles, and I want to make my turtle move on my network map. For now I have only can managed to load the shapefiles in my model. Could someone give me an idea how to move the turtle on my network map?

Here is my code so far:

extensions [gis]
breed [cars car]
turtles-own [destination]
globals [
  states-dataset 
  car-blue]

to custom-clear
  reset-ticks
  clear-turtles
  clear-patches
  clear-drawing
  clear-all-plots
end

to setup
  clear-all
  custom-clear
  ask patches [set pcolor green - 3]
  set states-dataset gis:load-dataset "C:/Users/ADMIN/Documents/QGIS/Export Netlogo/Format .shp/state.shp"

  gis:set-world-envelope gis:envelope-of states-dataset
  gis:set-drawing-color yellow
  gis:draw states-dataset 1

  set route-car-blue gis:load-dataset     "C:/Users/ADMIN/Desktop/routefiles/Shapefile/car/route-car-blue.shp"
  gis:set-drawing-color blue
  gis:draw angkot-permatabiru 1.5

  foreach gis:feature-list-of route-car-blue
  [car-pb -> let location gis:location-of gis:centroid-of car-pb
   create-turtles 5 [
    set xcor item 0 location
    set ycor item 1 location
    set shape "car"
    set size 1
  ]]
end

to go
  ask turtles [
  let new-location one-of [link-neighbors] of destination
  move-to new-location
  set destination new-location]
  tick
end

Does anybody know to fix my code? I want to make my turtle move based on my network map.

Upvotes: 0

Views: 35

Answers (1)

LeirsW
LeirsW

Reputation: 2305

The problem is probably in the circularity of your destination and new-location. You define new-location as being a link-neighbor of your destination, but since you don't have a destination yet, this new-location is set to nobody. You then set your destination to be your new-location, which also sets destination to nobody, ending up in a circle where no movement is happening.

The fix for this would be to define a destination for each turtle during setup

Upvotes: 1

Related Questions