-
-
Save qiemem/b59f3657bea34b9aa67648760b9c7471 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extensions [ gis nw ] | |
globals [ roads-dataset ] | |
breed [ nodes node ] | |
breed [ persons person ] | |
persons-own [ | |
current-location | |
destination | |
mypath | |
node-here | |
] | |
nodes-own [ | |
road-type | |
myneighbours | |
] | |
to setup | |
clear-all | |
reset-ticks | |
ask patches [ set pcolor white ] | |
;gis:load-coordinate-system (word "/Applications/NetLogo 6.0.1/map data/Westminster.prj") | |
set roads-dataset gis:load-dataset "Road_links.shp" | |
gis:set-world-envelope gis:envelope-of roads-dataset | |
;gis:set-drawing-color black | |
;gis:draw boundary-dataset 0 | |
;gis:draw roads-dataset 0.5 | |
foreach gis:feature-list-of roads-dataset [ vector-feature -> | |
foreach gis:vertex-lists-of vector-feature [ vertex -> | |
let previous-turtle nobody | |
foreach vertex [point -> | |
let location gis:location-of point | |
if not empty? location | |
[ | |
let x item 0 location | |
let y item 1 location | |
let current-node one-of (turtles-on patch x y) with [ xcor = x and ycor = y ] | |
if current-node = nobody [ | |
create-nodes 1 [ | |
setxy x y | |
set shape "circle" | |
set size 0.5 | |
set road-type "road" | |
set hidden? true | |
set current-node self | |
] | |
] | |
ask current-node [ | |
if is-turtle? previous-turtle [ | |
create-link-with previous-turtle | |
] | |
set previous-turtle self | |
] | |
] | |
] | |
] | |
] | |
set-default-shape persons "circle" | |
create-persons initial-number-of-persons | |
[ | |
set color red | |
set size 1 | |
set-location | |
] | |
end | |
to go | |
ask persons [ | |
if destination = 0 or destination = current-location [ | |
select-destination | |
] | |
move | |
] | |
tick | |
end | |
to set-location | |
set current-location min-one-of nodes [ distance myself ] | |
end | |
to select-destination | |
set destination one-of [ nodes with [ | |
road-type = "road" and | |
is-number? [ nw:distance-to myself ] of myself | |
] ] of current-location | |
end | |
to move | |
if current-location != destination [ | |
let next-node item 1 [ nw:turtles-on-path-to [ destination ] of myself ] of current-location | |
set current-location next-node | |
move-to current-location | |
] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment