📄 aaauser---emars.nlogo
字号:
ask patches with [ (pxcor = (screen-edge-x - 1)) and (abs(pycor) = screen-edge-y) ] [ set plabel "ORIGINAL TYPES" set plabel-color red ] wait .5 ; revert to actual (rate and type) display: ask turtles [recolor-turtle] ask patches with [(pxcor = (screen-edge-x - 1)) and (abs(pycor) = screen-edge-y)] [ set plabel no-label ]endto restore-turtles-all ;; Restore each turtles to it's setup type AND coordinates restore-turtles-types ask turtles [restore-position ] ; Recompute global type-totals list and rate-totals list recompute-totals ; Restore each patches' "nearby-types" list ask patches with [ region-id >= 1 ] [recompute-nearby] ; Display number of recalled state ask patch 1 screen-edge-y [set plabel 0 set plabel-color magenta]endto toggle-color-mode ;; Toggle between rate-shaded monochrome, type-based color, and shaded-color modes if no-rates != 1 [ set color-mode remainder (color-mode + 1) 3 ;; progresses from 0, to 1, to 2 ask turtles [recolor-turtle] ;; recolor ]endto recall-saved-state ;; Cycle board through saved states. ; First use reverts to original state (t-history0), ; second use reverts to initial adjusted state (t-history1), ; then on to states saved via "save" button. ; Last recalled state is displayed above board. locals [num-states] ask turtle 0 [set num-states length t-history] set current-state (current-state - 1) mod (num-states) ; cycle "current-state" counter to next state ask turtles [ revert-to-history current-state ] ; Recompute global type-totals list and rate-totals list: recompute-totals ; Restore each patch's "nearby-types" list: ask patches with [ region-id >= 1 ] [recompute-nearby] ; Display number of recalled state ask patch 1 screen-edge-y [set plabel current-state set plabel-color red] output-type " Last recalled state: " output-print current-stateend;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Primitive Help Systemto help-menu locals [choice1 choice2 choice3 Ntype] set choice1 (user-choice "Help with which topic?" [ "Overview" "Buttons" "Sliders" "Quit" ]) if choice1 = "Quit" [stop] output-type " HELP: " output-print choice1 if choice1 = "Overview" [ output-print "See 'Information' tab above." ] if choice1 = "Buttons" [ set choice2 (user-choice "Which button?" [ "Superstar" "Originals" "Density" "Start/Stop" "Run" "Quit"]) if choice2 = "Superstar" [ output-print "SUPERSTAR: Press this button and then click " output-print "on an agent to give it ten-fold 'pull'" output-print "compared to typical agents of its type." output-print "Must also switch 'rand-wgts' on." ] if choice2 = "Quit" [stop] ] if choice1 = "Sliders" [ output-print "(No help yet on this topic.)" ]end;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Methods that select complete "scenarios"to scenario-select; Use to set any of the globals - including sliders! - and run; any methods - including those linked to buttons!. So user can simply choose; from various scenarios, modes, etc.; Can use control center via print or show to describe mode or results; For example:; (1) pure peer effects (no rate effects, no history, no birth effects); (2) pure rate effects, just one type & mono-mode; (3) one group is effectively anti-religious, depressing rates of others; (4) various values for habit, etc.; (5) various numbers of regions, density, speed, etc.; Recall that t-pull holds ["pull1" "pull2" "pull3" "pull4" "type" "self" "pull"] for each type.; Recall that t-copy holds ["copy1" "copy2" "copy3" "copy4" "rate" "habit" "copy"] for each type. locals [choice1 choice2 choice3 Ntype Nfile scenario-data s-period s-regions s-density s-n-search s-target-type s-rand-wgts s-move-rate s-shares s-t-pull s-r-copy ] set choice1 (user-choice "Scenario?" [ "Basic" "Resist" "Conform" "Save" "Recall" "Quit" ]) if choice1 = "Quit" [stop] if choice1 = "Basic" [ set regions 2 setup set density 75 set speed 10 set move-rate 100 set rand-wgts false set t-pull [ [0 0 0 0 .3 .3 1.6] [0 0 0 0 .3 .3 1.6] [0 0 0 0 .3 .3 1.6] [0 0 0 0 .3 .3 1.6] ] set r-copy [ [0 0 0 0 .5 0 0] [0 0 0 0 .5 0 0] [0 0 0 0 .5 0 0] [0 0 0 0 .5 0 0] ] set shares [70 30 0 0] copy-to-sliders populate-region set shares [30 70 0 0] copy-to-sliders populate-region recall-saved-state recall-saved-state ] if choice1 = "Resist" [ set regions 2 setup set density 75 set speed 10 set move-rate 100 set rand-wgts false set t-pull [ [0 0 0 0 .3 .3 .3] [0 0 0 0 .3 .3 .3] [0 0 0 0 .3 .3 .3] [0 0 0 0 .3 .3 .3] ] set r-copy [ [0 0 0 0 .5 0 0] [0 0 0 0 .5 0 0] [0 0 0 0 .5 0 0] [0 0 0 0 .5 0 0] ] set shares [70 30 0 0] copy-to-sliders populate-region set shares [30 70 0 0] copy-to-sliders populate-region recall-saved-state recall-saved-state ] if choice1 = "Conform" [ set regions 2 setup set density 75 set speed 10 set move-rate 100 set rand-wgts false set t-pull [ [0 0 0 0 .0 .01 1.9] [0 0 0 0 .0 .01 1.9] [0 0 0 0 0 0 0] [0 0 0 0 0 0 0] ] set r-copy [ [0 0 0 0 .5 0 0] [0 0 0 0 .5 0 0] [0 0 0 0 .5 0 0] [0 0 0 0 .5 0 0] ] set shares [70 30 0 0] copy-to-sliders populate-region set shares [30 70 0 0] copy-to-sliders populate-region recall-saved-state recall-saved-state ] if choice1 = "Save" [ scenario-save ;; File names automatically increment with each successive save: set Nfile 1 while [file-exists? ("scenario-" + Nfile + ".txt")] [set Nfile Nfile + 1] file-open ("scenario-" + Nfile + ".txt") file-write current-scenario-data file-close ] if choice1 = "Recall" [ ;; Note: Tighten this code using the read-string tricks used in copy-to-sliders. set choice2 (user-choice "Full or partial recall?" [ "Full (start over)" "Partial (maintain board)" "Quit" ]) if choice2 = "Partial (maintain board)" [ ;; Partial does *not* restart, but merely changes parameters that affect motion. ;; Hence, no change in current configuration of agents, nor regions, density, shares. set scenario-data scenario-recall ; set period item 0 scenario-data ; set regions item 1 scenario-data ; set density item 2 scenario-data set n-search item 3 scenario-data set target-type item 4 scenario-data set move-rate item 5 scenario-data set rand-wgts item 6 scenario-data ; set shares item 7 scenario-data set t-pull item 8 scenario-data set r-copy item 9 scenario-data copy-to-sliders ] if choice2 = "Full (start over)" [ ;; Full resets everything and starts again with a blank board, ready to populate. set scenario-data scenario-recall ; set period item 0 scenario-data set regions item 1 scenario-data set density item 2 scenario-data set n-search item 3 scenario-data set target-type item 4 scenario-data set move-rate item 5 scenario-data set rand-wgts item 6 scenario-data set shares item 7 scenario-data set t-pull item 8 scenario-data set r-copy item 9 scenario-data copy-to-sliders setup ; Just for debugging: ; output-type "s-period: " output-print period ; output-type "s-regions: " output-print regions ; output-type "s-density: " output-print density ; output-type "s-n-search: " output-print n-search ; output-type "s-target-type: " output-print target-type ; output-type "s-move-rate: " output-print move-rate ; output-type "s-rand-wgts: " output-print rand-wgts ; output-type "s-shares: " output-print shares ; output-type "s-t-pull: " output-print t-pull ; output-type "s-r-copy: " output-print r-copy ] ]endto scenario-save ; Called by "scenario-select save" procedure. ; Each "select-scenario save" appends a new list of parameters to "current-scenario-data". ; Currely, each save writes "current-scenario-data" to a new file, "scenario-NNN.txt" ; where NNN = 1, 2, ... set current-scenario-data (list period regions density n-search target-type move-rate rand-wgts shares t-pull r-copy) ;; Note:;; Eventually, design a "scenario-select record" mode that automatically tracks user actions ;; for a given run: regions, density, sliders, populate, etc. ;; "Record" should also track use of "make-x-percent-move" and other scenarios and options, ;; but this will get complicated!;; Must also track each subsequent push of populate, run, and/or manually added turtle.;; Then design "scenario-select replay" to fully replay the scenario based on the saved info.endto-report scenario-recall locals [scenario-list] ; Get scenario data list (created by scenario-save) from file file-open user-choose-file set scenario-list file-read file-close report scenario-listend;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Methods that create (but do not move) turtles:to add-turtles [ this-region ] ;; Add turtles over current region, filling {density} percent of open patches locals[ n-new n-sum n-type-i pct-sum i XX list-sum n-histories new-patch turtle-type] ;; calculate number of new turtles to add set n-new round((density / 100) * count patches with [(region-id = this-region) and (not any? turtles-here)]) ;; determine number of prior state-saves (i.e., length of t-history) ; it should suffice to check any single turtle ; ifelse needed to avoid error when board is empty. ifelse any? turtles [ask one-of turtles [set n-histories length t-history] ] [set n-histories 2] ;; update slider-based parameters copy-from-sliders ;; determine types of new turtles based on share sliders get-type-percents ; Get type-percents from current share sliders ;; loop over types, creating cumulative list with one "i" ; for each new turtle of type i that must be created set list-sum [] set pct-sum 0 set n-sum 0 while [ i < N-types ] [ set pct-sum pct-sum + (item i type-percents) ; pct-sum = sum of percents up through type-i set n-type-i round(n-new * pct-sum) - n-sum ; n-type-i = number of i's added to list ; (= number of type-i turtles added to board). set n-sum n-sum + n-type-i set list-sum sentence list-sum (make-constant-list n-type-i i) ; append {n-new} elements to list-sum, ; each equal to i's current value set i (i + 1) ] ;; loop over elements in list-sum, randomly selecting (and removing) items, ; and adding a new turtle based on the (type) value of each item.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -