Traffic Light Coordinator
Model was written in NetLogo 5.0.5
•
Viewed 464 times
•
Downloaded 31 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
turtles-own[ traffic ] links-own[ reward ] to setup ca reset-ticks ask patches[set pcolor 69] setup-nodes setup-links setup-initial-traffic compute-link-reward color-nodes-label-links end to go ask turtle 0[dpop] color-nodes-label-links tick end ;; procedure to perform dpop to dpop ;; do not allow changes to node 0 initial traffic level if(who != 0)[ ;; traffic release level before modifying - will store best traffic level after foreach loop below let best-traffic traffic ;; sum of reward before modifying - will store best sum of neighbor links reward after foreach loop below let best-sum-n-reward sum-neighbor-link-reward ;; change values of traffic release level for node and find best traffic for node ("myopic" view) foreach["high" "medium" "low"][ if(? != best-traffic)[ set traffic ? compute-link-reward if(sum-neighbor-link-reward < best-sum-n-reward)[ ;; revert set traffic best-traffic compute-link-reward ] ] ] ] ask out-link-neighbors[dpop] end ;; similar to procedure - but a "myopic" version (only reports sum of reward of links with node's vision) to-report sum-neighbor-link-reward let own-who who let sum-n 0 ask links[ if([who] of end1 = own-who) or ([who] of end2 = own-who)[ set sum-n (sum-n + reward) ] ] report sum-n end ;; sum of all link rewards to-report sum-link-reward report (sum [reward] of links) end to color-nodes-label-links ;; color nodes ask turtles[ if(traffic = "high")[ set color red ] if(traffic = "medium")[ set color yellow ] if(traffic = "low")[ set color green ] ] ;; label links ask links[ set label reward set label-color black ] end ;; compute the rewards for all links - calls return-reward procedure to compute-link-reward ask links[ ;; get the traffic at start and end node of link and call return-reward ask links[set reward (return-reward ([traffic] of end1) ([traffic] of end2))] ] end ;; calculate the reward given the traffic release of a start and end node to-report return-reward[start-traffic end-traffic] ;; reassign int value to start-traffic if(start-traffic = "high")[ set start-traffic 3 ] if(start-traffic = "medium")[ set start-traffic 2 ] if(start-traffic = "low")[ set start-traffic 1 ] ;; reassign int value to end-traffic if(end-traffic = "high")[ set end-traffic 3 ] if(end-traffic = "medium")[ set end-traffic 2 ] if(end-traffic = "low")[ set end-traffic 1 ] ;; best scenario - highest reward if(start-traffic = end-traffic)[ report 10 ] ;; worse scenario (undercapacity at end node) - has higher negative reward than "start-traffic < end-traffic" (overcapacity at end node) if(start-traffic > end-traffic)[ report (((end-traffic - start-traffic) * 2) - 1) ] ;; overcapacity at end node scenario if(start-traffic < end-traffic)[ report ((start-traffic - end-traffic) * 2) ] ;; if nothing report 0 end to setup-initial-traffic ;; convert traffic-release-list from string to list format let tr-list read-from-string traffic-release-list ;; index let index 0 foreach tr-list[ ask turtle index[ set traffic ? ] set index (index + 1) ] end to setup-nodes crt 1[setxy 3 13 set shape "rounded-rectangle" set label who set label-color black] crt 1[setxy 1 10 set shape "rounded-rectangle" set label who set label-color black] crt 1[setxy 3 10 set shape "rounded-rectangle" set label who set label-color black] crt 1[setxy 5 10 set shape "rounded-rectangle" set label who set label-color black] crt 1[setxy 2 7 set shape "rounded-rectangle" set label who set label-color black] crt 1[setxy 4 7 set shape "rounded-rectangle" set label who set label-color black] crt 1[setxy 1 4 set shape "rounded-rectangle" set label who set label-color black] crt 1[setxy 3 4 set shape "rounded-rectangle" set label who set label-color black] crt 1[setxy 5 4 set shape "rounded-rectangle" set label who set label-color black] crt 1[setxy 3 1 set shape "rounded-rectangle" 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 to crt-links[from-turtle to-turtle] ask turtle from-turtle[create-link-to turtle to-turtle] 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.