Libraries‎ > ‎Library‎ > ‎

Constant social network

BehaviourComposer: ignore everything before this.

I create an entire social network where everyone has the same number of acquaintances.

Begin micro-behaviour

Constant 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 exactly "
                        average-acquaintance-count " acquaintances.")
    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]
    ask entire-community 
        [let me self
         while [count link-neighbors < average-acquaintance-count]
               [let x one-of other all-individuals 
                             with [count link-neighbors < average-acquaintance-count and 
                                   not link-neighbor? me]
                if x = nobody [stop]
                create-link-with x]]
    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 Power law social network behaviour assigns acquaintances to each individual to create a power law distribution.

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 11 May 2011.

BehaviourComposer: ignore everything after this.