path-simulator
Model was written in NetLogo 6.0.2
•
Viewed 121 times
•
Downloaded 16 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Info tab cannot be displayed because of an encoding error
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
; define turtles breed [ walkers walker ] ; define turtles and patches specific variables walkers-own [ goal ] patches-own [ popularity streets obstacle ] ; define global (observer) variables globals [ roads visible-routes gini-index-reserve lorenz-points ] ; setup procedure carried out once to setup clear-all set vis-pop false ask patches [ set pcolor green set obstacle 0 set popularity 0 ] ; call the experiment setup procedure make-experiment ; if no experiment is choosen stop if selected-experiment = "none" [ if message [user-message (word "Es wurde kein Szenario gewählt?!\n Zähle jetzt Schafe...")] ask n-of n-walker patches [sprout-walkers 1 [ set color white set size random 10 set shape "sheep" ] ] ] ; finsihed so reset ticks ; if you want to calculate a lorenz curve you need to uncomment this call ;update-lorenz-and-gini reset-ticks end ; procedure that controls the model run ; adapted from the original paths model to go ; for runtime scaling and graying the popularity patches ifelse not vis-pop [ask patches with [popularity >= pop-lowlimit and pcolor != orange and pcolor != red] [set pcolor gray]] [scale-p] ; main procedure that rules the movement move-walkers ; if you want to calculate a lorenz curve you need to uncomment this call ;update-lorenz-and-gini tick ; if you do not want to use the Behavoiur Space you may use the next to calls to dump out result files ;if ticks = 4000 [ ; export-world (word "results/results " behaviorspace-experiment-name behaviorspace-run-number ".csv") ; export-plot "number of patches per percentile" (word "results/results " behaviorspace-experiment-name behaviorspace-run-number "_number-of-patches-per-percentile.csv") ;] end ; procedure that calculate the attraction of a patch ; adapted from the original paths model to become-more-popular set popularity popularity + 1 ; if the increase in popularity takes us above the threshold, become a route ; current threshold is 1 times by a turtle if pcolor != orange [ if obstacle != 1 [ if popularity >= pop-lowlimit [ set pcolor gray ]] ] end ; procedure to control the movement of walkers ; adapted from the original paths model to move-walkers ask walkers [ if patch-here = goal [ if selected-experiment = "s-goal" [set goal one-of patches with [streets = 1] if show-goal [ ask goal [set pcolor yellow] ] ] if selected-experiment ="o-goal" or selected-experiment ="Y" or selected-experiment ="square" or selected-experiment ="houseOfSantaClaus" [set goal one-of patches with [pcolor = orange]] ] walk-towards-goal ] end ; procedure to control the popularity of patches, ; the destination of the next walkes step and the avoidance of obstacles ; adapted from the original paths model to walk-towards-goal ask patch-here [ become-more-popular ] face best-way-to goal avoid-patches end ; procedure that calculate and perfom the decison of the best direction ; adapted from the original paths model to-report best-way-to [ destination ] ; of all the visible route patches (=gray), select the ones ; that would take me closer to my destination let visible-patches patches in-radius walker-vision-dist ;let visible-routes visible-patches with [popularity >= pop-lowlimit] ifelse not max-pop [set visible-routes visible-patches with [ popularity >= pop-lowlimit] ;print "1" ] [set visible-routes visible-patches with-max [ popularity] ] ;print [popularity] of visible-routes let routes-that-take-me-closer visible-routes with [ distance destination < [ distance destination - 1] of myself ] ; decision ifelse any? routes-that-take-me-closer [ ; from those route patches, choose the one that is the closest to me report min-one-of routes-that-take-me-closer [ distance self ] ] [ ; if there are no nearby routes to my destination report destination ] end ; this procedure adapts the forward looking example of obstacles avoidance as presented by ; Vision Cone example of the Netlogo Lib in addition some ideas are taken from ; Thomas Christy at Bangor University 2009 and modified by William John Teahan ; http://files.bookboon.com/ai/index.html ; https://files.bookboon.com/ai/Obstacle-Avoidance-1.html ; found by google search "netlogo obstacle avoidance" page 3 to avoid-patches ; visualisation of cone of sight ; recolor all cone patches to the original colors ; we have to do so because otherwise the last cone will remain ask patches with [pcolor = sky] [ set pcolor green ] ask patches with [pcolor = pink] [ set pcolor red ] ask patches with [pcolor = cyan] [ set pcolor gray ] ; if visualisation of cones ist true ; color the cone depending on the underlying patch classes if vis-vision [ ask patches in-cone walker-vision-dist walker-v-angle [ if pcolor = green [ set pcolor sky ] if pcolor = gray [ set pcolor cyan] if pcolor = red [ set pcolor pink ] ] ] ; start of obstacle avoidance ; count patches in cone that are obstacles if there is at least one obstacle ; turn 12.5 degrees ; do this until there is no obstacle in cone while [count patches in-cone walker-vision-dist walker-v-angle with [obstacle = 1] > 0] [ rt 12.5 ] ; error workaround for touching the boundary of world that produces the "nobody" error ; we just check the patch in front and only if it is not nobody we head on let try one-of patches in-cone walker-vision-dist walker-v-angle with [obstacle != 1] if try != nobody ; turn to one of the patches in the cone WITHOUT (!=1) an obstacle [face one-of patches in-cone walker-vision-dist walker-v-angle with [obstacle != 1]] ; last check if there is no obstacle step 1 forward ; otherwise step 1 backwards and turn 90 deg ifelse [obstacle] of patch-ahead 1 != 1 [fd 1 ] [bk 1 lt 90] end ; ##################################################### ; create experiments ; this procedure creates some static road systems ; road width and geometry typ is defined by the GUI to create-roads if preset-roads = "triangle" [ set roads patches with [pxcor = -20 or pycor = 20 or pycor = pxcor - 2 ] ] if preset-roads = "square" [ set roads patches with [pxcor = -20 or pycor = 20 or pxcor = 20 or pycor = -20] ] if preset-roads = "X" [ set roads patches with [pxcor = pycor or (-1 * pxcor) = pycor ] ] ask roads [ paint-p patches in-radius road-width set pcolor gray ] set roads patches with [pcolor = gray] ask roads[ set popularity roads-pop set streets 1 ] display end ; this procedure creates some static road systems ; geometry is defined by the GUI to make-experiment ; triangle if selected-experiment = "Y" [ ; not rotated ;https://www.triangle-calculator.com/de/?what=vc&a=-40&a1=-40&3dd=3D&a2=0&b=0&b1=29.2825&b2=0&c=40&c1=-40&c2=0&submit=Berechnen&3d=0 ;[-40 -40] [0 29.2825] [40 -40] ;slightly rotated ;https://www.triangle-calculator.com/de/?what=vc&a=-40&a1=-40&3dd=3D&a2=0&b=4&b1=29&b2=0&c=35&c1=-43&c2=0&submit=Berechnen&3d=0 ;recolorize remaining orange patches back to green ask patches with [pcolor = orange] [set pcolor green] ;define goal patches and make them orange ask patches at-points [ [-40 -36] [4 27] [35 -43]] [ set pcolor orange] ; create walkers according to the settings ask n-of n-walker patches [sprout-walkers 1 [ if selected-experiment ="Y" [set goal one-of patches with [pcolor = orange]] set size 5 set color black set shape "stud_tri"] ] ] ; pentagle if selected-experiment = "houseOfSantaClaus" [ ask patches with [pcolor = orange] [set pcolor green] ask patches at-points [[-35 10] [-35 -40] [0 40] [35 10] [35 -40]] [ set pcolor orange] ask n-of n-walker patches [sprout-walkers 1 [ if selected-experiment ="houseOfSantaClaus" [set goal one-of patches with [pcolor = orange]] set size 4 set color 45 set shape "person student"] ] ] ; square if selected-experiment = "square" [ ask patches with [pcolor = orange] [set pcolor green] ask patches at-points [[-35 40] [-35 -40] [35 40] [35 -40]] [ set pcolor orange] ask n-of n-walker patches [sprout-walkers 1 [ if selected-experiment ="square" [set goal one-of patches with [pcolor = orange]] set size 4 set color 45 set shape "person student"] ] ] ; a street szenario is choosen and strets are the only places for goals and turles to be born if selected-experiment = "s-goal" [ if preset-roads != "none" [create-roads ; create walker and goals on structures (roads) ask n-of n-walker roads [ sprout-walkers 1 [ if selected-experiment = "s-goal" [set goal one-of patches with [streets = 1]] if show-goal [ask goal [set pcolor yellow]] set size 4 set color 45 set shape "person student" ] ] ] if preset-roads = "none" [ ask n-of n-walker patches [ sprout-walkers 1 [ set goal one-of patches if show-goal [ask goal [set pcolor yellow]] set size 4 set color 45 set shape "person student" ] ] if message [user-message (word "Es wurden keine vordefinierten Strassen gewählt.\n Bitte JETZT Strassen zeichnen!")] ] ] ; a free goal szenario is choosen (goals MUST be orange) if selected-experiment ="o-goal" [ if preset-roads != "none" [create-roads] ask n-of 4 patches with [pcolor = green][set pcolor orange] ask n-of n-walker patches [sprout-walkers 1 [ if selected-experiment ="o-goal" [set goal one-of patches with [pcolor = orange]] set size 4 set color 45 set shape "person student"] ] if message [user-message (word "Es wurden vier zufällige Ziele erzeugt. \nMit dem draw-world-items Button und der Farbauswahl orange können Weitere Ziele gesetzt werden.\n die Farbauswahl gray bzw. green erzeugt Strassen und Wiesen. ") ] ] end ;######################################################### ; reporter for analysis ; reports number of gray patches to-report trampling report count patches with [popularity >= pop-lowlimit] end ; reports number of patches with the pop-lowlimit value to-report popularity-minimum report count patches with [popularity = pop-lowlimit ] end ; reports teh average popularity value of all patches to-report popularity-average let psum sum [popularity] of patches with [popularity >= pop-lowlimit] let pcount count patches with [popularity >= pop-lowlimit] report psum / pcount end ;reports the maximum value of popularity to-report popularity-maximum let psum sum [popularity] of patches with-max [popularity] let pcount count patches with-max [popularity] report psum / pcount end ; reports the Gini Coefficient to-report gini-05 report gini-index-reserve / trampling end ; calls the help text not implemented yet to help clear-all import-drawing "images/help.png" if user-yes-or-no? "OK?" [ clear-all ] end ;; this procedure recomputes the value of gini-index-reserve ;; and the points in lorenz-points for the Lorenz and Gini-Index plots to update-lorenz-and-gini let sorted-popularity sort [popularity] of patches with [popularity >= pop-lowlimit] let total-popularity sum sorted-popularity let popularity-sum-so-far 0 let index 0 set gini-index-reserve 0 set lorenz-points [] ;; now actually plot the Lorenz curve -- along the way, we also ;; calculate the Gini index. ;; (see the Info tab for a description of the curve and measure) repeat count patches with [popularity >= pop-lowlimit] [ set popularity-sum-so-far (popularity-sum-so-far + item index sorted-popularity) set lorenz-points lput ((popularity-sum-so-far / total-popularity) * 100) lorenz-points ;print lorenz-points set index (index + 1) set gini-index-reserve gini-index-reserve + (index / count patches with [popularity >= pop-lowlimit]) - (popularity-sum-so-far / total-popularity) ] end ; function reports a list of the popuklarity values of all patches >= pop-lowlimit to-report spop report sort [popularity] of patches with [popularity >= pop-lowlimit] end ;; procedure to colorize the popularity ;; a linear approach from lowliomit to current max value is applied to scale-p if ticks > 10 [ let pmax max [popularity] of patches ;if pmax < pop-lowlimit [set pmax pop-lowlimit + pop-lowlimit] ;print pmax ask patches with [pcolor != orange and pcolor != green and pcolor != red] [ set pcolor scale-color magenta popularity pop-lowlimit pmax ] ] end ;######################################################### to paint-p [p] ask p [ set pcolor gray] end ; provides an simple way to draw new facilities to draw-world-items while [mouse-down?] [ create-turtles 1 [ setxy mouse-xcor mouse-ycor ask patches in-radius line-width [ set pcolor read-from-string p_color if pcolor = red [set obstacle 1 set streets 0] if pcolor = gray [set obstacle 0 set streets 1 set popularity roads-pop set popularity roads-pop] if pcolor = green [set obstacle 0 set streets 0 set popularity 0] ] die ] display ] end ; Copyright 2015 Uri Wilensky. ; See Info tab for full copyright and license.
There is only one version of this model, created about 4 years ago by Chris Reudenbach.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
path-simulator.png | preview | Preview for 'path-simulator' | about 4 years ago, by Chris Reudenbach | Download |
This model does not have any ancestors.
This model does not have any descendants.