ABM of Honor Culture

No preview image

1 collaborator

Default-person Kashif Zia (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.2.0 • Viewed 86 times • Downloaded 8 times • Run 0 times
Download the 'ABM of Honor Culture' 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

extensions [table]

breed [aggressors aggressor]
breed [rationals rational]
breed [honors honor]
breed [institutionals intitutional]

turtles-own [strength reputation status challenged-by challenged-to mytype visitedlocations mobilitystate currentdestination dxcor dycor]

globals [stagg sthon stins strat died counter Tsi]

patches-own [blockname]

to setup
  ca
  reset-ticks
  set died 0
  set counter 0
  let mx max-pxcor
  let my max-pycor
  let possible-agents mx * my
  let perc population / 100 * possible-agents / 4
  create-aggressors perc [set color red set mytype "aggressor"]
  create-rationals perc [set color green set mytype "rational"]
  create-honors perc [set color yellow set mytype "honor"]
  create-institutionals perc [set color blue set mytype "institutional"]

  ask patches [set pcolor black]

  ;ask patches [set plabel-color black] set plabel word pxcor word "," pycor]

  ask aggressors [
    move-to one-of patches with [not any? turtles-here ]
  ]

   ask rationals [
    move-to one-of patches with [not any? turtles-here]
  ]

   ask honors [
    move-to one-of patches with [not any? turtles-here]
  ]

   ask institutionals [
    move-to one-of patches with [not any? turtles-here]
  ]


   initializations
   network-formation

  ;segregate
   set died table:make
   ;export-view word ticks ".png"
  create-blocks
end 

to initializations
  ask turtles[
    set strength random-float 0.50 + 0.4
    set reputation strength
    set status "normal"
    set challenged-by -1
    set challenged-to -1
    set mobilitystate "reached" set visitedlocations table:make
  ]
end 

to network-formation ;; needs to be half
  ask turtles [
   network-formation-single
  ]
end 

to network-formation-single
  let distantneighbors n-of links-count turtles with [distance myself > radius]
  if (count distantneighbors > 0) [create-links-to distantneighbors]
  ask links [set color black]
end 

to aggressors-challenge
  let x 20 / 100 * count aggressors
  let few-agg n-of x aggressors
  ask few-agg [set status "need-to-fight" ]
  ;ask aggressors [set status "need-to-fight"  ]
end 

to go
  if ticks = 2000 [stop]
  aggressors-challenge
  set-status
  set-status
  update-values
  proceed
  if mobility-model = "randomwalk" [random-walk]
  draw
  measure-segregation
  tick
  ;export-view word ticks ".png"
end 

to set-status
  ask turtles[
  if breed = aggressors [
      if status = "need-to-fight" [
        let id who
        set status "fight"

        challenge id
      ]

      if status = "need-to-respond" [
        set status "fight"

      ]
    ]

    if breed = honors [
      if status = "need-to-respond" [
        set status "fight"

      ]
    ]

    if breed = institutionals [
      if status = "need-to-respond" [
          set status "call"


      ]
    ]

    if breed = rationals [
      if status = "need-to-respond" [
        let x turtle challenged-by
        let rep [reputation] of x
        ifelse (rep >= strength) [set status "giveup" ] [set status "fight" ]
      ]
    ]
  ]
end 

to update-values
  ask turtles [
    if status = "fight" and challenged-to != -1 [
      let opponent turtle challenged-to
      let oppstatus [status] of opponent
      if oppstatus = "fight"
      [
        let oppstr [strength] of opponent
        let opprep [reputation] of opponent
        ifelse (strength / oppstr >= 1) [
          set reputation reputation + 0.005
          set strength strength - 0.02
        ]
        [
          set strength strength - 0.03
          set reputation reputation - 0.02
        ]
      ]

      if oppstatus = "giveup"
      [
        ;strenght remains same he wins
        set reputation reputation + 0.01
      ]
    ]

    if status = "fight" and challenged-by != -1 [
      let opponent turtle challenged-by
      let oppstatus [status] of opponent
      if oppstatus = "fight"
      [
        let oppstr [strength] of opponent
        let opprep [reputation] of opponent
        ifelse (strength / oppstr >= 1) [
          set reputation reputation + 0.03
          set strength strength - 0.02
        ]
        [
          set strength strength - 0.03
          set reputation reputation + 0.02
        ]
      ]
    ]


    if status = "giveup" [
      set reputation reputation - 0.01
      set strength strength - 0.005
    ]

    if status = "call" [
      set reputation reputation - 0.02
      let opponent turtle challenged-by

      if random-float 1.00 < effectiveness / 100
      [update-challenger opponent]
    ]
  ]
end 

to update-challenger [c]
  ask c [
    set strength strength - 0.04
    set reputation reputation - 0.03
  ]
end 

to challenge [id]
  let tempd [link-neighbors] of self
  let tempn turtles in-radius radius
  let tempt (turtle-set tempn tempd)
  let temp nobody
  ifelse (inclusive?)[set temp one-of other tempt ][set temp one-of other tempt with [mytype != "aggressor"]]


  if temp != nobody [
    ask temp [
      set status "need-to-respond"
      set challenged-by id

    ]
    set challenged-to [who] of temp
  ]
end 

to proceed
  table:clear died
  set counter 0
  ask turtles [
    if (strength < 1) [set strength strength + 0.0005]
    if (strength < toughness / 100) [
      set counter counter + 1
      let tempd [link-neighbors] of self
      let tempn turtles in-radius radius
      let tempt (turtle-set tempn tempd)
      let a count tempt with [breed = aggressors]
      let r count tempt with [breed = rationals]
      let h count tempt with [breed = honors]
      let i count tempt with [breed = institutionals]
      let b mytype
      set b word b word " " counter
      if (a >= r and a >= h and a >= i) [table:put died b "aggressors" ]
      if (r >= a and r >= h and r >= i) [table:put died b "rationals"  ]
      if (h >= a and h >= r and h >= i) [table:put died b "honors"  ]
      if (i >= r and i >= h and i >= a) [table:put died b "institutionals"   ]

      die
    ]
  ]
  create-news died
  ask turtles[
    refresh-agent

  ]
end 

to refresh-agent
  set status "normal"
    set challenged-by -1
    set challenged-to -1
end 

to create-news [d]
  foreach table:keys d
  [ [?] ->

     let b table:get d ? ; mytype dieing type

     let c substring ? 0 (position " " ?)
     set c word c "s"; majority type
    ifelse (evolve?) [ ifelse (random-float 1.00 < 0.25) [ create-new c][ create-new b]   ] [ create-new c]
  ]
end 

to create-new [t]

  if (t = "aggressors") [create-aggressors 1 [set color red set mytype "aggressor" move-to one-of patches with [not any? turtles-here] set strength random-float 0.50 + 0.4
    set reputation strength network-formation-single set mobilitystate "reached" set visitedlocations table:make]]
  if (t = "rationals") [create-rationals 1 [set color green set mytype "rational" move-to one-of patches with [not any? turtles-here] set strength random-float 0.50 + 0.4
    set reputation strength network-formation-single set mobilitystate "reached" set visitedlocations table:make]]
  if (t = "honors") [create-honors 1 [set color yellow set mytype "honor" move-to one-of patches with [not any? turtles-here] set strength random-float 0.50 + 0.4
    set reputation strength network-formation-single set mobilitystate "reached" set visitedlocations table:make]]
  if (t = "institutionals") [create-institutionals 1 [set color blue set mytype "institutional" move-to one-of patches with [not any? turtles-here] set strength random-float 0.50 + 0.4
    set reputation strength network-formation-single set mobilitystate "reached" set visitedlocations table:make]]
end 

to draw
  set stagg 0
  set stins 0
  set sthon 0
  set strat 0

  ask aggressors [
    set stagg stagg + strength
  ]

  ask institutionals [
    set stins stins + strength
  ]

  ask honors [
    set sthon sthon + strength
  ]

  ask rationals [
    set strat strat + strength
  ]
end 

to random-walk
  ask turtles [
    do-random-walk 1
  ]
end 

to profile-based-walk
  ask turtles[
    ifelse table:length visitedlocations <= 4 [
      if ticks mod 20 = 0 [
      let loc word pxcor word "-" pycor
      table:put visitedlocations loc ticks
      ]
      do-random-walk 1
    ]
    [
      if mobilitystate = "reached" [
        let lst table:keys visitedlocations
        let r random 4
        let dest item r lst
        set currentdestination dest
        let pos position "-" currentdestination
        set dxcor read-from-string (substring currentdestination 0 pos)
        set dycor read-from-string (substring currentdestination (pos + 1) length(currentdestination))
        set mobilitystate "moving"
      ]

      if mobilitystate = "moving" [
        ifelse pxcor = dxcor and pycor = dycor [set mobilitystate "reached"]
        [
          set heading towardsxy dxcor dycor
          forward 1
        ]
      ]
    ]
  ]
end 

to do-random-walk [jumplength]
  rt random 360               ; set random heading
  forward jumplength          ; advance one step
end 

to segregate
  ask turtles [
    let w who
    let own mytype
    if (not is-happy? w own) [
      move-to one-of patches with [not any? turtles-here]
    ]
  ]
end 

to-report is-happy? [w own]
  let n 0
  let nown 0
  ask turtle w [set n sum [count turtles-here] of neighbors in-radius radius]
  ask turtle w [set nown sum [count turtles-here with [mytype = own]] of neighbors in-radius radius]

  let perown 1
  if (n != 0) [set perown nown / n]
  ifelse (perown >= 0.75) [report true] [report false]
end 

to create-blocks
  let x 0
  let l 0
  let c 0
  let blocksize 6
  while [l < max-pycor] [
    let k 0
    while [k < max-pxcor] [
      let i 0
      set x x + 1
      while [i < blocksize]
      [
        let j 0
        while [j < blocksize] [
          let mp patch (k + i) (l + j)
          ask mp [ifelse c = 0 [set blockname x] [set blockname x]]
          set j j + 1
        ]
        set i i + 1
      ]
      ifelse c = 0 [set c 1] [set c 0]
      set k k + blocksize
    ]
    ifelse c = 0 [set c 1] [set c 0]
    set l l + blocksize
  ]
end 

to measure-segregation
  let i 1
  let blocksize 3
  ;let b count patches / blocksize ; blovk size 3*3
  set Tsi 0

  let A count aggressors
  let B count honors
  let C count institutionals
  let D count rationals
  while [i < 50] [
    let bpatches patch-set patches with [blockname = i]
    let aa sum [count aggressors-here ] of bpatches
    let bb sum [count honors-here ] of bpatches
    let cc sum [count institutionals-here] of bpatches
    let dd sum [count rationals-here] of bpatches

    let si abs((aa / A) - (bb / B) - (cc / C) - (dd / D))
    ;let si abs((bb / B) - (gg / G) )
    set Tsi Tsi + si
    set i i + 1
  ]
  set Tsi Tsi / 4
end 

There is only one version of this model, created over 1 year ago by Kashif Zia.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.