Rumors on Your Network
No preview image
Model was written in NetLogo 5.1.0
•
Viewed 388 times
•
Downloaded 33 times
•
Run 0 times
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
extensions [ nw ] turtles-own [ ;; facebook data id name centrality ;; infection variables infected? heard-from ] directed-link-breed [tests test] links-own [ weight ] to load-graph clear-all ;; Hard-code your path if you don't want to get prompted every time: ;; let filename user-file "/path/to/your-network.graphml" let filename user-file if (filename != false) [ nw:load-graphml filename [ set infected? false set shape "circle" ] nw:set-context turtles links ] let no-of-components length (sentence nw:weak-component-clusters) ifelse no-of-components > 0 [let degrees-separated 360 / no-of-components let counter 0 foreach nw:weak-component-clusters [ let biggest-component-size max map [count ?] nw:weak-component-clusters if count ? != biggest-component-size [ask turtle-set ? [die]] ] reset-ticks ] [ user-message "No network was loaded, please try again." ] end to remove-most-central ask max-one-of turtles [ count my-links ] [ die ] nw:set-context turtles links end to update-layout layout-spring turtles links 0.2 .1 1 end to toggle-labels ;; if any have a label, turn off all labels ifelse any? turtles with [label != ""] [ ask turtles [set label ""] ] [ let the-number-of-turtles count turtles * (100 - label-threshold) / 100 ask max-n-of the-number-of-turtles turtles [size] [set label name] ] end to calc-centrality if centrality-measure = "random" [ ask turtles [set size random 14 + 1] stop ] if centrality-measure = "reset-size" [ ask turtles [set centrality 1 set size 1] stop ] if centrality-measure = "degree-centrality" [ ask turtles [set centrality count my-links] ask turtles [set size 10 * (normalize centrality min [centrality] of turtles max [centrality] of turtles)] stop ] let the-task (word "set centrality nw:" centrality-measure) ask turtles [run the-task] ask turtles [set size 10 * (normalize centrality min [centrality] of turtles max [centrality] of turtles)] end ;; -------------------------------- ;; ;; New code for the infection logic ;; ;; -------------------------------- ;; globals [ max-infections ;; number of people that you can infect points ;; number of points current-payoff last-infected ] to setup clear-all-plots ask turtles [ set infected? false set label "" set color white set size 3 ] ask links [ set thickness 1 set color grey ] set last-infected nobody ;; set current pay off to 100 set current-payoff 100 ;; this is the maximum number of turtles the user can ;; infect before the model runs set max-infections 5 reset-ticks end to undo ask last-infected [ set infected? false set color white set current-payoff 100 ] show (word [name] of last-infected " did not hear the rumor!") end to touch-infect let the-patch patch mouse-xcor mouse-ycor if mouse-down? and any? [turtles-here] of the-patch [ ask one-of [turtles-here] of the-patch [infect-me-initially] stop ] end to go tick infect ;; count down on current-payoff to keep track of points set current-payoff current-payoff * .9 ;; if all infected, stop if all? turtles [ infected? ] [ stop ] wait 2 end to infect ask turtles with [ infected? ] [ ;; infect at probability .5 ask link-neighbors with [ not infected? ] [ if random-float 100 < chance-of-spread [ set heard-from myself ask link-with myself [ set color pink set thickness 1 ] infect-me ] ] ] end ;; initial infection procedures to infect-by-centrality ifelse centrality-measure = "random" [ ask one-of turtles with [ not infected? ] [infect-me-initially] ] [ calc-centrality ask max-one-of turtles with [ not infected? and centrality != false] [ centrality ] [ infect-me-initially ] ] end to infect-by-name let the-named-turtles turtles with [member? person-name name and not infected?] if count the-named-turtles > 10 [ user-message "There are too many people with that name. Be more specific." stop ] if count the-named-turtles > 1 [ let the-name user-one-of "Which person do you want to tell?" [name] of the-named-turtles ask one-of turtles with [name = the-name][infect-me-initially] ] if count the-named-turtles = 1 [ ask the-named-turtles [infect-me-initially] ] if count the-named-turtles = 0 [ user-message (word "Either there is no person named \"" person-name "\" or they already heard the rumor.") ] end to update-color ifelse infected? [ set color red ] [ set color blue ] end to infect-me-initially ifelse count turtles with [ infected? ] < max-infections [ infect-me set heard-from "you" set points 0 show (word "You told " name " the rumor!") ] [ user-message "You have already told five people. Start the model now." ] end to infect-me set infected? true set color red set size 3 set points points + current-payoff set last-infected self end ; this normalizes a number to-report normalize [value the-min the-max] set the-min ifelse-value (the-min = 0) [.001] [the-min] let normalized (value - the-min) / (the-max - the-min) report normalized end to kill-smaller-components let the-component [] foreach nw:weak-component-clusters [ if length ? > length the-component [set the-component ?] ] set the-component (turtle-set the-component) show count the-component ask turtles with [not member? self the-component] [die] end ;; turtle procedure to show-centralities show (word "Name: " name ", degree: " count my-links ", betweenness: " nw:betweenness-centrality ", closeness: " nw:closeness-centrality ", eigenvector:" nw:eigenvector-centrality ", page-rank: " nw:page-rank) end ;; THE FOLLOWING PROCEDURES ONLY WORK AFTER THE RUMOR MODEL HAS RUN ITS COURSE ;; turtle procedure that shows who a turtle heard it all from to-report show-rumor-path let rumor-path (list) report (word name " heard it from " reduce word show-rumor rumor-path) end ;; helper procedure for above procedure to-report show-rumor [rumor-path] if heard-from != nobody[ set rumor-path lput (word [name] of heard-from ", who heard it from ") rumor-path report [show-rumor rumor-path] of heard-from ] report lput " you!" rumor-path end ;; turtle procedure that returns a LIST (rather than string like the procedures above) of who told whom to-report the-rumor-path-list let rumor-path (list self) report show-rumor-list rumor-path end ;; helper for above to-report show-rumor-list [rumor-path] ifelse heard-from != "you" [ set rumor-path lput heard-from rumor-path report [show-rumor-list rumor-path] of heard-from ] [ report rumor-path ] end ;; observer procedure that breaks apart the graph and reconstructs a graph based on who heard the rumor from whom. to illustrate-rumor-paths ;; resize all turtles ask turtles [set size 3 set label ""] ;; only do this if we have run the model and all turtles have it the rumor if any? turtles with [not infected?] [ user-message "You can't do this until you have run the model." stop ] ;; get all the rumor paths let the-rumor-paths [the-rumor-path-list] of turtles ask links [die] ;; iterate over them foreach the-rumor-paths [ let the-rumor ? ;; ask the last turtle in each rumor list to show their name - that is the person that the learner told initially ask last the-rumor [set label name] ;; build links while [length the-rumor >= 2][ ask item 1 ? [create-link-to item 0 ?] set the-rumor butfirst the-rumor ] ] end ;; this reports those who only heard the rumor but never told anyone to-report last-to-hear report turtles with [count my-out-links = 0] end ;; this reports those that heard it from the those who were intitially told to-report first-to-hear report turtle-set [out-link-neighbors] of initially-infected end ;; this reports those that heard it from the learner to-report initially-infected report turtles with [count my-in-links = 0] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Layouts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to redo-layout [ forever? ] repeat ifelse-value forever? [ 1 ] [ 50 ] [ layout-spring turtles links 1 (80 / 1) (1 / 1) display if not forever? [ wait 0.005 ] ] end to layout-once redo-layout false end to spring-forever redo-layout true end
There is only one version of this model, created over 10 years ago by David Weintrop.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
dweintrop.graphml | data | GraphML Example | over 10 years ago, by David Weintrop | Download |
This model does not have any ancestors.
This model does not have any descendants.