📄 aaa---sotl.nlogo
字号:
to clear-accidents if crash? [ ask patches with [accident?] [ set pcolor white set accident? false ] ]end;; set the turtles' speed based on whether they are at a red traffic light or the speed of the;; turtle (if any) on the patch in front of themto set-car-speed ;; turtle procedure ifelse (pcolor = red) or (pcolor = yellow) [ set speed 0 ] [ if intersection?[ if ((random 100) < prob-turn)[ turn-car ] ] ifelse v-car?[ ifelse SE-car? [ set-speed 0 -1 ] ;S [ set-speed 0 1 ] ;N ][ ifelse SE-car? [ set-speed 1 0 ] ;E [ set-speed -1 0 ] ;w ] ]end;; set the speed variable of the turtle to an appropriate value (not exceeding the;; speed limit) based on whether there are turtles on the patch in front of the turtleto set-speed [delta-x delta-y] ;; turtle procedure locals [ up-cars?-ahead turtles-ahead ] ;; get the turtles on the patch in front of the turtle ask patch-at delta-x delta-y [ set turtles-ahead turtles-here ] ;; if there are turtles in front of the turtle, slow down ;; otherwise, speed up ifelse any? turtles-ahead [ set up-cars?-ahead values-from turtles-ahead [v-car?] ifelse member? v-car? up-cars?-ahead and member? (not v-car?) up-cars?-ahead [ if not crash? [ set speed 0 ] ] [ set speed speed-of one-of turtles-ahead slow-down ] ] [ speed-up ]end;; decrease the speed of the turtleto slow-down ;; turtle procedure ifelse speed <= 0 ;;if speed < 0 [ set speed 0 ] [ set speed speed - acceleration ]end;; increase the speed of the turtleto speed-up ;; turtle procedure ifelse speed >= speed-limit ;;should be >= if speed should not go above 1... [ set speed speed-limit ] [ set speed speed + acceleration ]end;; set the color of the turtle to a different color based on how fast the turtle is movingto set-car-color ;; turtle procedure ifelse speed < (speed-limit / 2) [ set color blue ] [ set color cyan - 2 ]end;; changes direction of car at intersectionto turn-car ;; turtle procedure slow-down ;;setxy (int xcor) (int ycor) ifelse v-car?[ ifelse eastbound? [set SE-car? true set heading 90 ] ;->E [set SE-car? false set heading 270 ] ;->W ][ ifelse southbound? [set SE-car? true set heading 180 ] ;->S [set SE-car? false set heading 0 ] ;->N ] set v-car? (not v-car?)end;; keep track of the number of stopped turtles and the amount of time a turtle has been stopped ;; if its speed is 0to record-data ;; turtle procedure ifelse speed = 0 [ set num-cars-stopped num-cars-stopped + 1 set wait-time wait-time + 1 ] [ set wait-time 0 ]end;; crash any turtles at the same intersection going in different directionsto crash-cars ask intersections with [any? turtles-here with [v-car?] and any? turtles-here with [not v-car?]] [ set accident? true set pcolor orange ]end;; add the new information from this pass thru the go procedure to the HubNet liststo update-list-info set num-cars-stopped (100 * num-cars-stopped / number) set wait-data lput (mean values-from turtles [wait-time]) wait-data set stopped-data lput num-cars-stopped stopped-data set speed-data lput (mean values-from turtles [speed]) speed-data set cars-data lput (count turtles) cars-data set time-data lput clock time-data set wait-avgs replace-item (clock mod avg-range) wait-avgs (mean values-from turtles [wait-time]) set stopped-avgs replace-item (clock mod avg-range) stopped-avgs (num-cars-stopped) set speed-avgs replace-item (clock mod avg-range) speed-avgs (mean values-from turtles [speed]) end;; plot the data from this pass thru the go procedureto do-plotting set-current-plot "% Stopped Cars" set-current-plot-pen "default" plot num-cars-stopped set-current-plot-pen "avg" plot mean stopped-avgs ;plot mean filter [(position ? reverse stopped-data) < avg-range] stopped-data set-current-plot-pen "global" plot mean stopped-data set-current-plot "Average Wait Time of Cars" set-current-plot-pen "default" plot mean values-from turtles [wait-time] set-current-plot-pen "avg" ;plot mean filter [(position ? reverse wait-data) < avg-range] wait-data plot mean wait-avgs set-current-plot-pen "global" plot mean wait-data set-current-plot "Average Speed of Cars" set-current-plot-pen "default" plot mean values-from turtles [speed] set-current-plot-pen "avg" ;plot mean filter [(position ? reverse speed-data) < avg-range] speed-data plot mean speed-avgs set-current-plot-pen "global" plot mean speed-data set-current-plot "Number of Cars" set-current-plot-pen "default" plot count turtles set-current-plot-pen "global" plot mean cars-data endto plot-new-value [name-of-plot value] set-current-plot name-of-plot plot valueendto clear-plots-and-plot-in-new-plot [name-of-plot list-to-plot] clear-all-plots plot-new-list name-of-plot list-to-plotendto plot-new-list [name-of-plot list-to-plot] locals [index] set index 0 set-current-plot name-of-plot clear-plot repeat length list-to-plot [ plot item index list-to-plot set index index + 1 ]endto plot-value-and-lists [value-plot value list-plot1 list-to-plot1 list-plot2 list-to-plot2] plot-new-value value-plot value plot-new-list list-plot1 list-to-plot1 plot-new-list list-plot2 list-to-plot2end;; increases the clock by 1 and cycles phase to the next appropriate valueto clock-tick set clock clock + 1 ;; The phase cycles from 0 to p, then starts over. set phase phase + 1 if phase mod p = 0 [ set phase 0 ] ask intersections [ set greensteps (greensteps + 1) ]end; *** NetLogo Model Copyright Notice ***;; This activity and associated models and materials was created as part of the projects:; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and ; INTEGRATED SIMULATION AND MODELING ENVIRONMENT.; These projects gratefully acknowledge the support of the ; National Science Foundation (REPP & ROLE programs) -- grant numbers ; REC #9814682 and REC-0126227.;; Copyright 2002 by Uri Wilensky & Walter Stroup. Updated 2002. All rights reserved.;; Permission to use, modify or redistribute this model is hereby granted,; provided that both of the following requirements are followed:; a) this copyright notice is included.; b) this model will not be redistributed for profit without permission; from the copyright holders.; Contact the copyright holders for appropriate licenses for redistribution ; for profit.;; To refer to this model in academic publications, please use:; Wilensky, U. & Stroup, W. (2002). NetLogo HubNet Gridlock model.; http://ccl.northwestern.edu/netlogo/models/HubNetGridlock.; Center for Connected Learning and Computer-Based Modeling,; Northwestern University, Evanston, IL.;; In other publications, please use:; Copyright 1998 by Uri Wilensky and Walter Stroup. All rights reserved. See; http://ccl.northwestern.edu/netlogo/models/HubNetGridlock; for terms of use.;; *** End of NetLogo Model Copyright Notice ***@#$#@#$#@GRAPHICS-WINDOW4911098452480803.01121110111CC-WINDOW5872993967Command Center0PLOT0669279858Average Wait Time of CarsTimeAverage Wait0.0100.00.05.0truefalsePENS"default" 1.0 0 -2674135 true"avg" 1.0 0 -13345367 true"global" 1.0 0 -16777216 truePLOT0292279481Average Speed of CarsTimeAverage Speed0.0100.00.01.0truefalsePENS"default" 1.0 0 -2674135 true"avg" 1.0 0 -13345367 true"global" 1.0 0 -16777216 trueSLIDER1001019743grid-size-ygrid-size-y120811NILSLIDER3109743grid-size-xgrid-size-x120811NILSWITCH19582285115crash?crash?11-1000SWITCH48299115power?power?01-1000SLIDER44615579numbernumber1300032011carsPLOT0479279668% Stopped CarsTime% Stopped Cars0.0100.00.0100.0truefalsePENS"default" 1.0 0 -2674135 true"avg" 1.0 0 -13345367 true"global" 1.0 0 -16777216 trueBUTTON212257276290GogoT1TOBSERVERTNILSLIDER3119131152simulation-speedsimulation-speed010.010.00.11NILBUTTON39683480116Setupsetup trueNIL1TOBSERVERTNILSLIDER135119227152speed-limitspeed-limit0.01.01.00.11NILBUTTON225758290Re-Runsetup falseNIL1TOBSERVERTNILMONITOR282237359286Current Phasephase31SLIDER415499187pp120083
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -