Final v.0

Final v.0 preview image

1 collaborator

Default-person Noah Conley (Author)

Tags

(This model has yet to be categorized with any tags)
Model group MAM-2013 | Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 198 times • Downloaded 28 times • Run 0 times
Download the 'Final v.0' 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

globals [
  minimum-separation
  max-separate-turn
  max-align-turn
  max-cohere-turn
  max-avoid-turn
  vision
  current-tolerance
  current-watch
]

turtles-own [
  surface-attitude
  embedded-attitude
  embedded-strength
  surface-similars
  nearest-surface-similar
  surface-differents
  nearest-surface-different
  embedded-similars
  nearest-embedded-similar
  embedded-differents
  nearest-embedded-different
  tolerance-ratio
]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; setup
;; sets up all the parameters and turtles for the model.  sets up the 
;; variables that aren't currently in use, but may become active later.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  ca
  crt population [
    setxy random-xcor random-ycor
    if display-type = "Surface"
    [
      set size 3
      ifelse possible-surface = 38
      [ set shape one-of shapes ]
      [ set shape one-of sublist shapes 0 possible-surface ]
      set surface-attitude shape
      if possible-embedded < 14
      [ set color one-of sublist base-colors 0 possible-embedded ]
      set embedded-attitude color
      set embedded-strength 1 / e ^ (15 / 4) + random-float e ^ (25 / 4)
      set tolerance-ratio 0
    ]
    if display-type = "Embedded"
    [
      set embedded-strength 1 / e ^ (15 / 4) + random-float e ^ (25 / 4)
      set size .4 * ln embedded-strength + 2.5
      set shape "circle"
      if possible-embedded < 14
      [ set color one-of sublist base-colors 0 possible-embedded ]
      set embedded-attitude color
      ifelse possible-surface = 38
      [ set surface-attitude one-of shapes ]
      [ set surface-attitude one-of sublist shapes 0 possible-surface ]
      set tolerance-ratio 0
    ]
    if display-type = "Both"
    [
      set embedded-strength 1 / e ^ (15 / 4) + random-float e ^ (25 / 4)
      set size .4 * ln embedded-strength + 2.5
      ifelse possible-surface = 38
      [ set shape one-of shapes ]
      [ set shape one-of sublist shapes 0 possible-surface ]
      if possible-embedded < 14
      [ set color one-of sublist base-colors 0 possible-embedded ]
      set embedded-attitude color
      set surface-attitude shape
      set tolerance-ratio 0
    ]
  ]
  
  ;; flocking details set based on current tolerance level
  set current-tolerance tolerance
  set minimum-separation (current-tolerance / 20 + 3)
  set max-align-turn ((100 - current-tolerance) / 5)
  set max-separate-turn (current-tolerance / 5)
  set max-cohere-turn ((100 - current-tolerance) / 5)
  set max-avoid-turn ((100 - current-tolerance) / 5)
  
  set vision 10
  
  set current-watch "" ;; turtle being watched (none at beginning)
  
  reset-ticks
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; go
;; default way to run the model.  modifies the tolerance if there's a change,
;; gives orders to the turtles based on the current display state.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  if current-tolerance != tolerance
  [
    set current-tolerance tolerance
    set minimum-separation (current-tolerance / 20 + 6)
    set max-align-turn ((100 - current-tolerance) / 5)
    set max-separate-turn (current-tolerance / 5)
    set max-cohere-turn ((100 - current-tolerance) / 5)
    set max-avoid-turn ((100 - current-tolerance) / 5)
  ]
  ask turtles
  [
    if display-type = "Surface" 
    [ 
      surface-behavior
      surface-movement
    ]
    if display-type = "Embedded"
    [
      embedded-behavior
      embedded-movement
    ]
    if display-type = "Both"
    [
      embedded-behavior
      surface-behavior
      combined-movement
    ]
  ]
  repeat 5 [ ask turtles [ fd .1 ] display ]
  plot-ratio 
  tick
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; avoid-minority
;; makes a list of all turtles based on color and singles out those in the
;; smallest gorup.  tells the other turtles to behave normally towards each
;; other, but avoid the smallest group with 0% tolerance.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to avoid-minority
  let smallest first first sort-by [last ?1 < last ?2] filter [last ? > 0] n-values 140 [ (list ? count turtles with [ color = ? ] )]
  if current-tolerance != tolerance
  [
    set current-tolerance tolerance
    set minimum-separation (current-tolerance / 20 + 6)
    set max-align-turn ((100 - current-tolerance) / 5)
    set max-separate-turn (current-tolerance / 5)
    set max-cohere-turn ((100 - current-tolerance) / 5)
    set max-avoid-turn ((100 - current-tolerance) / 5)
  ]
  ask turtles
  [
    if display-type = "Surface" 
    [ 
      surface-behavior
      surface-movement
    ]
    if display-type = "Embedded"
    [
      embedded-behavior
      embedded-movement
    ]
    if display-type = "Both"
    [
      embedded-behavior
      surface-behavior
      combined-movement
    ]
  ]
  
  ask turtles with [color != smallest]
  [
    set current-tolerance 0
    set minimum-separation (current-tolerance / 20 + 6)
    set max-align-turn ((100 - current-tolerance) / 5)
    set max-separate-turn (current-tolerance / 5)
    set max-cohere-turn ((100 - current-tolerance) / 5)
    set max-avoid-turn ((100 - current-tolerance) / 5)
    if display-type = "Embedded"
    [
      if any? embedded-differents
      [
        set embedded-differents embedded-differents with [color = smallest]
        if any? embedded-differents
        [
          find-nearest-embedded-different
          if distance nearest-embedded-different < minimum-separation * 2
          [ avoid-embedded ]
        ]
      ]
    ]
    if display-type = "Both"
    [
      if any? embedded-differents
      [
        set embedded-differents embedded-differents with [color = smallest]
        if any? embedded-differents
        [
          find-nearest-embedded-different
          if distance nearest-embedded-different < minimum-separation * 2
          [ avoid-embedded ]
        ]
      ]
    ]
  ]
  repeat 5 [ ask turtles [ fd .1 ] display ]
  plot-ratio
  tick
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; avoid-majority
;; makes a list of all turtles based on color and singles out those in the
;; largest gorup.  tells the other turtles to behave normally towards each
;; other, but avoid the largest group with 0% tolerance.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to avoid-majority
  let largest first first sort-by [last ?1 > last ?2] filter [last ? > 0] n-values 140 [ (list ? count turtles with [ color = ? ] )]
  if current-tolerance != tolerance
  [
    set current-tolerance tolerance
    set minimum-separation (tolerance / 20 + 6)
    set max-align-turn ((100 - current-tolerance) / 5)
    set max-separate-turn (tolerance / 5)
    set max-cohere-turn ((100 - current-tolerance) / 5)
    set max-avoid-turn ((100 - current-tolerance) / 5)
    set vision 10
  ]
  ask turtles
  [
    if display-type = "Surface" 
    [ 
      surface-behavior
      surface-movement
    ]
    if display-type = "Embedded"
    [
      embedded-behavior
      embedded-movement
    ]
    if display-type = "Both"
    [
      embedded-behavior
      surface-behavior
      combined-movement
    ]
  ]
  
  ask turtles with [color != largest]
  [
    set current-tolerance 0
    set minimum-separation (current-tolerance / 20 + 6)
    set max-align-turn ((100 - current-tolerance) / 5)
    set max-separate-turn (current-tolerance / 5)
    set max-cohere-turn ((100 - current-tolerance) / 5)
    set max-avoid-turn ((100 - current-tolerance) / 5)
    if display-type = "Embedded"
    [
      if any? embedded-differents
      [
        set embedded-differents embedded-differents with [color = largest]
        if any? embedded-differents
        [
          find-nearest-embedded-different
          if distance nearest-embedded-different < minimum-separation * 2
          [ avoid-embedded ]
        ]
      ]
    ]
    if display-type = "Both"
    [
      if any? embedded-differents
      [
        set embedded-differents embedded-differents with [color = largest]
        if any? embedded-differents
        [
          find-nearest-embedded-different
          if distance nearest-embedded-different < minimum-separation * 2
          [ avoid-embedded ]
        ]
      ]
    ]
  ]
  repeat 5 [ ask turtles [ fd .1 ] display ]
  plot-ratio
  tick
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; surface-behavior
;; controls how the turtles behave in Surface mode.  they only keep track of
;; their surface attitude, represented by shape.  they have the chance to
;; randomly change on their own, or if they share a patch with a turtle of a
;; different shape, they have the chance to copy their surface attitude
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to surface-behavior
  let x random 100
  ifelse count other turtles-here != 0 and [surface-attitude] of one-of other turtles-here != [surface-attitude] of self
  [ 
    ifelse x < 10 [
      set surface-attitude [surface-attitude] of one-of other turtles-here
    ]
    [ 
      if x < 15
      [  
        ifelse possible-surface = 38
        [ set surface-attitude one-of shapes ]
        [ set surface-attitude one-of sublist shapes 0 possible-surface ]
      ]
    ]
  ]
  [ 
    if x < 55
    [  
      ifelse possible-surface = 38
      [ set surface-attitude one-of shapes ]
      [ set surface-attitude one-of sublist shapes 0 possible-surface ]
    ]
  ]
  set shape surface-attitude
  if display-type = "Surface" [ set size 3 ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; embedded-behavior
;; controls how the turtles behave in Embedded mode.  they only keep track of
;; their embedded attitude, represented by size and color.  they change based
;; on random interaction with other turtles.  they grow, shrink, or change
;; color based on chance and the color and size of the turtle they're with.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to embedded-behavior
  if count other turtles-here != 0
  [
    let t one-of other turtles-here
    let x random 100
    ifelse [embedded-attitude] of t = [embedded-attitude] of self
    [
      ifelse [size] of t - [size] of self > 2
      [
        ifelse x < 5
        [ set embedded-strength embedded-strength - .2 ]
        [
          if x < 10
          [ set embedded-strength embedded-strength + .1 ]
        ]
      ]
      [ if x < 5
        [ set embedded-strength embedded-strength + .1 ]
      ]
    ]
    [ 
      ifelse abs ([embedded-attitude] of self - [embedded-attitude] of t) < current-tolerance / 10
      [
        ifelse x < 5
        [
          set embedded-attitude [embedded-attitude] of t
          set embedded-strength embedded-strength + .4 * -1 ^ random 1
        ]
        [ 
          if x < 25
          [ set embedded-strength embedded-strength + .2 * -1 ^ random 1 ]
        ]
      ]
      [
        ifelse size < 2
        [
          ifelse x < 5
          [
            set embedded-attitude [embedded-attitude] of t
            set embedded-strength embedded-strength + .2
          ]
          [
            ifelse x < 20 [ set embedded-strength embedded-strength + .1 ] 
            [ if x < 42 [ set embedded-strength embedded-strength - .2 ] ] 
          ]
        ]
        [
          ifelse x < 1
          [
            set embedded-attitude [embedded-attitude] of t
            set embedded-strength embedded-strength + .8 * -1 ^ random 1
          ]
          [
            ifelse x < 31
            [
              set embedded-strength embedded-strength + .1
            ]
            [
              if x < 1 [ set embedded-strength embedded-strength - .4 ]
            ]
          ]
        ]
      ]
    ]
  ]
  
  if is-agentset? embedded-similars and is-agentset? embedded-differents and count embedded-differents != 0
  [ set tolerance-ratio count embedded-similars / count embedded-differents ]
  
  if embedded-strength < 1 / e ^ 4 [ set embedded-strength 1 / e ^ 4 ]
  if embedded-strength > e ^ 12 [ set embedded-strength e ^ 12 ]
  if display-type = "Embedded" [ set shape "circle" ]
  set size  .4 * ln embedded-strength + 2.5
  set color embedded-attitude
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; surface-movement
;; controls how the turtles move in Surface mode.  normally they move in a
;; straight line, but as tolerance gets lower, the chance that they will
;; follow flocking rules increases
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to surface-movement
  if random 100 < 100 - current-tolerance
  [
    find-surface-similars
    if any? surface-similars
    [ 
      find-nearest-surface-similar
      ifelse distance nearest-surface-similar < minimum-separation
      [ separate-surface ]
      [ 
        align-surface
        cohere-surface
      ]
    ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; embedded-movement
;; controls how the turtles move in Embedded mode.  turtles are always
;; affected by tolerance, but the flocking rules become more relaxed as level
;; of tolerance increases.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to embedded-movement
  find-embedded-similars
  if any? embedded-similars
  [ 
    find-nearest-embedded-similar
    ifelse distance nearest-embedded-similar < minimum-separation
    [ separate-embedded ]
    [ 
      align-embedded
      cohere-embedded
    ]
  ]
  
  find-embedded-differents
  if any? embedded-differents
  [
    find-nearest-embedded-different
    if distance nearest-embedded-different < minimum-separation * 2
    [ avoid-embedded ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; combined-movement
;; controls how the turtles move in Both mode.  surface and embedded behavior
;; are present, so rules for both modes are followed simultaneously.
;; surface rules are evaluated first because they are less important.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to combined-movement
  if random 100 < 100 - current-tolerance
  [
    find-surface-similars
    if any? surface-similars
    [ 
      find-nearest-surface-similar
      ifelse distance nearest-surface-similar < minimum-separation
      [ separate-surface ]
      [ 
        align-surface
        cohere-surface
      ]
    ]
  ]
  
  find-embedded-similars
  if any? embedded-similars
  [ 
    find-nearest-embedded-similar
    ifelse distance nearest-embedded-similar < minimum-separation
    [ separate-embedded ]
    [ 
      align-embedded
      cohere-embedded
    ]
  ]
  
  find-embedded-differents
  if any? embedded-differents
  [
    find-nearest-embedded-different
    if distance nearest-embedded-different < minimum-separation * 2
    [ avoid-embedded ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; flocking rules
;; there are two compies of almost every method below, one for surface, one
;; for embedded.  there are some differences, such as how turtles don't care
;; about finding turtles with different surface attitudes from themsevles,
;; because surface attitudes are more specific and diverse than embedded
;; attitudes.  Most of these are similar to the functions in the focking
;; model in the models library, the biggest difference is finding differents
;; and avoiding those differents.  These funcitons are similar to separating
;; from similars
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to find-surface-similars
  set surface-similars other turtles with [surface-attitude = [surface-attitude] of myself] in-radius vision
end 

to find-embedded-similars
  set embedded-similars other turtles with
  [
    color - current-tolerance / 10 < [color] of myself and color + current-tolerance / 10 > [color] of myself
  ]
  in-radius vision
end 

to find-embedded-differents
  set embedded-differents other turtles with
  [
    color - current-tolerance / 10 < [color] of myself and color + current-tolerance / 10 < [color] of myself
  ]
  in-radius vision
end 

to find-nearest-surface-similar
  set nearest-surface-similar min-one-of surface-similars [distance myself]
end 

to find-nearest-embedded-similar
  set nearest-embedded-similar min-one-of embedded-similars [distance myself]
end 

to find-nearest-embedded-different
  set nearest-embedded-different min-one-of embedded-differents [distance myself]
end 

to separate-surface
  turn-away ([heading] of nearest-surface-similar) max-separate-turn
end 

to separate-embedded
  turn-away ([heading] of nearest-embedded-similar) max-separate-turn
end 

to avoid-embedded
  turn-away ([heading] of nearest-embedded-different) max-avoid-turn
end 

to align-surface
  turn-towards average-similar-surface-heading max-align-turn
end 

to align-embedded
  turn-towards average-similar-embedded-heading max-align-turn
end 

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

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

to cohere-surface
  turn-towards average-heading-towards-surface-similars max-cohere-turn
end 

to cohere-embedded
  turn-towards average-heading-towards-embedded-similars max-cohere-turn
end 

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

to-report average-heading-towards-embedded-similars
  let x-component mean [sin (towards myself + 180)] of embedded-similars
  let y-component mean [cos (towards myself + 180)] of embedded-similars
  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 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; plot-ratio
;; plots the ratio of similars to differents the turtles observe when on
;; Embedded or Both mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to plot-ratio
  set-current-plot "local area ratio"
  let x 0
  ask turtles
  [ set x x + tolerance-ratio ]
  plot x / population
end 

There are 7 versions of this model.

Uploaded by When Description Download
Noah Conley almost 11 years ago Attitude and Behavior Download this version
Noah Conley almost 11 years ago Attitudes and Behavior Download this version
Noah Conley almost 11 years ago Attitudes and Behavior Download this version
Noah Conley almost 11 years ago Attitudes and Behavior Download this version
Noah Conley almost 11 years ago Version 2 Download this version
Noah Conley almost 11 years ago v.1.0 Download this version
Noah Conley almost 11 years ago Initial upload Download this version

Attached files

File Type Description Last updated
Final v.0.png preview Preview image almost 11 years ago, by Noah Conley Download
NoahConley_Design_Proposal.pdf word Initial Design Proposal almost 11 years ago, by Noah Conley Download
NoahConley_Progress_Report_1.pdf word Progress Report 1 almost 11 years ago, by Noah Conley Download
NoahConley_Progress_Report_2.pdf word Progress Report 2 almost 11 years ago, by Noah Conley Download
NoahConley_Progress_Report_3.pdf word Progress Report 3 almost 11 years ago, by Noah Conley Download
NoahConley_Progress_Report_4.pdf word Progress Report 4 almost 11 years ago, by Noah Conley Download

This model does not have any ancestors.

This model does not have any descendants.