2

Currently I am working on developing an infrastructure model in NetLogo and I have difficulty making the turtle follow the road. This I do using the gis extension.

The goal of this model is to simulate traffic movement, and for that the cars within the model need to follow the roads. However, the cars do not follow the roads at all when I try to make this work.

to load
  ca
  clear-patches
  show "Wegenbestand laden..."
  set data gis:load-dataset Input_bestand_shp
  show "Wegen geladen"

  show "Data importen..."
  let timing 1
  foreach gis:feature-list-of data
  [[b] -> ask patches gis:intersecting b
    [
    set pspeed gis:property-value b "snelheid"
    set road gis:property-value b "gid"
    set status gis:property-value b "status"
    set a_dir_x gis:property-value b "s_d_x"
    set a_dir_y gis:property-value b "s_d_y"
    set b_dir_x gis:property-value b "e_d_x"
    set b_dir_y gis:property-value b "e_d_y"
    if status = "gesloten" [ set pspeed 0]
    if pspeed = 30 [ set maxdruk Algemene_capaciteit_straat / 5 ]
    if pspeed = 80 [ set maxdruk Algemene_capaciteit_autoweg / 5]
    if pspeed = 130 [ set maxdruk Algemene_capaciteit_snelweg / 5]
    set fid gis:property-value b "did"
    show timing
    set timing (timing + 1)
  ]
  ]

  show "Data geimporteerd"

  ask patches [ set pcolor scale-color blue pspeed 0 130 ]

  set-default-shape turtles "car"

  ;set exp-count 1
  ;set border patches with [ count neighbors != 8 ]
end

to setup
  clear-turtles
  clear-all-plots

  reset-ticks

  setup-turtles
end

to setup-turtles
  ;een turtle is 5 autos
  ask patch Start-X Start-Y
  [sprout Verkeersintensiteit_geslotenweg / 5 [ set color red ]]

  ;1 tick = 1 minute
  ask patches[
    ask turtles-here[
      set speed pspeed / 60
      set currentroad road
      set dir_x b_dir_x
      set dir_y b_dir_y
    ]
  ]
end

to go
  setup-turtles
  ;1 tick = 1 minute
  ask turtles [
      facexy dir_x dir_y
      fd speed
  ]
end

With the above code I first tested to see if any direction would work. However, the cars either randomly stop, go in completely the wrong direction and I do not know what to do.

The input are line segments that are split on vertices. The a_dir_x and the others show the front and back of each segment to give a direction. The coordinate system is WGS 84 UTM 31N.

Another thing that I was considering was to use the move-to function, which should be easier for use. In that case I would require to know the cellsize and I do not know how this is determined in NetLogo.

Does anyone have any ideas or experience with this? Thank you!

here is an image of the interface tab

LuukvGorp
  • 66
  • 5
  • 2
    The problem seemed to lie with the coordinates. Coordinates were not recognized by NetLogo and I had to define the NetLogo coordinates beforehand instead. I did this by creating a set raster with known x columns and y rows and added these as features to the shapefile. This is not optimal so if there are better ways I would still like to know, but this is a way to deal with it. – LuukvGorp Jul 24 '18 at 13:15
  • Okay I found a way to do it. The best way I found was by a move-to function anyway, making the cars move to the end of the road based on the start of the road. Then to get the time I took the length of the road and divided it by the speed, so it still simulates the movement of a car, just by "teleporting". – LuukvGorp Aug 03 '18 at 11:03

0 Answers0