# Collective Equilibrium Selection via Pure Coordination

No preview image

Model was written in NetLogo 6.0
•
Viewed 118 times
•
Downloaded 11 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

globals [ this-cluster infinity ;; a very large number. tick-counter endogenous? payoff my-palette ] turtles-own [ strategy cluster pos-x pos-y node-clustering-coefficient ] links-own [ rewired? ;; keeps track of whether the link has been rewired or not ] to go end to construct-agent ;; turtles-own agent constructor set shape "circle" ;set label who end ;;;;;;;;;;;;;;;;;;;;;;;; ;;; Setup Procedures ;;; ;;;;;;;;;;;;;;;;;;;;;;;; to setup clear-all set endogenous? true set my-palette [ [255 127 39] [255 0 0] [255 255 0] [0 255 0] [0 64 128] [0 255 255] [128 128 255] [128 0 128] [255 0 128] [128 128 0] [0 0 0] [133 122 122] [255 127 39] [255 0 0] [255 255 0] [0 255 0] [0 64 128] [0 255 255] [128 128 255] [128 0 128] [255 0 128] [128 128 0] [0 0 0] [133 122 122] ] ask patches [ set pcolor white ] if topology = "Scale-Free" [ create-hubspoke ] if topology = "Random Permute" [ create-ringlat permute-all layout-circle (sort turtles) max-pxcor - 1 ] if topology = "Square Lattice" [ create-square-lattice ] if topology = "Ring Lattice" [ create-ringlat ] if topology = "ER Graph" [ setup-erdos-renyi ] if topology = "Small World" [ rewire-all ] if topology = "Star" [ create-star ] if topology = "Full" [ crt N [ construct-agent ] ask turtles [ create-links-with other turtles ] layout-circle turtles 10 ] let num-solutions n-solutions if num-solutions < 1 [ set num-solutions 9999999999 ] ifelse endogenous? [ if num-solutions > N [ set num-solutions N ] ask turtles [ set strategy 0 set label strategy ] let i 0 ask n-of num-solutions turtles [ set i i + 1 set strategy i ] ] [ ask turtles [ set strategy (random num-solutions) + 1 ] ] let all-strategies [strategy] of turtles let need-zero? min all-strategies = 0 ask turtles [ set strategy ( position strategy sort remove-duplicates all-strategies ) set label strategy ] set payoff n-values count-unique [ random-payoff ] ifelse need-zero? [ set payoff replace-item 0 payoff -99999999 ] [ ask turtles [ set strategy strategy + 1 set label strategy ] set payoff fput -99999999 payoff ] reset-ticks end to run-step ask one-of turtles with [ strategy = 0 or strategy != update-strategy ] [ set strategy update-strategy set label strategy set-color-ng strategy ] tick end to-report update-strategy ;; NEED TO DEFINE THIS LIST ;; because the dynamic definition is a randomized order! let worldview [strategy] of link-neighbors let option-payoff ( map [ [?1] -> (occurrences ?1 worldview) * (item ?1 payoff) ] (remove-duplicates worldview) ) report item ( position (max option-payoff) option-payoff ) (remove-duplicates worldview) end ;; creates a new lattice to create-ringlat crt N [ set color black construct-agent ] wire-ringlat end to wire-ringlat layout-circle (sort turtles) max-pxcor - 1 layout-circle (sort turtles with [ who mod 2 = 0] ) max-pxcor - 4 ;; iterate over the turtles let ni 0 while [ni < count turtles] [ ;; make edges with the next two neighbors ;; this makes a lattice with average degree of 4 let z 1 while [z <= floor (k / 2)] [ ask turtle ni [ create-link-with turtle ((ni + z) mod count turtles) [ set rewired? false ] ] set z z + 1 ] set ni ni + 1 ] end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; SCALE-FREE Procedures ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; used for creating a new node to make-node [old-node] 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 randaom 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 ;;;;;;;;;;;;;;;;; ;;; SF 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 thea ;; 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) (( 2 * k) / 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 ; Scale-Free Code Adapted From NetLogo library item ; that is Copyright 2005 Uri Wilensky. ; see info tab for full copyright info. to setup-erdos-renyi ;; Make a circle of turtles create-turtles N [ construct-agent ] layout-circle turtles (max-pxcor - 1) let success? false let count-tries 0 while [ not success? ] [ ask links [ die ] ;; Now give each pair of turtles an equal chance ;; of creating a link ask turtles [ ;; we use "self > myself" here so that each pair of turtles ;; is only considered once create-links-with turtles with [self > myself and random-float 1.0 < p ] ] set success? ( item 0 identify-clusters = 1 ) set count-tries count-tries + 1 if ( count-tries > 1000 ) [ set success? true print "couldn't make connected network! try different parameters!" ] ] end ;; clusters code adapted from "Dissemination of Culture" by ??? ;; see info tab for full copyright info to-report identify-clusters let max-cluster 0 let num-clusters 0 let seed one-of turtles ask turtles [ set cluster nobody ] while [seed != nobody] [ ask seed [ set cluster self set num-clusters num-clusters + 1 set this-cluster 1 grow-cluster ] if this-cluster > max-cluster [ set max-cluster this-cluster] set seed one-of turtles with [cluster = nobody] ] report list num-clusters max-cluster end to grow-cluster ask link-neighbors with [cluster = nobody] [ if cluster = nobody [ set this-cluster this-cluster + 1 ] set cluster [cluster] of myself grow-cluster ] end ;; small-worlds code adapted by material ;; Copyright 2005 Uri Wilensky. ;; see info tab for full copyright info. to rewire-all create-ringlat ;; set up a variable to see if the network is connected let success? false ;; if we end up with a disconnected network, we keep trying, because the APL distance ;; isn't meaningful for a disconnected network. let count-tries 0 while [not success?] [ ;; kill the old lattice, reset neighbors, and create new lattice ask links [ die ] wire-ringlat ; set number-rewired 0 ask links [ ;; whether to rewire it or not? if (random-float 1) < p [ ;; "a" remains the same let node1 end1 ;; if "a" is not connected to everybody if [ count link-neighbors ] of end1 < (count turtles - 1) [ ;; find a node distinct from node1 and not already a neighbor of node1 let node2 one-of turtles with [ (self != node1) and (not link-neighbor? node1) ] ;; wire the new edge ask node1 [ create-link-with node2 [ set color cyan set rewired? true ] ] ; set number-rewired number-rewired + 1 ;; counter for number of rewirings set rewired? true ] ] ;; remove the old edge if (rewired?) [ die ] ] set success? ( item 0 identify-clusters = 1 ) set count-tries count-tries + 1 if ( count-tries > 1000 ) [ set success? true print "couldn't make connected network! try different parameters!" ] ] end to rewire-one ;; make sure num-turtles is setup correctly else run setup first if count turtles != N [ setup ] let potential-edges links with [ not rewired? ] ifelse any? potential-edges [ ask one-of potential-edges [ ;; "a" remains the same let node1 end1 ;; if "a" is not connected to everybody if [ count link-neighbors ] of end1 < (count turtles - 1) [ ;; find a node distinct from node1 and not already a neighbor of node1 let node2 one-of turtles with [ (self != node1) and (not link-neighbor? node1) ] ;; wire the new edge ask node1 [ create-link-with node2 [ set color cyan set rewired? true ] ] ;; remove the old edge die ] ] ] [ user-message "all edges have already been rewired once" ] end to-report percent-saturated report ((count turtles with [color = red ] ) / (count turtles)) end to create-square-lattice let lat-width (closest-factors N) let lat-height (N / lat-width) let width max-pxcor - min-pxcor let height max-pycor - min-pycor let left-edge min-pxcor + 0.5 let top-edge min-pycor + 0.5 let slot-width width / lat-width let slot-height height / lat-height ;; this sets the order of neighbor addition to easily create a square lattice ;; with any degree (up to the length of the map) let square-neighbor-map [ [1 0] [0 1] [-1 0] [0 -1] [1 1] [-1 1] [-1 -1] [1 -1] ] if (k > length square-neighbor-map) [ print "Square lattice degree too large! Check code." stop ] print lat-width let xi 0 while [ xi < lat-width ] [ let yi 0 while [ yi < lat-height ] [ crt 1 [ set pos-x xi set pos-y yi setxy ( (xi * slot-width) + left-edge) ( (yi * slot-height) + top-edge) construct-agent ] set yi yi + 1 ] set xi xi + 1 ] ask turtles [ let ni 0 while [ni < k] [ let target-pos-x pos-x + item 0 item ni square-neighbor-map let target-pos-y pos-y + item 1 item ni square-neighbor-map if (target-pos-x > lat-width) [ set target-pos-x target-pos-x - lat-width ] if (target-pos-y > lat-height) [ set target-pos-y target-pos-y - lat-height ] if (target-pos-x < 0 ) [ set target-pos-x target-pos-x + lat-width ] if (target-pos-y < 0 ) [ set target-pos-y target-pos-y + lat-height ] create-links-with turtles with [ pos-x = target-pos-x and pos-y = target-pos-y ] set ni ni + 1 ] ] end to-report closest-factors [ num ] let greatestEdge 1 let i 1 while [ i < num ] [ if(num mod i = 0) [ if abs (greatestEdge - (num / greatestEdge) ) > abs ( i - (num / i) ) [ set greatestEdge i ] ] set i i + 1 ] report greatestEdge end to create-hubspoke set-default-shape turtles "circle" ;; make the initial network of two turtles and an edge crt 1 [ construct-agent ] ;; first node, unattached let mi 1 while [ mi < m ][ crt 1 [ let counter 1 repeat mi [ create-link-with turtle (mi - counter) set counter counter + 1 ] construct-agent ] set mi mi + 1 ] ;; second node, attached to first node repeat (N - m) [ add-link ] ask turtles with [who <= 5] [ while [ count link-neighbors < m ] [ let old-node find-partner while [ [who] of old-node = who ] [ set old-node find-partner ] create-link-with old-node ;; position the new node near its partner move-to old-node fd 8 ] ] end to add-link ;; 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 crt 1 [ repeat m [ let old-node find-partner while [ ([who] of old-node = who) OR (length filter [ [?1] -> ?1 = [who] of old-node ] [who] of link-neighbors != 0) ] [ set old-node find-partner ] create-link-with old-node ;; position the new node near its partner move-to old-node fd 8 ] construct-agent ] end to permute let success false while [ success = false ] [ let graphset sort link-set links let permutewith random count link-set links let permuter random count link-set links let abort false if [end1] of item permuter graphset = [end1] of item permutewith graphset [ set abort true ] if [end2] of item permuter graphset = [end1] of item permutewith graphset [ set abort true ] if [end2] of item permutewith graphset = [end1] of item permuter graphset [ set abort true ] ask [end1] of item permuter graphset [ if link-neighbor? [end2] of item permutewith graphset [ set abort true ] ] ask [end1] of item permutewith graphset [ if link-neighbor? [end2] of item permuter graphset [ set abort true ] ] if abort = false [ ask [end1] of item permuter graphset [ create-link-with [end2] of item permutewith graphset ] ask [end1] of item permutewith graphset [ create-link-with [end2] of item permuter graphset ] ask item permuter graphset [ die ] ask item permutewith graphset [ die ] set success true ] ] end to permute-all let z 0 while [z < ((count turtles) * k * 3)] [ permute set z z + 1 ] end to labels-from-list [ label-list color-list ] let i 0 while [i < length label-list] [ ask turtle i [ set label item i label-list set label-color item i color-list ] set i i + 1 ] end to-report clustering-coefficient let global-clustering-coefficient 0 ifelse all? turtles [count link-neighbors <= 1] [ ;; it is undefined ;; what should this be? set global-clustering-coefficient -1 ] [ let total 0 ask turtles with [ count link-neighbors <= 1] [ set node-clustering-coefficient "undefined" ] ask turtles with [ count link-neighbors > 1] [ let hood link-neighbors set node-clustering-coefficient (2 * count links with [ in-neighborhood? hood ] / ((count hood) * (count hood - 1)) ) ;; find the sum for the value at turtles set total total + node-clustering-coefficient ] ;; take the average set global-clustering-coefficient total / count turtles with [count link-neighbors > 1] ] report global-clustering-coefficient end to-report in-neighborhood? [ hood ] report ( member? end1 hood and member? end2 hood ) end to-report graph-density set N count turtles report ( (2 * count links) / ( N * (N - 1) ) ) end to-report random-lognormal [ mymean mystd ] let varx ( mystd ^ 2) let ess sqrt( ln(1 + (varx / ( mymean ^ 2))) ) let mu ln(mymean) - ((1 / 2) * (ess ^ 2)) report exp ( (mu + (ess * random-normal 0 1)) ) end to-report random-payoff report random-lognormal 100 50 end to-report occurrences [x the-list] report reduce [ [?1 ?2] -> ifelse-value (?2 = x) [?1 + 1] [?1] ] (fput 0 the-list) end to set-color-ng [ value ] ifelse N > 24 [ set color value ] [ let this-color value - 1 set color item this-color my-palette if this-color < 12 [ set shape "circle" ] if this-color >= 12 [ set shape "x" ] ] end to create-star crt N [ construct-agent ] ask turtles with [ who < k ] [ create-links-with turtles with [ who >= k ] ] ask turtles with [ who >= k ] [ create-links-with turtles with [ who < k ] ] layout-circle turtles 10 end to-report count-unique report length remove-duplicates [strategy] of turtles end

There are 2 versions of this model.

## Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.