Axelrod model

Axelrod model preview image

1 collaborator

Default-person Eleonora Barelli (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.1.1 • Viewed 177 times • Downloaded 11 times • Run 0 times
Download the 'Axelrod model' 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

;; Axelrod's Model for Cultural Evolution is an agent-based model described by
;; Robert Axelrod in his paper:
;; Axelrod, R. 1997. “The dissemination of culture - A model with local convergence and global polarization.”
;;        Journal of Conflict Resolution 41:203-226.
;;
;;
;; 2021 Eleonora Barelli (eleonora.barelli2@unibo.it)
;;
;; -------------------------------------------------- ;;

;;;;;;;;;;;;;;;;;
;;; VARIABLES ;;;
;;;;;;;;;;;;;;;;;

globals [
  time                            ;; time
  number_of_agents                ;; number of all agents in the society (obtained as world-size^2)
  cult_max                        ;; number associated to the culture with maximum traits for each feature [q-1, q-1, q-1, …, q-1]
  number_of_active_agents         ;; number of agents which have at least one neighbor with overlap in ]0,F[
  number_of_cultures              ;; number of cultures in the society at a certain time
  number_of_cultural_regions      ;; number of cultural regions simply connected
  component-size                  ;; number of agents explored so far in the current component
  giant-component-size            ;; number of agents in the giant component
]

turtles-own [
  culture                         ;; culture of an agent
  explored?                       ;; if the agent is already explored (or not) when determining number of cultural regions
]

;;;;;;;;;;;;;;;;;;;;;;;;
;;; SETUP PROCEDURES ;;;
;;;;;;;;;;;;;;;;;;;;;;;;

;;
;; General setup settings: clear plots, create the grid
;;

to setup
  clear-all
  clear-all-plots
  resize-world 0 (world-size - 1) 0 (world-size - 1)   ;; defining the size of the society
  set number_of_agents (world-size * world-size)       ;; there will be as many agents as the patches (not yet created)
  set-patch-size 360 / world-size                      ;; setting patch size for good looking
  ask patches [set pcolor 34]                          ;; setting color of patches
  set giant-component-size 0                           ;; initializing the number of agents in the biggest cultural domain
  set number_of_cultural_regions 0                     ;; initializing the number of the cultural regions
  setup-turtles                                        ;; creating the agents, locating them and setting their cultural values randomly
  reset-ticks
  set time 0
end 

;;
;; Agent settings: create agents, position them in the grid
;;

to setup-turtles
  set-default-shape turtles "person"
  create-turtles number_of_agents [                    ;; creating the agents
    set size 0.9
    while [any? other turtles-here] [ move-to one-of patches ] ;; setting agents' location: only one agent at each patch
  ]
  setup-culture-max                                    ;; assigning a value to the culture with maximum traits value
  setup-agent-culture                                  ;; setting agents culture
  count-cultures                                       ;; counting the amount of different cultures at time = 0
  do-plots                                             ;; plotting for visualization
end 

;;
;; Assigning a value to the culture with maximum traits values
;;

to setup-culture-max
  set cult_max (q ^ F - 1)
end 

;;
;; Assigning a random culture to each agent
;;

to setup-agent-culture
  ask turtles [                               ;; all agents, in a random order, are asked to
    set culture []                            ;; set their own variable “culture” to an empty list, then,
    repeat F [                                ;; F (number of cultural features) times,
      set culture lput random q culture       ;; add at the end of the list a random value in [0, q-1].
    ]                                         ;; Once the list is filled,
    setup-agent-culture-color                 ;; set a color for the agent according to its culture
  ]
end 

;;
;; Setting the color to the agent according to its culture
;;

to setup-agent-culture-color
  ;setting agent culture in base q
  let i 1
  let suma 0
  repeat F [
    set suma suma + item (i - 1) culture * q ^ (F - i)
    set i i + 1
  ]
  let Cult_base_q suma
  ;setting the corresponding color to the turtle according to the culture_base_q value. a range of blue is selected
  set color (9.9 * Cult_base_q / Cult_max) + 100
end 

;;;;;;;;;;;;;;;;;;;;;;
;;; MAIN PROCEDURE ;;;
;;;;;;;;;;;;;;;;;;;;;;

;;
;; Execute all the procedures in their order until there are active agents
;;

to go
  clear-links
  ask turtles [setup-agent-culture-color]                          ;; asking agents to setup their color
  tick
  set time time + 1
  set number_of_active_agents 0
  ask turtles [cultural-interaction]                               ;; asking agents to interact locally in asyncronous-random updating
  count-cultures                                                   ;; counting the amount of different cultures
  do-plots                                                         ;; plotting for visualization
  if number_of_active_agents = 0 [stop]                            ;; stopping when there are no active agents (when each agent
                                                                   ;;    has full or null overlap with each of its neighbors
end 

;;;;;;;;;;;;;;;;;;;;;;;;
;;; LOCAL PROCEDURES ;;;
;;;;;;;;;;;;;;;;;;;;;;;;

;;
;; agents look for a neighbor to interact with
;;

to cultural-interaction
  ; count the neighbors within the given radius that have a number of common traits in ]0, F[
  let number_of_possible_neighbors count other turtles in-radius radius with [(0 < overlap_between self myself ) and (overlap_between self myself < F)]
  ; if there is one or more such neighbors,
  if number_of_possible_neighbors > 0 [
    ; increase of 1 the number of active agents and
    set number_of_active_agents number_of_active_agents + 1
    ; select a neighbor within the radius
    let neighbor_turtle one-of other turtles in-radius radius
    ; and make it interact with the target agent
    let target_turtle self
    culturally_interacting target_turtle neighbor_turtle
  ]
end 

;;
;; reporting overlap between two agents (range from 0 to F)
;;

to-report overlap_between [target_turtle neighbor_turtle]
  let suma 0                                                         ;; Initialize to 0 a temporarily variable suma, then
  (foreach [culture] of target_turtle [culture] of neighbor_turtle   ;; for each element of the cultures of target and neighbor,
    [ [a b] -> if a = b [ set suma suma + 1]  ]                      ;; compare the traits and, if they are equal, add 1 to suma
    )
  report suma
end 

;;
;; interaction between a target agent and its selected neighbor
;;

to culturally_interacting [target_turtle neighbor_turtle]
  let overlap overlap_between target_turtle neighbor_turtle                       ;; Calculate the overlap between target and neighbor.
  if (0 < overlap and overlap < F ) [                                             ;; If the overlap is in ]0, F[,
    let prob_interaction (overlap / F)                                            ;; call overlap/F the probability of interaction, then,
    if random-float 1.0 < prob_interaction [                                      ;; according to this probability,
      let trait random F                                                          ;; select randomly a cultural feature to inspect
      let trait_selected? false
      while [not trait_selected?] [
        ifelse (item trait [culture] of target_turtle = item trait [culture] of neighbor_turtle)   ;; if that cultural feature has the same trait for both agents
        [
          set trait ((trait + 1) mod F)                                           ;; pass to the adjacent cultural feature
        ]
        [
          set trait_selected? true                                                ;; otherwise
        ]
      ]
      let new_cultural_value (item trait [culture] of neighbor_turtle)            ;; save the trait for that cultural feature of the neighbor
      set culture replace-item trait culture new_cultural_value                   ;; and replace the original cultural feature in the target agent with the neighbor’s trait
      setup-agent-culture-color                                                   ;; update the target agent's color according to the new culture
    ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; COMPONENT EXPLORATION ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;
;; Find all agents reachable from this node (it is a recursive procedure)
;;

to explore ;; turtle procedure
  if explored? [ stop ]
  set explored? true
  set component-size component-size + 1
  ask link-neighbors [ explore ]
end 

;;
;; an agent creates a link with all its neighbors with the same culture
;;

to creates-links-with-same-cultural-neighbors-in-neighborhood-of-radio-radius
  let neighborhood other turtles in-radius radius
  ask neighborhood [
    if overlap_between self myself = F                              ;; if they have the same cultures
    [
      let color_for_the_link color
      create-link-with myself [set color color_for_the_link]        ;; create a link
    ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; GLOBAL EXPLORATION ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;

;;
;; count the number of different cultures in the system
;;

to count-cultures
  let list_of_cultures []                                          ;; Initialize an empty list to contain the different cultures
  ask turtles [                                                    ;; All agents, in random order, are asked to
    set list_of_cultures lput culture list_of_cultures             ;; add their vector of culture to the list of cultures.
    ]
  set list_of_cultures remove-duplicates list_of_cultures          ;; Remove the duplicates from the resulting list
  set number_of_cultures length list_of_cultures                   ;; The number of different cultures is the length of the list
end 

;;
;; counting the number of agents in the biggest cultural region
;;

to count-turtles-on-biggest-region
  ; first it is linked all agents of the same culture (each agent looks for a neighbor which is in its neighborhood (agent inside in radius)
  ask turtles [
    creates-links-with-same-cultural-neighbors-in-neighborhood-of-radio-radius
  ]
  find-all-components                                                  ;; exploring each connected network finding and counting agents of the same culture
end 

;;
;; finding all the connected components in the network and their sizes
;;

to find-all-components
  set number_of_cultural_regions 0                             ;; Initialize to 0 the number of cultural regions
  ask turtles [ set explored? false]                           ;; All the agents, until all get explored, are asked to
  loop
  [
    let starting_turtle one-of turtles with [ not explored? ]  ;; find a starting agent that has not been yet explored
    if starting_turtle = nobody [ stop ]                       ;; (if no agents are left, the loop stops)
    set component-size 0                                       ;; Initialize to 0 the component size
    ask starting_turtle [                                      ;; Ask the starting agent to
      explore                                                  ;; Count its similar neighbors (recursive procedure
                                                               ;; in which the component-size counter is updated)
      set number_of_cultural_regions number_of_cultural_regions + 1   ;; Once the explore procedure ends, increase the number of cultural regions
    ]
    if component-size > giant-component-size [                 ;; If the component explored is bigger than the giant component,
      set giant-component-size component-size                  ;; call its dimension the giant-component-size
    ]
  ]
end 

;;;;;;;;;;;;;;
;;; GRAPHS ;;;
;;;;;;;;;;;;;;

to do-plots
  ;setting the plot of Cultures
  set-current-plot "Graph"
  set-current-plot-pen "Number of cultures"
  plotxy time (number_of_cultures / q ^ F)
end 

There is only one version of this model, created about 3 years ago by Eleonora Barelli.

Attached files

File Type Description Last updated
Axelrod model.png preview Preview for 'Axelrod model' about 3 years ago, by Eleonora Barelli Download

This model does not have any ancestors.

This model does not have any descendants.