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

📄 aaauser---emars.nlogo

📁 NETLOGO
💻 NLOGO
📖 第 1 页 / 共 5 页
字号:
       ; because "max-one-of" (and "one-of") chooses the *first* patch from the set       ; of patches ordering lexographically, by pycor and then pxcor!             ;; Show "walking" turtle on slowest speed       if speed = 1 [             set steps distancexy-nowrap xcor-max ycor-max          set heading towardsxy-nowrap xcor-max ycor-max          repeat steps [               fd 1 (set initial-pcolor pcolor) (set pcolor white)               wait 0.3 (set pcolor initial-pcolor)           ]          set heading (heading - heading)    ; rotate turtle back to zero heading       ]    setxy xcor-max ycor-maxendto update-nearby [ x-type x-change ]    ;; Updates "nearby" lists for new or old nbrs of moved/added turtle    ;; Invoked by (turtle's new or old) patch    ;; Value of x-change is 1 for turtle's new patch and -1 for turtle's old patch    ;; 1) Update nearby-types    ask neighbors with [region-id >= 1]        [            set nearby-types replace-item x-type nearby-types                 (x-change + (item x-type nearby-types))            set nearby-types replace-item N-types nearby-types                 (x-change + (item N-types nearby-types))        ]end    to-report nearby-populations [ pxx pyy id ]    ; reports list of turtle populations [total type1 type2 ... ] nearby patch    locals [ n-near ]    ifelse (id = 0)              ; get number of type-i nbrs (or all if type-i = 0)        [ask patch pxx pyy [set n-near (count neighbors with [any? turtles-here]) ]]        [ask patch pxx pyy [set n-near (count neighbors with [any? turtles-here with [own-type = id ]]) ]]    report n-nearendto set-type-id [type-id]    ;; changes turtle's type to value of {type-id}    set own-type type-idendto empower-turtle [xpower];; Creates a "superstar" agent with "xpower" times normal "pull".;; Procedures also turns on individualized (rand-wgts) weighting, ;; because "superstar" impact occurs through "rnd-type" effect.  loop [    if (mouse-down?) [        ifelse (not any? turtles-at mouse-xcor mouse-ycor) [stop] [            ask one-of turtles-at mouse-xcor mouse-ycor [               ; Revise following code block so that (re-)clicking on a superstar               ; normalizes him by (re-)setting his rnd-type to [1 ... 1].               without-interruption [                  foreach [0 1 2 3 4 5 6] [                      set rnd-type replace-item ? rnd-type xpower                  set shape "superstar"                      ]                ]            ]            set rand-wgts true            stop        ]    ]  ]endto recolor-turtle    ;; changes turtle's color and shape based on its current rate and type (and program's current color-mode)    ;; Base color on own-type and shading on own-rate.    ;; Previously used: "set color ... + int(8 * own-rate) - 4" in place of "set color scale-color ..."    ;; To set rate-based (circular) size: "set shape item (int(7.9 * own-rate)) turtle-size-list"    if color-mode = 0       [set color scale-color gray (.5 * own-type) 0 1 ]    if color-mode = 1       [set color (item own-type type-colors) ]    if color-mode = 2       [set color scale-color (item own-type type-colors) (.2 + .75 * own-rate) 0 1]    ;; Set turtle shape based on type unless it is an "empowered" super-turtle:    ifelse (item 0 rnd-type >= 5)        [set shape "superstar"]       [set shape item own-type type-shapes]endto display-original-color    ;; changes turtle's color based on its original rate and type (and program's current color-mode)    ;; does not alter turtle's actual rate and type, stored in "own-type" and "own-rate".    ;; Base color on own-type and shading on own-rate.    if color-mode = 0         [set color scale-color gray (.3 + .5 * (item 3 (item 0 t-history))) 0 1 ]    if color-mode = 1         [set color (item (item 3 (item 0 t-history)) type-colors) ]    if color-mode = 2         [set color scale-color (item (item 3 (item 0 t-history)) type-colors)          (.2 + .75 * (item 2 (item 0 t-history))) 0 1 ]endto restore-type    ;; changes turtle's type, rate, and color back to original values.    set-type-id (item 3 (item 0 t-history))    if no-rates != 1 [      set own-rate (item 2 (item 0 t-history))      if (rand-wgts = 1) [set own-rate own-rate * (item 0 rnd-rate)]    ]    recolor-turtle  endto restore-position    ;; moves turtle back to original patch (but retains all other attributes)    set xcor (item 0 (item 0 t-history))        ; set xcor birth-xcor    set ycor (item 1 (item 0 t-history))        ; set ycor birth-ycorendto recompute-nearby    ;; When called by any patch on main board, re-computes patch's "nearby-types" list    ;  Invoke after altering board via restore, recall, etc.    foreach types-list1 [ set nearby-types replace-item ? nearby-types (count neighbors         with [region-id >= 1 and any? turtles-here with [own-type = ?]])    ]    set nearby-types replace-item N-types nearby-types (sum but-last nearby-types)end        to-report totals-in-region [xx]    ; Recopute type-totals and rate-totals for region [xx]    ;  Invoke before displaying regional shares    locals [type-totals-xx ]    set type-totals-xx zeroN1    ; 1) Recompute type-totals:    foreach types-list1 [        set type-totals-xx replace-item ? type-totals-xx         (count turtles with [(own-type = ?) and (region-id = xx) ])    ]    set type-totals-xx replace-item N-types type-totals-xx (sum but-last type-totals-xx)    report type-totals-xx    ;; 2) To recompute rate-totals: Modify code from recompute-totals.endto-report shares-in-region [xx]    ; Recopute type-shares and rate-averages for region [xx]    ; Invoke to display regional shares    locals [type-shares-xx ]    ; 1) Recompute type-totals:    ; Get regional type totals from "totals-in-region" reporter     set type-shares-xx totals-in-region xx    if item N-types type-shares-xx > 0 [        foreach types-list1 [            set type-shares-xx replace-item ? type-shares-xx (round(1000 * (item ? type-shares-xx / item N-types type-shares-xx)) / 10)        ]    ]    report but-last type-shares-xx    ;; 2) To recompute rate-totals: Modify code from recompute-totals.endto output-regional-shares    ; Uses shares-in-region reporter to output current shares by region    output-type " REGIONAL SHARES (at time = " output-type period output-print ")"    foreach (sublist types-list1 0 regions) [output-write shares-in-region (1 + ?)]    output-print " "endto recompute-totals    ; Recopute type-totals and rate-totals (used in plots)    ;  Invoke after altering board via restore, recall, etc.    ; 1) Recompute type-totals:    foreach types-list1 [set type-totals replace-item ? type-totals         (count turtles with [own-type = ?])]    set type-totals replace-item N-types type-totals (sum but-last type-totals)    ; 2) Recompute rate-totals:    if no-rates != 1 [        foreach types-list1 [set rate-totals replace-item ? rate-totals             (sum values-from turtles with [own-type = ?][own-rate])]        set rate-totals replace-item N-types rate-totals (sum but-last rate-totals)    ]end        to blink-turtle [ blink-time blink-pause blink-shape blink-color blink-pcolor ]    ;; causes turtle to temporarily display a different shape, color, and patch color    locals [ i actual-shape actual-color actual-pcolor blinks]    set actual-shape shape    set actual-color color    set actual-pcolor pcolor    set blinks int(blink-time / blink-pause)    set i 0    while [i < blinks] [        set color blink-color set shape blink-shape set pcolor blink-pcolor        wait blink-pause        set color actual-color set shape actual-shape set pcolor actual-pcolor        wait blink-pause        set i (i + 1)    ]endto add-to-history    ;; Adds "snapshot" of turtle's current state to t-history list.    locals [n-states]    ; initialize t-history as empty list [  ]    if (t-history = 0) [set t-history [ ] ]    ; add sublist = [xcor,ycor,rate,type] of current turtle    set t-history lput (sentence xcor (sentence ycor (sentence own-rate own-type) )) t-history    ; Display number of newly saved state    ask one-of turtles [set n-states length t-history - 1]   ; update "num-state" counter    ask patch 1 screen-edge-y         [set plabel n-states set plabel-color red]endto revert-to-history [state-num]    ;; Reverts turtle to position, rate, and type saved in item {state-num}    ; of t-history list.    set xcor item 0 (item state-num t-history)    set ycor item 1 (item state-num t-history)    if no-rates != 1 [set own-rate item 2 (item state-num t-history)]    set own-type item 3 (item state-num t-history)    recolor-turtle    set current-state state-numendto set-rand-wgts [ w r ]    locals [ i ]    ;; Computes turtle-specific random adjustment factors that are applied to    ;; the turtle-type based parameters if "rand-wgt" is on.    ;; Must provide decimal bases w & r,     ;; since "random" returns *discrete* numbers when base is integer.    ;; Consider picking weights from bounded normal distribution or something analogous.    ;; 1) Multiplicative weights for adjust-type calculations    ;; uniformly distributed over [1 - w/2, 1 + w/2]    ;; If rnd-type not yet initialized, set it to N+3 zeros    if (rnd-type = 0) [ set rnd-type zeroN3]    set i 0    while [i < (N-types + 3)] [        set rnd-type ( replace-item i rnd-type (precision (1 + (random-float w) - (w / 2)) 2) )            ;; For readability when inspecting turtles, use "precision" to round weights.            ;; Rounding to 2 decimal places should not significantly affect behavior.        set i (i + 1)    ]    ;; 2) Multiplicative weights for adjust-rate calculations,    ;; uniformly distributed over [1 - r/2, 1 + r/2]    ;; If rnd-type not yet initialized, set it to N+3 zeros    if no-rates != 1 [        if (rnd-rate = 0) [ set rnd-rate zeroN3 ]        set i 0        while [i < (N-types + 3)] [            set rnd-rate ( replace-item i rnd-rate (1 + (random-int-or-float r) - (r / 2)) )            set i (i + 1)        ]    ]endto adjust-type    locals [totals i x largest-id largest-total current-total my-type max-possible-nbrs birth-type xx1 xx2]    ; Recall matrix t-pull, elements 0 ... N-1 = cross-type conformity effects    ; element N  = born/base-type effect, N+1 = self/habit/last-period, N+2 = (uniform) conformity    set my-type own-type    set max-possible-nbrs (count neighbors with [ region-id > 0 ])    set totals zeroN        ; initialize totals = [0 0 ... 0]                            ; i-th entry will hold "utility" from switching to type i.    set birth-type (item 3 (item 0 t-history))                            ; item 0 of t-history = original[pxcor pycor rate type]    set i 0                        ; Prepare to loop over each type    ifelse (rand-wgts = true)      ; Execute different versions if rand-wgts "on"/"off"    ;; Random-wgts case:    [         while [i < N-types] [            set x item i totals            ;; 1) Include "birth" effect if i = person's "born" type            if (i = birth-type)[                set x (x + (item N-types (item i t-pull)) * item N-types rnd-type)            ]            ;; 2) Add internal "habit" factor if i = person's current type            ; plus 0-to-1 "rateX" factor for additional impact of own-rate            ; Intuition re. "rateX": Higher current rate -> more incentive to stay with current type.            if (i = own-type) [                set x (x + ((item (N-types + 1) (item i t-pull)                 * item (N-types + 1) rnd-type) +

⌨️ 快捷键说明

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