Togetherness

No preview image

1 collaborator

79107734_n00-1 Seth Tisue (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0RC6 • Viewed 338 times • Downloaded 20 times • Run 0 times
Download the 'Togetherness' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

http://www.hermetic.ch/pca/tg.htm

HOW IT WORKS

http://www.hermetic.ch/pca/algorithms.htm#tg

RELATED MODELS

Segregation
Voting

CREDITS AND REFERENCES

Thanks to Seth Tisue for his work on this model.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [average-togetherness]

to setup
  clear-all
  set-default-shape turtles "square"
  ask n-of (round (density * count patches)) patches
  [
    sprout 1
    [
      set color item (random num-colors) base-colors
    ]
  ]
  update-average
  reset-ticks
end 

to go
  repeat count patches
  [
    let t1 nobody
    while [t1 = nobody or [surrounded?] of t1]
    [
      set t1 one-of turtles
    ]
    ask t1
    [
      let p1 patch-here
      let p2 random-nearby
      let t2 one-of turtles-on p2
      ifelse t2 = nobody
      ;; case 1: move to empty patch?
      [
        let g gain p2
        if g >= 0 or (g = -1 and random lossy-move-chance = 0)
        [
          move-to p2
        ]
      ]
      ;; case 2: swap with turtle on occupied patch?
      [
        if color != [color] of t2 and
           not [surrounded?] of t2
        [
          let g gain p2 + [gain p1] of t2
          if g >= 0 or ((g = -1 or g = -2) and random lossy-move-chance = 0)
          [
            move-to p2
            ask t2 [ move-to p1 ]
          ]
        ]
      ]
    ]
  ]
  update-average
  tick
end 

to-report gain [new-patch]  ;; turtle procedure
  let c color
  let old count (turtles-on neighbors) with [color = c]
  let new count other (turtles-on [neighbors] of new-patch) with [color = c]
  report new - old
end 

to-report surrounded?  ;; turtle procedure
  report togetherness = 8
end 

;; picks a random patch from our Von Neumann neighborhood
;; in the radius set by the selection-range slider

to-report random-nearby  ;; patch procedure
  let x radius - random (2 * radius + 1)
  let y radius - random (2 * radius + 1)
  ifelse (x = 0 and y = 0) or (abs x + abs y > radius)
    [ report random-nearby ]
    [ report patch-at x y ]
end 

; Note: Is there a better way to write this last procedure?
; We're generating random offsets and then throwing out
; half of them as invalid; can't we directly pick
; valid offsets somehow? - ST 3/7/07

to-report togetherness ;; turtle procedure
  let c color
  report count (turtles-on neighbors) with [color = c]
end 

to update-average
  set average-togetherness mean [togetherness] of turtles
end 

There are 2 versions of this model.

Uploaded by When Description Download
Seth Tisue almost 13 years ago uses NL 5.0 now Download this version
Seth Tisue over 14 years ago Togetherness Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.