Kuramoto model

Kuramoto model preview image

1 collaborator

Alonsela Alon Sela (Author)

Tags

Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.3.1 • Viewed 124 times • Downloaded 10 times • Run 0 times
Download the 'Kuramoto model' 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

;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;


turtles-own [
freq1
freq2
]

to setup
  clear-all
  ;set-default-shape turtles "circle"
  ;; make the initial network of two turtles and an edge
  make-node nobody        ;; first node, unattached
  make-node turtle 0      ;; second node, attached to first node
  reset-ticks
end 

;;;;;;;;;;;;;;;;;;;;;;;
;;; Main Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;

to go
  ;; new edge is green, old edges are gray
  ask links [ set color gray ]
  make-node find-partner         ;; find partner & use it as attachment
                                 ;; point for new node
  tick
  if layout? [ layout ]
end 

;; used for creating a new node

to make-node [old-node]
  crt 1
  [
    set color red
    set shape "arrow"
    set heading random 360
    set size 3
    set freq1 (random 100) / 10
    if old-node != nobody
      [ create-link-with old-node [ set color green ]
        ;; position the new node near its partner
        move-to old-node
        fd 8
      ]
  ]
end 

;; This code is the heart of the "preferential attachment" mechanism, and acts like
;; a lottery where each node gets a ticket for every connection it already has.
;; While the basic idea is the same as in the Lottery Example (in the Code Examples
;; section of the Models Library), things are made simpler here by the fact that we
;; can just use the links as if they were the "tickets": we first pick a random link,
;; and than we pick one of the two ends of that link.

to-report find-partner
  report [one-of both-ends] of one-of links
end 

;;;;;;;;;;;;;;
;;; Layout ;;;
;;;;;;;;;;;;;;

;; resize-nodes, change back and forth from size based on degree to a size of 1

to resize-nodes
  ifelse all? turtles [size <= 1]
  [
    ;; a node is a circle with diameter determined by
    ;; the SIZE variable; using SQRT makes the circle's
    ;; area proportional to its degree
    ask turtles [ set size sqrt count link-neighbors ]
  ]
  [
    ask turtles [ set size 1 ]
  ]
end 

to layout
  ;; the number 3 here is arbitrary; more repetitions slows down the
  ;; model, but too few gives poor layouts
  repeat 3 [
    ;; the more turtles we have to fit into the same amount of space,
    ;; the smaller the inputs to layout-spring we'll need to use
    let factor sqrt count turtles
    ;; numbers here are arbitrarily chosen for pleasing appearance
    layout-spring turtles links (1 / factor) (7 / factor) (1 / factor)
    display  ;; for smooth animation
  ]
  ;; don't bump the edges of the world
  let x-offset max [xcor] of turtles + min [xcor] of turtles
  let y-offset max [ycor] of turtles + min [ycor] of turtles
  ;; big jumps look funny, so only adjust a little each time
  set x-offset limit-magnitude x-offset 0.1
  set y-offset limit-magnitude y-offset 0.1
  ask turtles [ setxy (xcor - x-offset / 2) (ycor - y-offset / 2) ]
end 

to-report limit-magnitude [number limit]
  if number > limit [ report limit ]
  if number < (- limit) [ report (- limit) ]
  report number
end 

to-report sinheading [heading1 heading2]
     if debug?
        [write "from reporter " print heading1
         write "from reporter "  print heading2
         ]
     let temp1 sin(heading1 - heading2)
     report temp1
end 

to sync
  let k 0.5

  ask turtles [
    if debug? [type "$$$$$$$$$$$$$$$$$$$$$$$$$ : " print who]
    let n 0
    let sin-res 0
    let sigma 0
    let res 0

    fd 0.01
    display
    let my-heading heading
    ;show turtles
    let neig link-neighbors
    ask neig [
      if debug? [
        type "in 
neig-loop " ;show who write "
his heading= " print heading write "
my heading = "print my-heading ] set sin-res sinheading heading my-heading ;let sum-heading (sum-heading + sinheading ) set sigma (sigma + sin-res) set n (n + 1) if debug? [ write "sin-res= " print sin-res write "sigma = " print sigma ] ] set res (k / n * sigma) if debug? [ type "res= "print res ] rt res display fd 1 bk 1 ifelse (heading > 0 ) and (heading < 10) [set color yellow] [set color red] ] ask turtles [rt 1] end ; Copyright 2005 Uri Wilensky. ; See Info tab for full copyright and license.

There is only one version of this model, created over 2 years ago by Alon Sela.

Attached files

File Type Description Last updated
Kuramoto model.png preview Preview for 'Kuramoto model' over 2 years ago, by Alon Sela Download

This model does not have any ancestors.

This model does not have any descendants.