Improved Wheeler's CT Model

No preview image

1 collaborator

Default-person Yicheng Shen (Author)

Tags

casualty 

Tagged by Yicheng Shen almost 2 years ago

collateral damage 

Tagged by Yicheng Shen almost 2 years ago

collateral damage) 

Tagged by Yicheng Shen almost 2 years ago

insurgency 

Tagged by Yicheng Shen almost 2 years ago

wargame 

Tagged by Yicheng Shen almost 2 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.2.2 • Viewed 75 times • Downloaded 7 times • Run 0 times
Download the 'Improved Wheeler's CT Model' 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

patches-own [density]

globals[city forest
        soldier_casualty
        insurgent_casualty
        civilian_casualty
        anger new_join
        ending max_anger
successful_ambush]

breed[insurgents insurgent]
breed[civilians civilian]
breed[soldiers soldier]
breed[protesters protester]


soldiers-own[flockmates alert]
civilians-own[panic panic_time]
insurgents-own[detect detect_time]

to setup
  ca
  setup_patches
  setup_individuals

  set soldier_casualty 0
  set insurgent_casualty 0
  set civilian_casualty 0
  set ending 0
  set anger 0
  set new_join 0
  set max_anger 0
  set successful_ambush 0

  reset-ticks
end 

to setup_patches

   ask patches
  [ set density (random 10000) ]
  repeat 2 [  diffuse density 1 ]  ; can change density layout if needed

  ask patches
  [ set pcolor scale-color green density 9000 1000]

  set city min-n-of 120 patches [density]      ; low density city
  set forest max-n-of 20 patches [density]     ; high density forest

  ask city [set pcolor black]
end 

to setup_individuals

  create-civilians initial_civilian_number * 0.9
   [ set size 1.5
    setxy random-xcor random-ycor
    set color white
    set shape "person"
    set panic False
    set panic_time 0
  ]

   create-protesters initial_civilian_number * 0.1
   [ set size 1.5
    setxy random-xcor random-ycor
    set color pink
    set shape "person"
  ]


   create-insurgents initial_insurgent_number
  [ set size 1.5
    setxy random-xcor random-ycor
    set color red
    set shape "person soldier"
    set detect False
    set detect_time 0
  ]


  create-soldiers initial_soldier_number
  [ set size 1.5
    set xcor random-normal 0 1
    set ycor random-normal 0 1
    set color blue
    set shape "person police"
    set flockmates no-turtles
    set alert False
  ]
end 

to go
;user-message "Insurgency has been eliminated"
;user-message "Government forces have been defeated"
  if not any? civilians [ stop ]
  if not any? insurgents [ set ending 1 stop ]
  if not any? soldiers [ set ending 2 stop]
  if soldier_casualty > (initial_soldier_number * 2)
  [set ending 2 stop]

  ask civilians [civilians_movement]
  ask protesters [protesters_movement]
  ask insurgents [insurgents_movement]
  ask soldiers [soldiers_movement]


;  if count civilians < 5
; [ create-civilians 15
;   [ set size 1.5
;    setxy random-xcor random-ycor
;    set color white
;    set shape "person"
;    set panic False
;    set panic_time 0
;  ]
;  ]



  if Reinforcement? [           ; reinforcement: send in 10 more soldiers when there are fewer than 5 remaining
  if count soldiers < 5
  [create-soldiers 10
  [ set size 1.5
    set xcor random-normal 0 1
    set ycor random-normal 0 1
    set color blue
    set shape "person police"
    set flockmates no-turtles
    set alert False
  ]]
  ]

  check-anger

;  ask links [die]
  tick
end 

to  check-anger

  if anger > 0
  [set anger anger - 0.05]

  if anger < 0
  [set anger 0]

  if any? civilians [
  if anger > 10       ; medium anger = more protesters
    [
       let x random 100
       if x > 90
      [ask one-of civilians [die]
          create-protesters 1
         [ set size 1.5
         setxy random-xcor random-ycor
          set color pink
          set shape "person"
            ]
      ]
    ]


  if anger > 20    ; high anger = more insurgents
    [let x random 100
       if x > 90
     [
     set new_join new_join + 1
         create-insurgents 1
       [set size 1.5
        setxy random-xcor random-ycor
        set color red
        set shape "person soldier"
        set detect False
        set detect_time 0
       ]
      ]
     ]
  ]

  if anger > max_anger
  [set max_anger anger]
end 

to protesters_movement
  right random 20
  left random 20
  fd 0.8
end 

to civilians_movement

  if any? insurgents in-radius 4       ; if seeing insurgents, become panic for 20 ticks
  [set panic_time 20]

  ifelse panic_time > 0
  [
;    let target insurgents in-radius 3
;    ask target [set detect True]

    set color yellow
    set panic True
    face min-one-of soldiers [distance myself]           ; run towards soldiers during panic
    set heading heading + random-normal 0 10
    fd 1
    set panic_time panic_time - 1
  ]


  [set panic False
    set color white
    ifelse [density] of patch-ahead 1 < 5500          ; avoid forest when wandering around normally
    [fd 1]
    [set heading heading + 180 + random-normal 0 30
    fd 1]
  ]

;  let p min-one-of patches in-radius 15 [density]
;
;  ifelse [density] of p < density
;  [
;    face p
;    fd  0.6
;     ]
;
;  [  right random 20
;      left random 20
;    fd 0.8
;  ]
end 

to insurgents_movement

  let p max-one-of patches in-radius 20 [density]

  if [density] of p > density [           ;  find nearest forest to hide
    face p
    fd  1]

  if any? civilians in-radius 4 or any? soldiers in-radius 3    ; if seen by soliders or civilians, detected for 20 ticks
  or any? insurgents with [detect = True] in-radius 4
  [set detect_time 20]

  ifelse detect_time > 0
  [set detect True
    face min-one-of turtles with [color != red] [distance myself]     ; move away to hide
    set heading heading + 180 + random-normal 0 30
    fd 1
  set detect_time detect_time - 1 ]
  [set detect False]


  if any? soldiers with [alert = False] in-radius 8   ; ambush those soliders with alert = false
  [
   insurgents-ambush-soldiers
  ]
end 

to soldiers_movement

;    ifelse any? insurgents
;
;    [face one-of insurgents
;    ; [distance myself]
;    set heading heading
;    fd 0.3]
;    [flock]

  if any? civilians with [panic = True] in-radius 10
  or any? insurgents in-radius 3
  or any? soldiers with [alert = True] in-radius 5
  [set alert True]


  if any? civilians in-radius 10
  [misfire]


  ifelse any? insurgents with [detect = True]  in-radius 15
  [
   ifelse alert = True
  [face min-one-of insurgents with [detect = True] [distance myself]
    set heading heading
    fd 1]
  [flock
    fd 1]

  if any? insurgents-here
  [soldiers-fight-insurgents]
  ]

   [set alert False
    flock
    fd 1]
end 

to misfire

  let sight [density] of patch-here

  let x random 100
  if x > (accuracy) * 100 *  9000 / sight

  [  let y random 100
     if y > 50
    [
    set anger anger + 3
    ask one-of civilians in-radius 10 [die]
    set civilian_casualty civilian_casualty + 1
    ]
  ]
end 

to soldiers-fight-insurgents
  let x random 100

  ifelse x > (1 - effectiveness) * 100

  [
  ask min-one-of insurgents with [detect = True] [distance myself] [die]
  set insurgent_casualty insurgent_casualty + 1

    let y random 100
    if y > (accuracy * 100)
    [
      if any? civilians in-radius 10
      [set anger anger + 1.5
       ask one-of civilians in-radius 10 [die]
      set civilian_casualty civilian_casualty + 1]     ;; low accuracy cause more civilian death
     ]

  ]

  [  set soldier_casualty soldier_casualty + 1
    set successful_ambush successful_ambush + 1
     die
     ]
end 

to insurgents-ambush-soldiers
  set detect True

  let x random 100
  ifelse x > 70                          ; 70% kill soldier and 30% insurgent dies

  [
    set insurgent_casualty insurgent_casualty + 1
    let y random 100
    if y > (accuracy * 100)
     [if any? civilians in-radius 10
        [set anger anger + 3
         ask one-of civilians in-radius 10 [die]
      set civilian_casualty civilian_casualty + 1]     ;; low accuracy cause more civilian death
     ]
    die
  ]

  [ let insurgent-target one-of soldiers with [alert = False] in-radius 8

    ask insurgent-target [die]
  set soldier_casualty soldier_casualty + 1
  ask soldiers in-radius 8 [set alert True]]
end 



;; flocking code

to flock
  find-flockmates
  let nearest-neighbor min-one-of flockmates [distance myself]
  if any? flockmates
    [
      ifelse distance nearest-neighbor < 1
        [ separate ]
        [ align
          cohere ] ]
end 

to find-flockmates
  set flockmates other soldiers in-radius 8
end 

to find-nearest-neighbor
  let nearest-neighbor min-one-of flockmates [distance myself]
end 

;;; SEPARATE

to separate
  let nearest-neighbor min-one-of flockmates [distance myself]
  turn-away ([heading] of nearest-neighbor) 1.5
end 

;;; ALIGN

to align  ;; turtle procedure
  turn-towards average-flockmate-heading 5
end 

to-report average-flockmate-heading
  let x-component sum [dx] of flockmates
  let y-component sum [dy] of flockmates
  ifelse x-component = 0 and y-component = 0
    [ report heading ]
    [ report atan x-component y-component ]
end 

to cohere
  turn-towards average-heading-towards-flockmates 3
end 

to-report average-heading-towards-flockmates
  let x-component mean [sin (towards myself + 180)] of flockmates
  let y-component mean [cos (towards myself + 180)] of flockmates
  ifelse x-component = 0 and y-component = 0
    [ report heading ]
    [ report atan x-component y-component ]
end 

to turn-towards [new-heading max-turn]
  turn-at-most (subtract-headings new-heading heading) max-turn
end 

to turn-away [new-heading max-turn]
  turn-at-most (subtract-headings heading new-heading) max-turn
end 

to turn-at-most [turn max-turn]
  ifelse abs turn > max-turn
    [ ifelse turn > 0
        [ rt max-turn ]
        [ lt max-turn ] ]
    [ rt turn ]
end 

There is only one version of this model, created almost 2 years ago by Yicheng Shen.

Attached files

File Type Description Last updated
Bennett_2008_JASSS_EvolutionofInsurgency.pdf pdf Reference of Bennett almost 2 years ago, by Yicheng Shen Download
Paper for this improved model.pdf pdf My paper for describing this improved model almost 2 years ago, by Yicheng Shen Download
Wheeler 2005 JASSS It pays to be Popular.pdf pdf Basic Reference of Wheeler almost 2 years ago, by Yicheng Shen Download

This model does not have any ancestors.

This model does not have any descendants.