Word-of-mouth

Word-of-mouth preview image

3 collaborators

Agnieszka Kowalska-Styczeń (Author)
Tomasz Owczarek (Team member)

Tags

cellular automata 

Tagged by Katarzyna Sznajd-Weron almost 8 years ago

social science 

Tagged by Katarzyna Sznajd-Weron almost 8 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 5.2.1 • Viewed 1203 times • Downloaded 88 times • Run 0 times
Download the 'Word-of-mouth' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Info tab cannot be displayed because of an encoding error

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

                                                                                                                                                                                                                                                                                   globals[
  A_no_list            ;; number of type-A agents in each iteration
  B_no_list            ;; number of type-B agents in each iteration
  nb                   ;; type of neighborhood
  latane_denominator   ;; depends on type of nb (4, 12, 24)
  result               ;; "pending" or "stable"; if "stable" model stops
]

turtles-own[
  class                ;; agent's type i.e. A or B
  value                ;; 1 or -1 depending on the class
  action               ;; describes action of the agent ("stay", "change" or "move")
  movement-counter     ;; counts how many times agent tried to move this turn
  patch-2              ;; the patch agent occupied 2 iterations earlier
  patch-1              ;; the patch agent occupied 1 iteration earlier
  class-2              ;; agent's type 2 iterations earlier
  class-1              ;; agent's type 1 iteration earlier
]

to setup
  clear-all
  set-neighbourhood
  set A_no_list []
  set B_no_list []
  ask patches[
    if random-float 1 < density
    [
      let val 1
      if random-float 1 > type_A [set val -1]
      sprout 1
      [
        set-class val
        set shape "square"
        set movement-counter 0
      ]
    ]
  ]
  set result "pending"
  reset-ticks
end 

to go
  if ticks = 1
  [
    ask turtles
    [
      set patch-1 patch-here
      set class-1 class
    ]
  ]
  if ticks > 1
  [ ask turtles
    [
      set patch-2 patch-1
      set patch-1 patch-here
      set class-2 class-1
      set class-1 class
    ]
  ]
  if rule = "MR" [ ask turtles [ MR-rule ] ]
  if rule = "UR" [ ask turtles [ UR-rule ] ]
  if rule = "ULR" [ ask turtles [ ULR-rule ] ]
  ask turtles [ make-action ]
  count-population
  tick
  if ticks > 1 [ check-stop-conditions ]
  if ((result != "pending") or (ticks >= 1000)) [ stop ]
end 

to set-class [ class-value ]
  ifelse class-value = 1
  [
    set class "A"
    set value 1
    set color green
  ]
  [
    set class "B"
    set value -1
    set color red
  ]
end 

to set-neighbourhood
  if range = 1
  [
    set nb [
              [-1 0]
           [0 -1] [0 1]
               [1 0]
           ]
  ]
  if range = 2
  [
    set nb [
                        [-2 0]
                [-1 -1] [-1 0] [-1 1]
           [0 -2] [0 -1]       [0 1] [0 2]
                  [1 -1] [1 0] [1 1]
                         [2 0]
           ]
  ]
  if range = 3
  [
    set nb [
                              [-3 0]
                      [-2 -1] [-2 0] [-2 1]
               [-1 -2] [-1 -1] [-1 0] [-1 1] [-1 2]
          [0 -3] [0 -2] [0 -1]       [0 1]  [0 2] [0 3]
                 [1 -2] [1 -1] [1 0] [1 1]  [1 2]
                        [2 -1] [2 0] [2 1]
                               [3 0]
           ]
  ]
end 

to set-direction
  set heading ((random 4) * 90)
end 

to move
  fd 1
  if any? other turtles-here [ move ]   ;; if patch is occupied - repeat
end 

to moving-procedure
  let p patch-here
  ifelse movement-counter = 0
  [ set-direction ]
  [ set heading heading + 90 ]
  move
  ifelse ((p = patch-here) and (movement-counter < 4))
  [
   ;; if agent ends in the same patch - repeat whole procedure and increase counter
    set movement-counter movement-counter + 1
    moving-procedure
  ]
  [ set movement-counter 0 ]
end 

to MR-rule
  set action "stay"                                     ;; default state
  let nn turtles at-points nb                           ;; take all turtles in neighbourhood
  let influence sum [value] of nn                       ;; sum their values
  ifelse influence = 0                                  ;; infl==0 means that no. of A and B are the same
  [ set action "move" ]
  [ if influence * value < 0 [ set action "change" ] ]  ;; infl*value is < 0 when most neighbours are opposite type
end 

to UR-rule
  set action "stay"                                     ;; default state
  let nn turtles at-points nb                           ;; take all turtles in neighbourhood
  let influence sum [value] of nn                       ;; sum their values
  ifelse count nn = abs influence                       ;; no. of neighbors==abs(infl) means that all nn are the same
  [
    ifelse influence = 0                                ;; in that case influence = 0 means that there are no neighbours
    [ set action "move" ]                               ;; and agent just moves
    [
      if influence * value < 0 [ set action "change" ]  ;; if influence <> 0 then check if neighbours' type is different
    ]                                                   ;; infl*value is < 0 when neighbours are opposite type - change
  ]                                                     ;; if not, nothing changes (default state, i.e. "stay")
  [ set action "move" ]                                 ;; move if not all neighbours are the same
end 

to ULR-rule
  set action "stay"                                     ;; default state
  let nn turtles at-points nb                           ;; take all turtles in neighbourhood
  let influence sum [value] of nn                       ;; sum their values
  ifelse count nn = abs influence                       ;; no. of neighbors==abs(infl) means that all nn are the same
  [
    ifelse influence = 0                                ;; in that case influence = 0 means that there are no neighbours
    [ set action "move" ]                               ;; and agent moves
    [
      if influence * value < 0                          ;; if influence <> 0 then check if neighbours' type is different
      [ set latane_denominator 4                        ;;
        if range = 2 [ set latane_denominator 12 ]      ;; denominator depends on type of neighbourhood
        if range = 3 [ set latane_denominator 24 ]      ;;
        if random-float 1 < sqrt((count nn) / latane_denominator) [ set action "change" ]  ;; change only when
     ]                                                                                     ;; random r < sqrt(k/lat_denom)
    ]
  ]
  [ set action "move" ]
end 

to make-action
  if action = "move" [ if random-float 1 < movement_prob [ moving-procedure ] ]
  if action = "change" [ set-class (-1 * value) ]
end 

to count-population
  set A_no_list lput (count turtles with [class = "A"]) A_no_list
  set B_no_list lput (count turtles with [class = "B"]) B_no_list
end 

to check-stop-conditions
  ifelse (abs (count turtles with [class = "A"] - count turtles with [class = "B"]) = count turtles)
  [ set result "stable" ]    ;; all turtles are the same
  [                          ;;
    let change 0
    ask turtles
    [
      if ((patch-here != patch-2) or (class != class-2))
      [
        set change 1
      ]
    ]
    if change = 0 [ set result "stable" ] ;; oscilating or not changing
  ]
end 


;; not used but now can be useful if greater ranges are considered in the future

to set-latane
 let i 0
 repeat range
 [
   set i (i + 1)
   set latane_denominator latane_denominator + (i * 4)
 ]
end 

There is only one version of this model, created almost 8 years ago by Katarzyna Sznajd-Weron.

Attached files

File Type Description Last updated
Word-of-mouth.png preview Preview for 'Word-of-mouth' almost 8 years ago, by Katarzyna Sznajd-Weron Download

This model does not have any ancestors.

This model does not have any descendants.