Libraries‎ > ‎Library‎ > ‎

Power law social network

BehaviourComposer: ignore everything before this.  
Creates a power law social network.

Begin micro-behaviour
Begin description:
Create an entire social network with bi-directional links between all individuals where the number of acquaintances is distributed according to a power law.
End description

Power law social network

Begin NetLogo code:
substitute-text-area-for average-acquaintance-count-text-area 4  
substitute-text-area-for community-expression all-individuals                  

   [let average-acquaintance-count average-acquaintance-count-text-area
    output-print (word "Initialising the social network so everyone has an average of "
                        average-acquaintance-count " acquaintances with a power law distribution.")
    let entire-community community-expression
    let total-population count entire-community
    if total-population < average-acquaintance-count + 1
       [output-print "Too few individuals to create a network." stop]
    let total-links round (0.5 * average-acquaintance-count * total-population)
    let linkees sort entire-community
    repeat total-links 
           [let a one-of linkees
            ; find someone who is not a and not already linked with a
            let b one-of linkees
            while [b = a or [link-neighbor? a] of b]
                  [set b one-of linkees]
            ask a [create-link-with b]
            ; preferential treatment for those already linked
            set linkees fput a fput b linkees
            ; remove anyone that is connected to everyone else
            if [count link-neighbors] of a + 1 = total-population [set linkees remove a linkees]
            if [count link-neighbors] of b + 1 = total-population [set linkees remove b linkees]]
    output-print "Initialisation completed."]
End NetLogo code


You can edit the text areas to change the average number of acquaintances per person or to change the set of individuals that are to be linked together.

Related behaviours

The Constant social network behaviour assigns the same number of acquaintances to each individual.

How this works

First this computes the total number of links which is half of the population times the average number of acquaintances. (Each link represents an acquaintance relationship for both ends of the link, hence we divide by two.) For each link that needs to be added it selects both ends randomly from a list that initially contains the entire population. If  the two individuals are already linked it selects again. When a link is added then the individuals at the ends of the link are added to the list. This makes those with connections more likely to gain new connections. This is known as preferential attachment and it generates a power law distribution.


This was implemented by Ken Kahn on 3 February 2011. Updated 10 May 2011.

BehaviourComposer: ignore everything after this.