Traffic Predictor
Model was written in NetLogo 5.0.5
•
Viewed 435 times
•
Downloaded 22 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
globals[result] turtles-own[ high medium low prob-high prob-medium prob-low in-link-list ] to compute-prob[n] let num-neighbors length ([in-link-list] of turtle n) let first-n "-" let second-n "-" let third-n "-" carefully[set first-n (item 0 ([in-link-list] of turtle n))][] carefully[set second-n (item 1 ([in-link-list] of turtle n))][] carefully[set third-n (item 2 ([in-link-list] of turtle n))][] ask turtle n[ ifelse(num-neighbors = 1)[ let high-index 0 foreach["H" "M" "L"][ let first-t ? set prob-high (prob-high + ((retrieve-prob first-n first-t) * (item high-index high))) set high-index (high-index + 1) ] let medium-index 0 foreach["H" "M" "L"][ let first-t ? set prob-medium (prob-medium + ((retrieve-prob first-n first-t) * (item medium-index medium))) set medium-index (medium-index + 1) ] let low-index 0 foreach["H" "M" "L"][ let first-t ? set prob-low (prob-low + ((retrieve-prob first-n first-t) * (item low-index low))) set low-index (low-index + 1) ] ;; for precision purposes set prob-high (precision prob-high 2) set prob-medium (precision prob-medium 2) set prob-low (precision prob-low 2) ] [ ifelse(num-neighbors = 2)[ ;; num-neighbors = 2 let high-index 0 foreach["H" "M" "L"][ let first-t ? foreach["H" "M" "L"][ let second-t ? set prob-high (prob-high + ((retrieve-prob first-n first-t) * (retrieve-prob second-n second-t) * (item high-index high))) set high-index (high-index + 1) ] ] let medium-index 0 foreach["H" "M" "L"][ let first-t ? foreach["H" "M" "L"][ let second-t ? set prob-medium (prob-medium + ((retrieve-prob first-n first-t) * (retrieve-prob second-n second-t) * (item medium-index medium))) set medium-index (medium-index + 1) ] ] let low-index 0 foreach["H" "M" "L"][ let first-t ? foreach["H" "M" "L"][ let second-t ? set prob-low (prob-low + ((retrieve-prob first-n first-t) * (retrieve-prob second-n second-t) * (item low-index low))) set low-index (low-index + 1) ] ] ;; for precision purposes set prob-high (precision prob-high 2) set prob-medium (precision prob-medium 2) set prob-low (precision prob-low 2) ] [ ;; num-neighbors = 3 let high-index 0 foreach["H" "M" "L"][ let first-t ? foreach["H" "M" "L"][ let second-t ? foreach["H" "M" "L"][ let third-t ? set prob-high (prob-high + ((retrieve-prob first-n first-t) * (retrieve-prob second-n second-t) * (retrieve-prob third-n third-t) * (item high-index high))) set high-index (high-index + 1) ] ] ] let medium-index 0 foreach["H" "M" "L"][ let first-t ? foreach["H" "M" "L"][ let second-t ? foreach["H" "M" "L"][ let third-t ? set prob-medium (prob-medium + ((retrieve-prob first-n first-t) * (retrieve-prob second-n second-t) * (retrieve-prob third-n third-t) * (item medium-index medium))) set medium-index (medium-index + 1) ] ] ] let low-index 0 foreach["H" "M" "L"][ let first-t ? foreach["H" "M" "L"][ let second-t ? foreach["H" "M" "L"][ let third-t ? set prob-low (prob-low + ((retrieve-prob first-n first-t) * (retrieve-prob second-n second-t) * (retrieve-prob third-n third-t) * (item low-index low))) set low-index (low-index + 1) ] ] ] ;; for precision purposes set prob-high (precision prob-high 2) set prob-medium (precision prob-medium 2) set prob-low (precision prob-low 2) ] ] ] end to-report retrieve-prob [node traf] if(traf = "H")[ report ([prob-high] of turtle node) ] if(traf = "M")[ report ([prob-medium] of turtle node) ] if(traf = "L")[ report ([prob-low] of turtle node) ] report 0 end to setup ca reset-ticks ask patches[set pcolor 69] setup-nodes setup-links setup-cpt setup-prob end to setup-nodes crt 1[setxy 3 13 set shape "rounded-rectangle" set color blue set label who set label-color black] crt 1[setxy 1 10 set shape "rounded-rectangle" set color blue set label who set label-color black] crt 1[setxy 3 10 set shape "rounded-rectangle" set color blue set label who set label-color black] crt 1[setxy 5 10 set shape "rounded-rectangle" set color blue set label who set label-color black] crt 1[setxy 2 7 set shape "rounded-rectangle" set color blue set label who set label-color black] crt 1[setxy 4 7 set shape "rounded-rectangle" set color blue set label who set label-color black] crt 1[setxy 1 4 set shape "rounded-rectangle" set color blue set label who set label-color black] crt 1[setxy 3 4 set shape "rounded-rectangle" set color blue set label who set label-color black] crt 1[setxy 5 4 set shape "rounded-rectangle" set color blue set label who set label-color black] crt 1[setxy 3 1 set shape "rounded-rectangle" set color blue set label who set label-color black] end to setup-links crt-links 0 1 crt-links 0 3 crt-links 1 2 crt-links 1 4 crt-links 2 4 crt-links 2 5 crt-links 3 2 crt-links 3 5 crt-links 3 8 crt-links 4 5 crt-links 4 6 crt-links 4 8 crt-links 4 9 crt-links 5 6 crt-links 5 7 crt-links 6 9 crt-links 7 9 crt-links 8 7 end ;; for setting up the conditional probability table (CPT) to setup-cpt ask turtles[ ifelse((count in-link-neighbors) != 0)[ set in-link-list sort ([who] of in-link-neighbors) set high n-values (3 ^ (count in-link-neighbors)) [random 100] set medium n-values (3 ^ (count in-link-neighbors)) [random 100] set low n-values (3 ^ (count in-link-neighbors)) [random 100] foreach (n-values (3 ^ (count in-link-neighbors)) [?])[ let sum-item ((item ? high) + (item ? medium) + (item ? low)) set high (replace-item ? high (precision ((item ? high) / sum-item) 2)) set medium (replace-item ? medium (precision ((item ? medium) / sum-item) 2)) set low (replace-item ? low (precision ((item ? low) / sum-item) 2)) set prob-high 0 set prob-medium 0 set prob-low 0 ] ][ set in-link-list 0 set high random 100 set medium random 100 set low random 100 let sum-item (high + medium + low) set high (precision (high / sum-item) 2) set medium (precision (medium / sum-item) 2) set low (precision (low / sum-item) 2) set prob-high high set prob-medium medium set prob-low low ] ] end to crt-links[from-turtle to-turtle] ask turtle from-turtle[create-link-to turtle to-turtle] end to setup-prob compute-prob 1 compute-prob 3 compute-prob 2 compute-prob 4 compute-prob 5 compute-prob 6 compute-prob 8 compute-prob 7 compute-prob 9 end
There is only one version of this model, created about 10 years ago by Larry Lin.
This model does not have any ancestors.
This model does not have any descendants.