⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aaauser---emars.nlogo

📁 NETLOGO
💻 NLOGO
📖 第 1 页 / 共 5 页
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MARS 1.07m; MARS = "Multi-Agent Religion Simulation"; (Schelling-like Simulation of Migration/Conformity/Conversion);; Last modified: 2005-7-29, 12:30am; Runs under NetLogo 2.1beta2;;; Coding credits: ; Coded in NetLogo by XXXXXXXXX in 12/2002, 1/2003, 5-6/2003, and 10-11/2004; with assistance from XXXXXXXXXXX.; ; ; Note: ";:" at left indicates commands for debugging use only; Note: ";x" at left indicates commands needed in TRX (type x rate) version ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Globals, Breeds, etc.:globals [; Globals defined by sliders and switches:; ;  Sliders (for each type, i = 0, 1, ..., N-1 and/or j = r(ed), g(reen), b(lue), y(ellow));    j_num;    j_pull1     j_pull2  ...    j_pullN-1    j_type    j_self    j_pull;    j_copy1     j_copy2  ...    j_copyN-1    j_rate    j_habit   j_copy;;    red    green    blue    yellow;    rand-wgts;    move-rate;    density;    regions;    rateX                   ;;x    rateX                    ;x replace with 0-100 slider in TRX version    n-search                 ;; list - number of patches that "find-new-patch" checks (use with                             ;; patch selection criteria, such as max num of nbrs, num like self, etc.)    t-sliders                ;; list of root-names of type sliders ("pull1" "pull2" ... "type" "self" "pull")    r-sliders                ;; list of root-names of rate sliders ("copy1" "copy2" ... "rate" "habit" "copy")                             ;; used with "run" command to automate copying values to/from sliders    ;; type and color info    N-types                  ;; number of different types (referred to as "N" in comments)    zeroN                    ;; list of N zeros, [0 0 ... 0]    zeroN1                   ;; list of N+1 zeros, [0 0 ... 0 0]    zeroN3                   ;; list of N+3 zeros, [0 0 ... 0 0 0 0]    oneN                     ;; list of N ones, [1 1 ... 1]    oneN1                    ;; list of N+1 ones, [1 1 ... 1 1 ]    oneN3                    ;; list of N+3 ones, [1 1 ... 1 1 1 1]    type-colors              ;; list of type names (e.g. red, ...)    type-names               ;; list of the actual strings (e.g., "red", ...)    c-list                   ;; list of first letter of colors ["r" "g" ...]    type-shapes              ;; list of shapes of each type of turtle    turtle-shape-list        ;; list of the actual strings ("circle", "box", ...)    turtle-size-list         ;; Use to alter turtle size according to rate (only for circles)    border-color             ;; color of border patches (currently grey)    divider-color            ;; color of divider patches (currently grey)    main-board-color         ;; color of main board (currently black)    ;; model variables    shares                   ;; share each type in turtle population    type-percents    t-pull                   ;; weighting factors used in adjust-type calculations    r-copy                   ;; random weighting factors used in adjust-rate calculations    copy-flag-value    pull-flag-value    modify-stage-list        ;; toggles state of buttons, used to interpret sliders    current-state            ;; which turtle-state (saved via t-history) was recalled last.     color-mode               ;; 0 = rate-shaded mono, 1 = type-colored, 2 = type-colored and rate-shaded.    color-state              ;; 0 = original type and rate, 1 = current.    current-region           ;; Cycles over [1 .. N-regions] as "populate-region" is invoked.    population               ;; list = [total population, region 1 pop, region 2 pop, etc.]    region-totals            ;; list = [region 1's current population, region 2's pop, ..., total pop]    region-max               ;; list = [total number of patches, total in region 1, in region 2 ...]        ;; statistics    percent-similar          ;; average percent of local turtles of same type    g-stats                  ;; actual-g/expected-g statistics for each type of turtle    type-totals              ;; list w/ current number of turtles (one entry for each type + one for overall)    rate-totals              ;; list w/ current summed turtle rates (one entry for each type + one for overall)    types-list1              ;; used in "foreach" loops = [0 1 2 3 ]    types-list2              ;; used in "foreach" loops = [0 1 2 3 4]    ;; parameters that can only be changed via recoding    slow-speeds              ;; cut-off slider speed value for blinking action    max-speed                ;; slider speed setting that sets wait to zero.    max-wait                 ;; longest pause (corresponds to slowest slider speed setting)    blink-period             ;; total blinking time    blink-interval           ;; time per blink (in seconds)    no-rates                 ;; Flag = 1 if only types are calculated, = 0 if both are used.                             ;; "no-rate=1" yields simple (type-only) version of program (MARS-1)    plot-period              ;; time (in periods) between updating of plots (currently set to 10)        ;; parameters that remain fixed for a given run    N-regions                ;; Number of religions, as determined by "regions" slider    ;; parameters that may vary during run    ;; (see also sliders)    target-type              ;; parameters for "find-new-patch" (N-list)    period                   ;; tracks total number of number of moves (including to same location)    w-span                   ;; type parameter used by set-rand-wgts method.    r-span                   ;; rate parameter used by set-rand-wgts method.    current-scenario-data    ;; information required to replay scenario (since last "start/run")                             ;; ... not yet implemented; see "to scenario-update".    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;FOR DEBUGGING ONLY ;;;;;;;;;;;;;;;;;        zz1 zz2 zz3 zz4                             ; globals for testing     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    ;; rate and type adjustment parameters (copied to/from sliders)    saved-rcopy-sets            ; saved r-copy matrices    saved-tpull-sets            ; saved t-pull matrices    saved-shares]turtles-own [    ;; matrix of turtle's past "states": [ [state0] [state1] ...]     t-history          ;; Each "state" is a (sub)list of form [xcor, ycor, rate, type].                         ;; State0 (sublist 0) is for birth, sublist 1 for initial                       ;; state (after adjusting rate and type), and subsequent sublists are those                       ;; saved by user.        ;; Random values used to "personalize" the parameters that determine turtle type changes.    ;; Determined when via "set-rand-wgts" procedure when turtle is "born."    ;; Used when "rand-wgt" switch is "on"; ignored when "off"    rnd-type                  ;; 3+N-item list    ;; Random values used to "personalize" the parameters that determine turtle rate changes.    ;; Determined when via "set-rand-wgts" procedure when turtle is "born."    ;; Used when "rand-wgt" switch is "on"; ignored when "off"    rnd-rate                  ;; 3+N-item list    ;; Key state variables    own-rate                    ;; current rate of participation (e.g., church attendance rate)    own-type                    ;; current type of particpant (e.g., type of religion)]patches-own [    region-id                     ;; 0 for edges, 1 for region 1, 2 for 2, etc.    nearby-types                  ;; list with item i = number of type-i nbrs, and                                   ;  last item = total number of nbrs.]to save-parameters  if saved-rcopy-sets = 0 [set saved-rcopy-sets [] ]  set saved-rcopy-sets lput ((length saved-rcopy-sets) / 2) saved-rcopy-sets   set saved-rcopy-sets lput r-copy saved-rcopy-sets  if saved-tpull-sets = 0 [set saved-tpull-sets [] ]  set saved-tpull-sets lput ((length saved-tpull-sets) / 2) saved-tpull-sets   set saved-tpull-sets lput t-pull saved-tpull-sets  if saved-shares = 0 [set saved-shares [] ]  set saved-shares lput ((length saved-shares) / 2) saved-shares  set saved-shares lput shares saved-sharesendto recall-parameters [i]  if saved-rcopy-sets != 0 [     set r-copy item (2 * i + 1) saved-rcopy-sets     set t-pull item (2 * i + 1) saved-tpull-sets     set shares item (2 * i + 1) saved-shares  ]end;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Set/initialize basic paramters:;; Buttons (and the procedures they run);; reds (add-turtles-manually 0), ditto for greens, blues, yellows; Start/End (Setup); Run/Pause (go); Options (menu); Populate (populate-region); Color (toggle-color-mode); Scenarios (menu);  ;; Switches (and their globals);; rand-wgts (rand-wgts)to initialize-shapes-and-colors    set type-colors [sky red green yellow]        ; color values (numerical values) as defined by NetLogo    set type-names ["blue" "red" "green" "yellow"]              ; color names (strings) used by plots (note "blue", not "sky")    ;set type-shapes ["circle" "circle" "circle" "circle"]   ; for color output    set type-shapes ["circle" "x" "triangle" "box"]    ; for b&w (printed) output        ; shape names (strings) used on board.      set c-list ["b" "r" "g" "y"]        ; first letter in color names (could be derived via "first" operator)    ;set turtle-size-list     ;   ["circle0" "circle1" "circle2" "circle3" "circle4" "circle5" "circle6" "circle7"]    set-default-shape turtles item 0 type-shapes      set main-board-color white    set border-color black    set divider-color blackendto initialize-parameters;; Use this section to store basic parameterslocals [ XX ]    set no-rates 0                     ; use to suppress rate-related features.    set current-state 0                ; use to track which (saved) board is being displayed    set slow-speeds 3                  ; moving turtles blink only if speed < slow-speeds    set max-wait 1                     ; time (in seconds) to wait if speed = 0    set max-speed 10                   ; maximal speed setting    set period 1                       ; use to limit stat and plot updates    set blink-period 1                 ; use for 1 sec of blinking    set blink-interval .2              ; use for .2 sec per blink    set plot-period 10                 ; number of periods between plot-updates        set w-span 1.0                     ; used in set-rand-wgts    set r-span 1.0                     ; used in set-rand-wgts    set N-types 4                      ; number of "types" (i.e., turtle colors)        set zeroN  n-values (N-types) [0]        ; = [0 0 ... 0], length N    set oneN   n-values (N-types) [1]        ; = [1 1 ... 1], length N    set zeroN1 n-values (N-types + 1) [0]    ; = [ 0 0 ... 0 0 ], length N+1    set oneN1  n-values (N-types + 1) [1]    ; = [ 1 1 ... 1 1 ], length N+1    set zeroN3 n-values (N-types + 3) [0]    ; = [ 0 0 ... 0 0 0 0 ], length N+3    set oneN3  n-values (N-types + 3) [1]    ; = [ 1 1 ... 1 1 1 1 ], length N+3            set n-search oneN                   ; find-new-patch initially searches just one patch    set target-type oneN                ; multi-patch searches default: prefer max turtles of own type        set shares make-constant-list N-types ( 1 / N-types)                                              ; initially all types have equal shares (even if all are zero).    set type-percents make-constant-list N-types ( 1 / N-types)                                              ; ... and hence also equal percentages (even if all are zero).    set type-totals (sentence zeroN1 )        ; = [ 0 0 ... 0 ], length N+1    set rate-totals n-values (N-types + 1) [.5]       ; = [ .5 .5 ... .5 ], length N+1    set types-list1 [0 1 2 3 ]                ; used in "foreach" loops    set population (sentence zeroN1 )      ; start w/ zero turtles of all types on board    set region-totals (sentence zeroN1 )   ; start w/ zero turtles of all types on board                                            ; Initialize t(ype)-pull and r(ate)-copy matrices:        ; Sub-lists have (N+3) elements, one for each type factor        ; plus initial base, habit, and alternate (uniform-conformity) factor.        ; Create t-pull and r-copy as list of lists,         ; each containing N-copies of the XX sub-list, yielding two N x (N+3) matrices overall.    set t-pull n-values (N-types) [zeroN3]    set r-copy n-values (N-types) [zeroN3]        ; Equivalent to "set t-pull [ [0 0 0 0 0 0 0] ... [0 0 0 0 0 0 0] ]"    set t-sliders ["pull1" "pull2" "pull3" "pull4" "type" "self" "pull"]    set r-sliders ["copy1" "copy2" "copy3" "copy4" "rate" "habit" "copy"]        ; strings with base-names of sliders (which give full names when appended to "r_" "g_" ...)    set copy-flag-value 2.1             ; flag to read from full matrix of copy-sliders    set pull-flag-value 2.1             ; flag to read from full matrix of pull-sliders;x    set rateX 0                         ;x remove for TRX version    set current-scenario-data []endto initialize-board    locals [ i ]    ;; Lay out board (borders, regions, etc.)    ;; Step 1a: Set region-id's for borders and dividers    ask patches [        ;; initialize all patches         set region-id 1        if N-regions >= 1 [          if N-regions >= 2 and pycor <= 0               [ifelse pycor = 0 [set region-id .2] [set region-id 2]]          if N-regions >= 3 and pycor < 0 and ((pxcor >= 0))               [ifelse ((pxcor = 0)) [set region-id .3] [set region-id 3]]          if N-regions >= 4 and pycor > 0 and ((pxcor >= 0))               [ifelse ((pxcor = 0)) [set region-id .4] [set region-id 4]]          ;; create border around edge and through y-axis          if ((abs(pxcor) = screen-edge-x) or (abs(pycor) = screen-edge-y))               [set region-id 0]        ]    ]    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -