Homophily- Jiawei Fu- Version 2

Homophily- Jiawei Fu- Version 2 preview image

1 collaborator

Default-person Jiawei Fu (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.2.0 • Viewed 241 times • Downloaded 27 times • Run 0 times
Download the 'Homophily- Jiawei Fu- Version 2' 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

Turtles-own [wealth]
globals[number-homophily]
extensions[nw]

to setup
  clear-all
  nw:set-context turtles links
  ask patches [set pcolor white]
  create-turtles number-of-nodes [
    set wealth Random 10
    set shape "circle"
    set color scale-color green wealth -5 12
    set size 1
    setxy random-xcor random-ycor]
  reset-ticks
end 

to go
  ask links [set color gray]
  ask one-of turtles [
  make-node-homophily find-partner wealth] ;
  tick
  if layout? [layout]
  if number-homophily >= number-of-links [stop]
end 

to make-node-homophily [node]
  if node != nobody
  [
        create-link-with node [set color red]
        move-to node
        fd 8
  ]
        set number-homophily number-homophily + 1
end 

to-report find-partner [W]
 report one-of other turtles with [wealth = W or wealth = W - 1 or wealth = W + 1]
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) (10 / factor) (10 / 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 

There is only one version of this model, created over 9 years ago by Jiawei Fu.

Attached files

File Type Description Last updated
Homophily- Jiawei Fu- Version 2.png preview Preview for 'Homophily- Jiawei Fu- Version 2' over 9 years ago, by Jiawei Fu Download

This model does not have any ancestors.

This model does not have any descendants.