Wheeler's CT Model

No preview image

1 collaborator

Default-person Yicheng Shen (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.2.2 • Viewed 50 times • Downloaded 3 times • Run 0 times
Download the '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]

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


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

  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
   [ set size 1.5
    setxy random-xcor random-ycor
    set color white
    set shape "person"
    set panic False
    set panic_time 0
  ]


   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? insurgents [ stop ]
  if not any? soldiers [ stop ]

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


  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
  ]]
  ]

  tick
end 

to civilians_movement

  if any? insurgents in-radius 3       ; 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 3 or any? soldiers in-radius 3    ; if seen by soliders or civilians, detected for 20 ticks
  [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 1
  [set alert True]


  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 soldiers-fight-insurgents
  let x random 100
  ifelse x > 20                        ; 80% kill insurgent and 20% soldier casulaty

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

  [ die
  set soldier_casualty soldier_casualty + 1]
end 

to insurgents-ambush-soldiers
  set detect True

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

  [ die
    set insurgent_casualty insurgent_casualty + 1
  ]

  [ 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
Wheeler 2005 JASSS It pays to be Popular.pdf pdf Reference almost 2 years ago, by Yicheng Shen Download

This model does not have any ancestors.

This model does not have any descendants.