Protest

Protest preview image

1 collaborator

Default-person Jana Tučková (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.2.1 • Viewed 40 times • Downloaded 0 times • Run 0 times
Download the 'Protest' modelDownload this modelEmbed this model

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


Comments and Questions

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

Click to Run Model

breed [protesters1 protester1]
breed [protesters2 protester2]
breed [police policeman]

protesters1-own [
  xinit1
  dest1
  averse1a
  averse1
]
protesters2-own [
  xinit2
  dest2
  averse2a
  averse2
]
police-own [
  xinitp
  target
  destp
]

globals [
  totaltick
  count-1
  count-2
]


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;setup;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all
  setup-police
  setup-protesters1
  setup-protesters2
  set totaltick 0
  reset-ticks
end 

to count1
  set count-1 count protesters1 with [xcor < 0]
end 

to count2
  set count-2 count protesters2 with [xcor > 0]
end 

to setup-protesters1
  set-default-shape protesters1 "person"
  create-protesters1 num-protesters1
  [
    set color red
    set size 1
    ; 'random' only calls numbers from 0 to 'number'.
    ; Fiddle so that the number is 1 above police line.
    set xinit1 random (15 - (0.5 * police-width))
    setxy (xinit1 + (0.5 * police-width) + 1) random-ycor
    set dest1 patch -16 ycor
    set averse1 random-normal averse-mean1 (averse-mean1 - averse-mean1 / 2)
    ; set averse1a random-gamma 2 1 ; for left-skewed distribution (gamma is right-skewed)
    ;set averse1 -1 * averse1a + averse-mean1 ; for left-skewed distribution (mirror image of gamma)
    ; set averse1 averse1a ; for right-skewed (i.e. aggressive)
    if averse1 < 1
    [
    set averse1 averse-mean1
    ]
    ]
end 

to setup-protesters2
  set-default-shape protesters2 "person"
  create-protesters2 num-protesters2
  [
    set color green
    set size 1
    ; 'random' only calls numbers from 0 to 'number'.
    ; Fiddle so that the number is 1 below police line.
    set xinit2 random ((0.5 * police-width) - 14)
    setxy (xinit2 - (0.5 * police-width) - 2) random-ycor
    set dest2 patch 16 ycor
    set averse2 random-normal averse-mean2 (averse-mean2 - averse-mean2 / 2)
    ;set averse2a random-gamma 2 1 ; for left-skewed distribution (gamma is right-skewed)
    ;set averse2 -1 * averse2a + averse-mean2 ; for left-skewed distribution (mirror image of gamma)
    ;set averse2 averse2a ; for right-skewed (i.e. aggressive)
    if averse2 < 1
    [
    set averse2 averse-mean2
    ]
    ]
end 

to setup-police
   let vertical-spacing (world-height / 4)
   let min-ypos (min-pycor - 0.5 + vertical-spacing / 2)
   set-default-shape police "person police"
   create-police num-police
  [
    set color blue
    set size 1
    let row who / 4
    setxy 0 (min-ypos + row * vertical-spacing)
    set destp patch 0 (min-ypos + row * vertical-spacing)
    ; random police set up - commented out below
;    set xinitp random police-width ; random placements within thin blue line
;    setxy xinitp - (0.5 * police-width) random-ycor
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;go;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
 ask police
 [
   police-step
 ]
 ask protesters1
 [
   protester1-step
 ]
 ask protesters2
 [
   protester2-step
 ]
 if totaltick > 5000 [
  ;file-open "protester1_states.txt" ; open file
  ;;ask protesters1 [file-write xcor] ; get and save data
  ;file-write count protesters1 with [xcor < 0]

  ;file-open "protester2_states.txt" ; open file
  ;;ask protesters2 [file-write xcor] ; get and save data
  ;file-write count protesters2 with [xcor > 0]

  file-open "averse_normal.txt" ; open file
  ask protesters1 [file-print averse1 file-print "\n"] ; get and save data
  ask protesters2 [file-print averse2 file-print "\n"] ; get and save data
  file-close-all

  ;file-close-all

    stop
  ] ; a tick doesn't exactly correspond to a time-unit, but with 100000 it takes on the order of 30 sec at normal speed
  set totaltick totaltick + 1 ; ticking along
count1
  count2
end 

to police-step
  ; ifelse random < 0 ; randomly choose whether to face protester1 or protester2, 50/50
  ifelse random-float 1 <  num-protesters1 / (num-protesters1 + num-protesters2) ; randomly choose whether to face protester1 or protester2, based on ratio of protesters
  [ ; if facing protester1 first
    ifelse (xcor > (- 0.5 * police-width)) and (xcor < (0.5 * police-width))
    [
      ; if within the thin blue line and protester1 in sight
      ifelse (any? protesters1 in-cone police-keenness 120) ;
      [ ; move towards protester1
        set target one-of protesters1 in-cone police-keenness 120
        face target
        forward 1
      ] ; close "move towards protester1"
      [ ; open within the thin blue line and protesterB in sight
        ifelse (any? protesters2 in-cone police-keenness 120)
        [; move towards protester2
          set target one-of protesters2 in-cone police-keenness 120
          face target
          forward 1
        ] ; close "move towards protester2"
        [ ; open "else move back to original position"
          face destp ; face destination
          forward 1
        ]
      ] ; close " within the thin blue line and protester2 in sight"
    ] ; close "within the thin blue line and protester2 in sight"
    [ ; Otherwise move to destp
      face destp
      forward 1
    ]
  ] ; close if facing protester1 first
  [ ; open elseif facing protester2 first
    ifelse (xcor > (- 0.5 * police-width)) and (xcor < (0.5 * police-width))
    [   ; If within the thin blue line,
      ; if within the thin blue line and protester2 in sight
      ifelse (any? protesters2 in-cone police-keenness 120) ;
      [ ; move towards protester2
        set target one-of protesters2 in-cone police-keenness 120
        face target
        forward 1
      ] ; close "move towards protester2"
      [ ; open within the thin blue line and protesterB in sight
        ifelse (any? protesters1 in-cone police-keenness 120)
        [; move towards protester1
          set target one-of protesters1 in-cone police-keenness 120
          face target
          forward 1
        ] ; close "move towards protester1"
        [ ; open "else move back to original position"
          face destp ; face destination
          forward 1
        ]
      ] ; close " within the thin blue line and protester2 in sight"
    ] ; close "within the thin blue line and protester2 in sight"
    [ ; Otherwise move to destp ;
      face destp
      forward 1
    ]
   ]
end 

to protester1-step
  face dest1
  ; If police within view, then turn around
  ifelse any? police in-cone averse1 120
  [
    left 180
    fd 1
  ]
  [
    right random 45
    left random 45
    forward 1
  ]
end 

to protester2-step
  face dest2
  ifelse any? police in-cone averse2 120
  [
    right 180
    fd 1
  ]
  [
    right random 45
    left random 45
    forward 1
  ]
end 

There is only one version of this model, created 3 months ago by Jana Tučková.

Attached files

File Type Description Last updated
Protest.png preview Preview for 'Protest' 3 months ago, by Jana Tučková Download

This model does not have any ancestors.

This model does not have any descendants.