Helping_vs_Harming

Helping_vs_Harming preview image

1 collaborator

Default-person Joe Blass (Author)

Tags

(This model has yet to be categorized with any tags)
Parent of 1 model: Child of Helping_vs_Harming
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.2.0 • Viewed 262 times • Downloaded 31 times • Run 0 times
Download the 'Helping_vs_Harming' 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

;;; originally all the globals were able to be set by the user; too many damn parameters! 
;;; Now they are set in setup; the indicated settings provide some nice behavior
globals [
  number-of-turtles
  social-radius
  social-gain  
  life-expectancy
]

turtles-own [
  ;;; internal setting variables
  social-currency
  p-theft
  p-protect
  age
  my-life-expectancy
  num-neighbors
  
  ;;; color variables
  r
  g
  b
  
  ;;; turn variables
  take-action
  my-neighbors
  got-away?
  
  ;; reproduction variables
  can-breed?
  my-mateworthy-neighbors
  my-mate
    
  ;;; helper variables
  random-choice-num ;;; every turn a turtle uses random to pick what to do; this is so we can pick one random number per turn in the ifelse block
  my-count ;; this is just a placeholder variable; not at all necessary for logic but is handy to avoid retyping code blocks
  ]

to setup
  ;;; initialize world block
  ca
  
  if (protect-threshold < theft-threshold) [ ;;; verbose is just there to be able to turn this message off for behavior-space experiments
    if verbose? [user-message "Oops: the protection threshold must be larger than the theft threshold"]
    stop
  ]
  
  ;;; set globals to some nice defaults
  set number-of-turtles 300 ;;; This mostly affects how fast things change; doesnt majorly affect the outcome of the model
  set social-radius 10 ;;; if this is smaller turtles tend to die out quickly
  set life-expectancy 40 ;;; much less than 50 and turtles die out before reproducing; much more and everything just slows down. Might as well specify instead of making it user-set.
  set social-gain 8 ;;; NOTE: in a different model, social-gain would be a crucial parameter to vary! 
  ;;; However, in this model it doesn't make things that interesting, just move faster.
  ;;; I think this is because this model is set up such that it's a constant increment, that is, turtles only ever gain or lose
  ;;; a maximum of social-gain divided amongst neighbors, rather than from each neighbor. Also, social-currency is not a zero sum game 
  ;;; (since turtles are born with social-currency). I thought it made sense to hide it from the user for simplicity
   
  ask patches [ set pcolor grey ] ;;; turtles are initialized black and can end up white, so grey background is best
  
  ;;; set up run block
  crt number-of-turtles [
    ;;; initialize color and location. we are going to do some color math so we have to do this a little hamfistedly
    set r 0
    set g 0
    set b 0
    set color rgb r g b ;; everyone starts off green, randomly placed in the world, with equal social currency
    set size 2
    setxy random-xcor random-ycor
    
    ;; internal variables
    set can-breed? (social-currency > mate-threshold)
    set social-currency initial-social-currency
    set p-theft (theft-threshold - 5 + random 11) ;; everyone has their own theft threshold within 5 of the set threshold
    set p-protect (protect-threshold - 5 + random 11) ;; ditto protection threshold
    if p-theft >= p-protect [set p-theft (p-protect - 1)] ;; make sure p-theft < p-protect; this gives preference to protection rather than theft. call me old-fashioned.
    set age 0
    set my-life-expectancy (life-expectancy - 5 + random 11)
    set got-away? false
  ]
  
  reset-ticks
end 

to go
  if (count turtles = 0) [stop]
  if time-limit? ;; do we want the model to eventually halt?
  [ if (count turtles > 5000 or ticks > 1000) [stop]] 
  ;;; these population/tick limits were decided upon by seeing where the model 
  ;;; starts to slow down enormously and by which point clear trends have emerged.  Note that
  ;;; these settings are much larger than is normally needed to see those trends.
  
  ;;; first code block resets internals, moves the turtles, and picks what to do
  ask turtles [
    
    turn-reset ;;; resets internal variables
    ;;; move
    rt random 360 ;; turtles wiggle and move randomly
    fd 5 ;; take a few steps
    
    ;;; pick an action. Actions will actually happen during the resolution phase
    ;;; this does NOT have to happen after ALL the turtles have moved because they are just picking what
    ;;; they WILL do, they are not actually doing it yet
    set random-choice-num random 100
    ifelse (random-choice-num < p-theft) 
    [ set take-action "steal" 
      ifelse (random 100 < probability-of-getting-away) ;; if you steal, figure out whether you get away with it (independent of who's watching)
      [ set got-away? true]
      [ set got-away? false]]
    [ ifelse (random-choice-num < p-protect) ;; if we got here that means p-theft < choice-num < p-protect
      [ set take-action "do-nothing" ] ;; and we do nothing
      [ set take-action "protect" ] ;; otherwise we protect
    ]
  ]  
  
  ;;; resolve performs the actions and resolves the consequences
  ;;; has to happen after all turtles have moved and chosen their actions
  ask turtles [resolve] ;; within resolve, functions to actually perform actions are called
  
  ;;; update social currency and age and check to see if turtles die
  ;;; death here may be redundant with the fact that they die at the beginning of the turn.
  ask turtles [
    if (social-currency > 100) [ set social-currency 100 ]
    if (social-currency <= 0) [ die ] ;; turtles at zero die
    if (age > my-life-expectancy) [ die ]
    set age (age + 1)
  ]
  
  ask turtles [ if can-breed? [ reproduce-if-possible ]] ;;; after all actions are resolved, turtles reproduce if they can
  
  tick
end 

to turn-reset
    ;;; reset some information at each tick
    set my-mate false ;; reset mate info
    set got-away? false 
    set color rgb r g b ;;; reset color
    set can-breed? (social-currency > mate-threshold) ;;; reset breeding status
    set my-neighbors other turtles in-radius social-radius ;; figure out who your neighbors are
    set num-neighbors count my-neighbors
    ;;; turtles have the opportunity to die at the beginning and end of turns
    ;;; at the beginning in case they are too old
    ;;; at the end so that turtles about to die do not have a chance to reproduce
    if (social-currency <= 0) [ die ] ;; turtles at zero die
    if (age > my-life-expectancy) [ die ]
end 

;;; calls the particular resolution functions

to resolve
  ifelse (take-action = "steal")
  [ steal ]
  [ ifelse (take-action = "protect") 
    [ protect ]
    [ do-nothing ]
  ]
end 

to steal
  ;;; note that steal actually handles MOST of what happens to turtles, i.e., both thieves and protectors  
  ;;; in this implementation, a successful thief takes TOTAL social-gain divided amongst the victims. 
  ;;; another possibility would be to have it take a social-gain from EACH victim
  ifelse (got-away? or not any? my-neighbors with [take-action = "protect"]) ;; if no one is watching out for thieves or you get away with it
  [ if (num-neighbors > 0) ;; provided you have neighbors
    [ set social-currency (social-currency + social-gain) ;; get social-gain from chumpy neighbors
      ask my-neighbors [set social-currency (social-currency - (social-gain / [num-neighbors] of myself))] 
    ] ;; each neighbor loses social-gain/count neighbors
  ]    ;;; if you have no neighbors, don't sweat it, you do nothing.
     
  ;;; otherwise, someone is watching out for thieves AND you got caught
  [ set my-count (count my-neighbors with [take-action = "protect"])
    set social-currency (social-currency - social-gain) ;; lose social-gain
    ask my-neighbors with [take-action = "protect"]
      [ set social-currency (social-currency + (social-gain / [my-count] of myself))]  ;;; protectors don't each get social-gain, since the more protectors you have, the less each protection matters
  ]
  
  ;;; thieves turn redder regardless of whether they were successful in stealing or not.  That's because 
  ;;; color is only used as a visualization tool and to help the system track how many times turtles
  ;;; have ATTEMPTED a particular action.
  ifelse (r < 230)
    [ set r (r + 25) ]
    [ set r 255 ]
end 

to protect
  ;;; catching thieves is handled by the steal function
  set my-count (count my-neighbors with [take-action = "steal" and not got-away?])
  if (my-count = 0) ;; if none of your neighbors tried to steal and did not get away with it, then you are being a busybody
    [ set social-currency (social-currency - social-gain) ;; lose social-gain 
      ask my-neighbors [set social-currency (social-currency + (social-gain / [num-neighbors] of myself))]
    ] ;;; all your neighbors are smugly satisfied with themselves and each other
  
  ;;; otherwise, someone has tried to steal
  ;;; but we don't have to do anything because it is handled by the steal function
  
  ;;; protectors turn bluer
  ifelse (b < 230) ;;; turtles who are protectors turn bluer
  [ set b (b + 25) ]
  [ set b 255 ]
end 

to do-nothing
  ;;; the only thing we need to do within this function is change the color a bit
  ;;; gaining or losing social value is handled by other functions.
  ifelse (g < 230) ;;; show the turtle's guilt by turning it redder
  [ set g (g + 25) ]
  [ set g 255 ]
end 

to reproduce-if-possible
  ;; only called by turtles who can reproduce, so we don't have to check within the function
  set my-mateworthy-neighbors my-neighbors with [can-breed? and (my-mate = false)] ;; my-mate is set to false at the beginning of each tick
  if any? my-mateworthy-neighbors
  [ set my-mate max-one-of my-mateworthy-neighbors [social-currency]
    ask my-mate [ set my-mate true ] 
    ;;; I know it's a bit odd to have the my-mate variable be a combination of booleans and agents, but this should still work
    ;;; the point is to have my-mate bound or not. We do it this way so that turtles don't mate twice per turn
    hatch 1 [
      set social-currency initial-social-currency
      set p-protect ((([p-protect] of myself + [p-protect] of [my-mate] of myself) / 2) - 5 + random 11) ;; average p-protect of parents, plus some randomness
      set p-theft ((([p-theft] of myself + [p-theft] of [my-mate] of myself) / 2) - 5 + random 11) ;; average p-theft of parents, plus some randomness
      if p-theft >= p-protect [set p-theft (p-protect - 1)] ;; make sure p-theft < p-protect; this gives preference to protection rather than theft. call me old-fashioned.
      set age 0
      set my-life-expectancy ((([my-life-expectancy] of myself + [my-life-expectancy] of [my-mate] of myself) / 2) - 5 + random 11)
      set got-away? false
      
      ;;; placement and color
      set r 0
      set g 0
      set b 0
      set color rgb r g b ;; no matter who your parents are, you start off innocent
      ;;; move a little
      rt random 360
      fd 3
    ]
  ]
end 

;;; reporters for charts

to-report proportion-of-thieving-turtles
  ifelse (count turtles = 0)
  [report 0]
  [ report count turtles with [r > 250] / count turtles]
end 

;;; next three reporters count the proportion of turtles of each "type"
;;; a turtle is of a type if they have performed a particular action ten times
;;; since each color starts at 0 and adds 25 each time an action is taken, we can 
;;; count types by seeing who has a color > 250.
;;; note that these will not sum to 1, since turtles are not necessarily of ANY type

to-report proportion-of-protector-turtles
  ifelse (count turtles = 0)
  [report 0]
  [ report count turtles with [b > 250] / count turtles]
end 

to-report proportion-of-placid-turtles
  ifelse (count turtles = 0)
  [report 0]
  [ report count turtles with [g > 250] / count turtles]
end 

to-report proportion-of-mixed-turtles
  ifelse (count turtles = 0)
  [report 0]
  [ report count turtles with [(r > 250) and (b > 250)] / count turtles]
end 

;;; next three reporters count the number of turtles who performed each of the three actions.

to-report turtles-who-just-stole
  report count turtles with [take-action = "steal"]
end 

to-report turtles-who-just-protected
  report count turtles with [take-action = "protect"]
end 

to-report turtles-who-just-did-nothing
  report count turtles with [take-action = "do-nothing"]
end 

;;; next three reporters count proportion of turtles who performed each of the three actions.
;;; they use the above three reporters.
;;; since all turtles do one of the three, these three values will always sum to 1.

to-report proportion-turtles-who-just-stole
  ifelse (count turtles = 0)
  [report 0]
  [ report turtles-who-just-stole / count turtles]
end 

to-report proportion-turtles-who-just-protected
  ifelse (count turtles = 0)
  [report 0]
  [ report turtles-who-just-protected / count turtles]
end 

to-report proportion-turtles-who-just-did-nothing
  ifelse (count turtles = 0)
  [report 0]
  [ report turtles-who-just-did-nothing / count turtles]
end 

;;; these next five reporters are for charts that are no longer included, but there was no reason to delete 
;;; the functions themselves.  If others want to visualize the breeding population, the functions are here.

;;; reports how many turtles can breed

to-report num-turtles-that-can-breed
  ifelse (count turtles = 0)
  [report 0]
  [ report count turtles with [can-breed?]]
end 

;;; uses previous reporter to report what proportion of all turtles can breed

to-report proportion-breeding-turtles
  ifelse (count turtles with [can-breed?] = 0)
  [report 0]
  [report ((count turtles with [can-breed?]) / count turtles)]
end 

;;; next three reporters report on the actions taken last turn by the turtles that can breed.
;;; ultimately these results are very similar to the overall actions taken so were not included.

to-report proportion-thieving-breeders
  ifelse (count turtles with [can-breed?] = 0)
    [report 0]
    [report ((count turtles with [can-breed? and (take-action = "steal")]) / num-turtles-that-can-breed)]
end 

to-report proportion-protecting-breeders
  ifelse (count turtles with [can-breed?] = 0)
    [report 0]
    [report ((count turtles with [can-breed? and (take-action = "protect")]) / num-turtles-that-can-breed)]
end 

to-report proportion-complacent-breeders
  ifelse (count turtles with [can-breed?] = 0)
    [report 0]
    [report ((count turtles with [can-breed? and (take-action = "do-nothing")]) / num-turtles-that-can-breed)]
end 

There are 8 versions of this model.

Uploaded by When Description Download
Joe Blass almost 9 years ago Final version of model (info tab updated) Download this version
Joe Blass almost 9 years ago Reverted to older version Download this version
Joe Blass almost 9 years ago Reverted to older version Download this version
Joe Blass almost 9 years ago Reverted to older version Download this version
Joe Blass almost 9 years ago Final version of Helping vs. Harming model Download this version
Joe Blass almost 9 years ago First version of Exploitation vs. Protection model Download this version
Joe Blass almost 9 years ago Final version of Helping vs. Harming model Download this version
Joe Blass almost 9 years ago Initial upload Download this version

Attached files

File Type Description Last updated
Blass Poster Ad.pdf pdf Poster slam slides almost 9 years ago, by Joe Blass Download
Blass_ABM_FinalProj_Poster.pdf pdf Final Project Poster: These sheets will be arranged in three columns of four sheets. first slide is a title. These slides are read by column, not by row almost 9 years ago, by Joe Blass Download
Blass_Final_Proj_Proposal-v2.docx word updated design document almost 9 years ago, by Joe Blass Download
Blass_Final_Proj_Proposal-v3.docx word Final Design Document almost 9 years ago, by Joe Blass Download
Blass_Final_Proj_Proposal.docx word final project design document almost 9 years ago, by Joe Blass Download
Blass_Final_Project_ABM_2015_v2.docx word Final Project Report almost 9 years ago, by Joe Blass Download
Blass_Poster.pptx powerpoint poster almost 9 years ago, by Joe Blass Download
Blass_status_update_5.18.docx word final project status update 1 almost 9 years ago, by Joe Blass Download
Blass_status_update_5.25.docx word status update 2 almost 9 years ago, by Joe Blass Download
Blass_status_update_6.1.docx word Final status update almost 9 years ago, by Joe Blass Download
Helping_vs_Harming.png preview Preview for 'Helping_vs_Harming' almost 9 years ago, by Joe Blass Download
Modeling Exploitative vs Protective Behavior_Blass_ABM2015 Final Project.pdf pdf Final Project Report almost 9 years ago, by Joe Blass Download

This model does not have any ancestors.

Children:

Graph of models related to 'Helping_vs_Harming'