Mobile Aggregation Example

Mobile Aggregation Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner almost 12 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 541 times • Downloaded 75 times • Run 4 times
Download the 'Mobile Aggregation Example' 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

turtles-own [
  ;; The easiest way to handle the clusters is to designate one
  ;; node in the cluster as the "leader".  It doesn't really matter
  ;; which node it is; the choice is arbitrary, but it gives us a way
  ;; to identify the cluster.  Every node knows who the leader of
  ;; its cluster is.
  leader
  ;; This is used to make all of the nodes in a cluster turn by
  ;; the same number of degrees.  Each leader chooses a random
  ;; amount, then everyone else uses the amount from their leader.
  turn-amount
]

to setup
  clear-all
  set-default-shape turtles "circle"
  crt population
    [ set color red
      setxy random-xcor random-ycor
      rt random-float 360
      ;; initially, every node leads its own cluster of one
      set leader self ]
  reset-ticks
end 

to go
  ;; All the leaders choose turn amounts
  ask turtles with [leader = self] [
    set turn-amount random 10 - random 10
  ]
  ;; All nodes follow their leaders
  ask turtles [
    rt [turn-amount] of leader
    fd 0.1
  ]
  ;; Here's the tricky part. We check whether any pairs
  ;; of clusters are touching, and if they are, we merge them.
  ask turtles [
    let candidates turtles in-radius 1 with [leader != [leader] of myself]
    if any? candidates [
      create-links-with candidates [ hide-link ]
      ask candidates [ merge ]
    ]
  ]
  tick
end 

;; This is a recursive procedure -- it calls itself.
;; That way the new leader propagates through the entire
;; cluster.

to merge  ;; node procedure
  ;; First this node merges.
  set leader [leader] of myself
  set heading [heading] of leader
  set color blue
  ;; Then any neighboring nodes that haven't merged yet
  ;; merge.
  ask link-neighbors with [leader != [leader] of myself]
    [ merge ]
end 


; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Mobile Aggregation Example Download this version
Uri Wilensky over 14 years ago Mobile Aggregation Example Download this version

Attached files

File Type Description Last updated
Mobile Aggregation Example.png preview Preview for 'Mobile Aggregation Example' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.