NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.
FIND THE CORNERS
LINK THE CORNERS
NetLogo Version: NetLogo 4.0.4
globals [ space-color building-color ] ;; BREEDS USED TO CREATE CAMPUS GRAPH breed [ builders builder ] breed [ waypoints waypoint ] undirected-link-breed [ paths path ] to startup setup end to generate setup display end to setup ca setup-world setup-graph end to setup-world set space-color black set building-color red ask patches [ set pcolor space-color ] let index 0 repeat 10 [ create-builders 1 [ set index ++ index show index ;; magic numbers: ;; 3 x 3 = minimum dimensions of a building chunk ;; 18 x 18 = maximum dimensions of a building chunk let w 3 + random 15 let h 3 + random 15 ;; place the builder randomly, but so that the edges clear the world ;; edge by at least one unit setxy (1 + min-pxcor + random ((world-width - 1 - w)) ) (1 + min-pycor + random ((world-height - 1 - h)) ) ;; orient the builder correctly to start building. ;; builders start in lower left corner of chunk ;; then zigzag left to right, top to bottom set heading 90 let turn 90 repeat h [ repeat w [ set pcolor building-color ; set plabel index jump 1 ] lt turn jump 1 lt turn jump 1 set turn (- turn) ] show index ;; when done, it die die ] ] end to setup-graph let out-corners patches with [ is-open-space? and is-outside-corner? ] ask out-corners [ set pcolor sky ] let in-corners patches with [ is-open-space? and between-ex 2 (count neighbors with [ pcolor = red ] ) 8 and not has-colinear-red-neighbors? and not in-alley? ] ask in-corners [ set pcolor lime ] let corners (patch-set in-corners out-corners) ask corners [ sprout 1 [ set breed waypoints set shape "cross" set color white set size 1.0 set heading 0 ] ] ask waypoints [ let me self ask waypoints with [ who > [ who ] of myself ] [ let you self create-path-with me [ set color pink set thickness .5 ] let head towards me let resolution 2 ;; resolution of corner crossing let tiles (patch-set n-values (resolution * floor distance me) [ patch-at-heading-and-distance head ((? + 1) / resolution ) ] ) ifelse any? tiles with [ ;; NO PART GOES THROUGH A BUILDING is-building? or ;; NO PART PASSES THOUGH ANOTHER waypoint ;; (that is, no overlapping paths!) any? waypoints-here with [ self != me and self != you ] ] [ ask path-with me [ die ] ] [ ask tiles [ ] ; [ set pcolor magenta ] ask path-with me [ set color green set thickness .5 ] ] ] ] ;let mags patches with [ pcolor > 0 and shade-of? pcolor gray ] ;let magsp [ pcolor ] of mags ;let minm min magsp ;let maxm max magsp ;let spanm maxm - minm ;ask mags [ set pcolor scale-color magenta pcolor minm maxm ] end to-report between-ex [ a b c ] report (a < b and b < c) end to-report is-open-space? report ( pcolor != building-color ) end to-report is-building? report ( pcolor = building-color ) end to-report neighbors-that-are-building-parts report ( neighbors with [ is-building? ] ) end to-report is-outside-corner? report ( 1 = count neighbors-that-are-building-parts) end to-report has-colinear-red-neighbors? let rn neighbors-that-are-building-parts if not any? rn [ report false ] if count rn != 3 [ report false ] let spx [pxcor] of rn let spy [pycor] of rn ifelse mean spx = first spx or mean spy = first spy [ report true ] [ report false] end to-report in-alley? let rn neighbors-that-are-building-parts if not any? rn [ report false ] if count rn != 6 [ report false ] if all? patches at-points [ [-1 0][1 0] ] [ is-open-space? ] [ report true ] if all? patches at-points [ [0 -1][0 1] ] [ is-open-space? ] [ report true ] report false end to-report ++ [ value ] report value + 1 end to-report -- [ value ] report value - 1 end
View or download the complete model file (to download: right-click, save-link-as):
-- Download campus-buildings-path-graph --