BlackBox
No preview image
Model was written in NetLogo 5.0.4
•
Viewed 252 times
•
Downloaded 36 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
;; BlackBox Simulation: Krishna, Jaehyuk, Sanna ;; 0 = black = 0 ;; 4 = gray = 1 ;; 105 = blue = 2 ;; 125 = magenta = 3 ;; 85 = cyan = 4 ;; 55 = green = 5 ;; 15 = red = 6 ;; 25 = orange = 7 ;; 137 pink = 8 ;; 139.9 = white = 9 globals [ColorList Quad3Matrix Quad4Matrix Quad2Matrix NQuad2Matrix matrixlist Q1self Q1neighbor Q4t Q3t] extensions [matrix rnd] patches-own[] to setup clear-all set ColorList [0 4 105 125 85 55 15 25 137 139.9] set matrixlist [0 1 2 3 4 5 6 7 8 9] ask patches [set pcolor (item (random 10) ColorList)] set-label let i 12 let j 10 while [i < 18] [ while [j < 20] [ ifelse random 2 = 1 [ask patch i j [set pcolor 139.9]][ask patch i j [set pcolor 0]] set j (j + 1) ] set j 10 set i (i + 1) ] setmatrices set Q1self [.99 .99 .813 .705 .652 .610 .545 .537 .507 .5] set Q1neighbor .499 set-label reset-ticks end to set-label ask patches [ if pcolor = 0 [set plabel "0" set plabel-color 139.9] if pcolor = 4 [set plabel "1" set plabel-color 0] if pcolor = 105 [set plabel "2" set plabel-color 0] if pcolor = 125 [set plabel "3" set plabel-color 0] if pcolor = 85 [set plabel "4" set plabel-color 0] if pcolor = 55 [set plabel "5" set plabel-color 0] if pcolor = 15 [set plabel "6" set plabel-color 0] if pcolor = 25 [set plabel "7" set plabel-color 0] if pcolor = 137 [set plabel "8" set plabel-color 0] if pcolor = 139.9 [set plabel "9" set plabel-color 0] ] end to setmatrices set Quad4Matrix matrix:from-row-list [ [1 0 0 0 0 0 0 0 0 0] [.4 0 .1 .05 .1 .05 .1 .05 .1 .05] [.55 0 0 0 .15 0 .15 0 .15 0] [.4 .05 .1 0 .1 .05 .1 .05 .1 .05] [.55 0 .15 0 0 0 .15 0 .15 0] [.5 0 0 0 0 .5 0 0 0 0] [.55 0 .15 0 .15 0 0 0 .15 0] [.4 .05 .1 .05 .1 .05 .1 0 .1 .05] [.55 0 .15 0 .15 0 .15 0 0 0] [.4 .05 .1 .05 .1 .05 .1 .05 .1 0] ] ; set Quad4Matrix matrix:times-scalar Quad4Matrix .9 ; foreach [1 2 3 4 5 6 7 8 9] [matrix:set Quad4Matrix ? ? (1 - sum(matrix:get-row Quad4Matrix ?))] ; matrix:set Quad4Matrix 0 0 1 set Quad3Matrix matrix:from-row-list [ [1 0 0 0 0 0 0 0 0 0] [.71 0 .07 .05 .04 .03 .05 .02 .01 .02] [.58 0 0 0 .25 0 .06 0 .11 0] [.55 .03 .06 0 .03 .01 .07 .01 .05 .19] [.6 0 .07 0 0 0 .25 0 .08 0] [.5 0 0 0 0 .5 0 0 0 0] [.77 0 .09 0 .09 0 0 0 .05 0] [.52 .05 .09 .01 .07 .03 .01 0 .09 .13] [.55 0 .16 0 .19 0 .1 0 0 0] [.56 .12 .02 .02 .07 .01 .09 .03 .08 0] ] set Quad2Matrix matrix:from-row-list [ [1 0 0 0 0 0 0 0 0 0] [.4 0 .1 .05 .1 .05 .1 .05 .1 .05] [.55 0 0 0 .15 0 .15 0 .15 0] [.4 .05 .1 0 .1 .05 .1 .05 .1 .05] [.55 0 .15 0 0 0 .15 0 .15 0] [.5 0 0 0 0 .5 0 0 0 0] [.55 0 .15 0 .15 0 0 0 .15 0] [.4 .05 .1 .05 .1 .05 .1 0 .1 .05] [.55 0 .15 0 .15 0 .15 0 0 0] [.4 .05 .1 .05 .1 .05 .1 .05 .1 0] ] set NQuad2Matrix matrix:from-row-list [ [1 0 0 0 0 0 0 0 0 0] [0 0 .17 .08 .17 .08 .17 .08 .17 .08] [0 0 0 0 .33 0 .33 0 .33 0] [0 .08 .17 0 .17 .08 .17 .08 .17 .08] [0 0 .33 0 0 0 .33 0 .33 0] [0 0 0 0 0 1 0 0 0 0] [0 0 .33 0 .33 0 0 0 .33 0] [0 .08 .17 .08 .17 .08 .17 0 .17 .08] [0 0 .33 0 .33 0 .33 0 0 0] [0 .08 .17 .08 .17 .08 .17 .08 .17 0] ] end to go ask one-of patches with [pxcor > 9 and pycor < 10][set pcolor quad4] UpdateQ4 ask one-of patches with [pxcor < 10 and pycor < 10] [set pcolor quad3] UpdateQ3 ask one-of patches with [pxcor < 10 and pycor > 9] [set pcolor quad1] ask one-of patches with [pxcor > 9 and pycor > 9] [set pcolor quad2] if sum([pcolor] of patches with [pxcor > 9 and pycor < 10]) = 0 [set Q4t ticks] if sum([pcolor] of patches with [pxcor < 10 and pycor < 10]) = 0 [set Q3t ticks] set-label tick end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to UpdateQ4 foreach matrixlist [ if (count patches with [pcolor = (item ? colorlist) and pxcor > 9 and pycor < 10]) = 0 [ matrix:set-column Quad4Matrix ? [0 0 0 0 0 0 0 0 0 0] foreach matrixlist [ let temp ? let sums (1 / sum(matrix:get-row Quad4Matrix temp)) matrix:set-row Quad4Matrix temp (map [? * sums] (matrix:get-row Quad4Matrix temp)) ] ] ] end to-report quad4 report item (rnd:weighted-one-of (n-values length (ColorList) [ ? ]) [ item ? (matrix:get-row (Quad4Matrix) (position pcolor colorlist)) ]) ColorList end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to UpdateQ3 foreach matrixlist [ if (count patches with [pcolor = (item ? colorlist) and pxcor > 9 and pycor < 10]) = 0 [ matrix:set-column Quad3Matrix ? [0 0 0 0 0 0 0 0 0 0] foreach matrixlist [ let temp ? let sums (1 / sum(matrix:get-row Quad3Matrix temp)) matrix:set-row Quad3Matrix temp (map [? * sums] (matrix:get-row Quad3Matrix temp)) ] ] ] end to-report quad3 report item (rnd:weighted-one-of (n-values length (ColorList) [ ? ]) [ item ? (matrix:get-row Quad3Matrix (position pcolor colorlist)) ]) ColorList end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to-report quad1 let CTP [0 0 0 0 0 0 0 0 0 0] ;;; temp list for updating let temp (position pcolor colorlist) ;;; finds color number set CTP replace-item temp CTP ((item temp Q1self) + (item temp CTP)) ;; updates temp list with self prob ask neighbors with [pycor > 9 and pxcor < 10] ;; does it for neighbors [ set temp (position pcolor colorlist) set CTP replace-item temp CTP (Q1neighbor + (item temp CTP)) ] let btemp 8 - (count neighbors with [pycor > 9 and pxcor < 10]) ;; finds extra neighbors set CTP replace-item 0 CTP ( btemp * Q1neighbor + (item 0 CTP)) ;; udpates extra black patches let temp2 max(CTP) let temp3 position temp2 CTP report (item temp3 colorlist) end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to-report quad2 if pxcor = 18 [ if (pcolor = 0) [report 0] let tempx pxcor let tempy pycor ifelse (([pcolor] of patch (tempx - 1) tempy = 139.9) and ([pcolor] of patch (tempx - 2) tempy = 139.9)) [report (item (10 - (position pcolor colorlist)) colorlist)] [ifelse random 10 = 0 [report 0][report (item (10 - (position pcolor colorlist)) colorlist)]] ] if (pxcor = 10 or pxcor = 11 ) [ report item (rnd:weighted-one-of (n-values length (ColorList) [ ? ]) [ item ? (matrix:get-row Quad2Matrix (position pcolor colorlist)) ]) ColorList ] if pxcor = 19 [ let tempx pxcor let tempy pycor ifelse (([pcolor] of patch (tempx - 1) tempy = 139.9) and ([pcolor] of patch (tempx - 2) tempy = 139.9)) [ report item (rnd:weighted-one-of (n-values length (ColorList) [ ? ]) [item ? (matrix:get-row NQuad2Matrix (position pcolor colorlist)) ]) ColorList ] [ report item (rnd:weighted-one-of (n-values length (ColorList) [ ? ]) [item ? (matrix:get-row Quad2Matrix (position pcolor colorlist)) ]) ColorList ] ] if pxcor > 11 or pxcor < 18 [ report 139.9 ; let tempx pxcor ; let tempy pxcor ; ; ifelse (([pcolor] of patch (tempx - 1) tempy = 139.9) and ([pcolor] of patch (tempx - 2) tempy = 139.9)) ; [ ; if pcolor = 139.9 [report 139.9] ; if pcolor = 0 [ ifelse random 2 = 1 [report 0][report 139.9]] ; ] ; [ ; if pcolor = 0 [ ifelse random 2 = 1 [report 0][report 139.9]] ; if pcolor = 139.9 [ ifelse random 2 = 1 [report 0][report 139.9]] ; ] ] end
There are 6 versions of this model.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.