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!