Heterogeneous Network Games

No preview image

1 collaborator

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.3 • Viewed 295 times • Downloaded 19 times • Run 0 times
Download the 'Heterogeneous Network Games' modelDownload this modelEmbed this model

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

;;;;;;;;;;;;;;;;;;;;;;;;
;;; Global variables ;;;
;;;;;;;;;;;;;;;;;;;;;;;;
globals
[
  tie_counter         ;; when adding random ties, this varibale monitors the number of random ties already added
  random_agent_1      ;; used when one or more agents are randomly selected
  random_agent_2      ;; used when one or more agents are randomly selected
  links_in_network    ;; sets the number of links in the network
  iteration           ;; sets the number of iterations to a maximum (in case of falling into a cycle).
  nash_network        ;; used when the action profile of all agents is and equilibrium best response
]

;;;;;;;;;;;;;;;;;;;;;;;
;;; Types of agents ;;;
;;;;;;;;;;;;;;;;;;;;;;;
breed [bops bop]      ;; bop agents prefer A=0
breed [bips bip]      ;; bip agents prefer A=1

;;;;;;;;;;;;;;;;;;;;;;;;
;;; Turtle variables ;;;
;;;;;;;;;;;;;;;;;;;;;;;;
turtles-own
[
  action                  ;; agent's choice (1 or 0)
  threshold_high          ;; agent's threshold to choose their disliked_action, as a function of their number of connections
  threshold_low           ;; agent's threshold to choose their liked_action, as a function of their number of connections
  alpha                   ;; payoff earned for coordinating in the liked_action
  beta                    ;; payoff earned for coordinating in the disliked_action 
  tie_check               ;; auxiliary variable that is needed to check whether two agents maintain a link
  set_ties                ;; indicates the set of links an agent maintains
  total_ties              ;; indicates the cardinality of the set of links an agent maintains: agent's degree
  set_A1                  ;; set of agents who choose A=1
  set_A0                  ;; set of agents who choose A=0 
  A0_neighbors            ;; set of neighbors who choose A=1, for the focal agent
  A1_neighbors            ;; set of neighbors who choose A=1, for the focal agent
  total_A0_neighbors      ;; cardinality of the set of neighbors A_0
  total_A1_neighbors      ;; cardinality of the set of neighbors A_1
  liked_action            ;; this is the choice that gives higher payoffs to the focal agent
  disliked_action         ;; this is the choice that gives lower payoffs to the focal agent
  prob_like_first         ;; probability of liking the first choice
  happy                   ;; variable that shows if an agent's choice == liked_choice
  nash                    ;; variable that shows if an agent's choice is stable when fixing the choices of all her neighbors
  set_nash                ;; this is the set of agents that don't want to change their choice
  total_set_nash          ;; this is the cardinality of the nash set
]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setting up the world ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all               ;; clears the world   
  reset-ticks             ;; ticks start from 0 after every setup
  setup-link_number       ;; calculates the number of links in the network
  setup-bops              ;; creates the bops
  setup_bips              ;; creates the bips
  make_network            ;; sets the random formation prior to the coordination game
  setup-liked_action      ;; sets the value of the favorite action for each breed
  setup-disliked_action   ;; sets the value of the non-favorite action for each breed
  setup-first_choice      ;; sets the random initial choice agents make
  set iteration 0         ;; sets the iteration counter: relevant for the length of run
  set nash_network 0      ;; sets the nash network variable
  setup_color             ;; sets the initial color of the turtles
end 

to setup-link_number  
  set links_in_network ((proportion-links * ((number_nodes * (number_nodes - 1)) / 2 )) / 100)
end 
;; The initial number of links is given by the input of the proportion-links slider

to setup-bops
  set-default-shape bops "circle"
  create-bops (number_nodes)
  [
  set size 1
  ]
end 
;; All nodes created are initially bops

to setup_bips
  if number_nodes = 0 [stop]   
  if number_bips > number_nodes [stop] 
  set-default-shape bips "triangle"
  loop [                       
  if (number_bips > 0) [      
    ask one-of turtles [ set breed bips]
  ]
  if (count bips = number_bips) [stop] 
  ]
end 
;; if there are no nodes in the network there can be no bips
;; if the number of bips to be created is greater than the number of nodes, all nodes will remain as bops
;; the loop process randomly chooses a node to change her breed from bop to bip
;; the loop process starts only if at least one bip is to be created, as given by the input from the number_bips slider
;; the process stops when the number of bips is the one selected in the setup

to make_network
  repeat links_in_network [ layout-spring turtles links 0.4 6 1]  
  set tie_counter 0            
  while [tie_counter < links_in_network] 
  [
    set random_agent_1 0 
    set random_agent_2 0
    ask turtle random_agent_1 [ask link-neighbors [set tie_check 1]]
    while [(random_agent_1 = random_agent_2) or ([tie_check] of turtle random_agent_2 = 1)] 
    [                                                                                       
      ask turtle random_agent_1 [ask link-neighbors [set tie_check 0]] 
      set random_agent_1 random number_nodes    
      set random_agent_2 random number_nodes
      ask turtle random_agent_1 [ask link-neighbors [set tie_check 1]] 
    ]
    ask turtle random_agent_1 [create-link-with turtle random_agent_2]
    set tie_counter tie_counter + 1  
  ]
  if (links_in_network = 0) [layout-circle (sort turtles) max-pxcor - 2  ] 
  ask turtles [set set_ties link-neighbors]      
  ask turtles [set total_ties count set_ties]
  ask turtles [
    set alpha 3       
    set beta 2      
  ]
end 
;; the spring-out layout arranges the setup given the links, it is ignored if layout-circle is set
;; the tie_counter = 0 sets that initially there are no links in the network
;; the process of link creatiion is repeated as long as there are less than the proportion of links chosen in the setup
;; there are two random agents chosen to create a link between them. The two random agents are initially agent 0
;; if there is a link between two agents the tie_check gives value 1
;; if either both random_agents are the same or are already linked, they are skipped from the formation process
;; for each agent the count of links (link-neighbors) starts in 0 
;; Pairs of agents are randomly selected from the entire population (number_nodes) and if they are not connected an undirected link is formed
;; and the tie_counter of links is updated, by adding a new link into it. 
;; The update will stop when the total number of links counted is the one setup
;;
;; If there are no links to be formed, the layout-circle locates all agents on a circle
;;
;; The set_ties is the set of neighbors for an agent
;; The total_ties is the cardinality of the neighborhood
;; Alpha is set to 3 and beta is set to 2

to setup-liked_action  
  ask turtles [
  ifelse breed = bops
  [set liked_action 0] 
  [set liked_action 1]
  ]
end 
;; this is the parameter for liked actions given an agents breed
;; bops like action 0 and bips like action 1

to setup-disliked_action 
  ask turtles [
  ifelse breed = bops
  [set disliked_action 1]  
  [set disliked_action 0]
  ]
end 
;; this is the parameter for disliked actions given an agents breed
;; bops dislike action 1 and bips dislikeaction 0

to setup-first_choice    
  ask turtles [
    set prob_like_first random 100   
    ifelse prob_like_first < I_like_first_choice 
    [set action liked_action]
    [set action disliked_action]
    ]                        
end 
;; this setups the choice agents start with (prior to "go")
;; First, it sets a random number between 0 and 100 as the probability to like the first choice
;; if the probability set is lower than the probability set as an input in the I_like_first_choice slider, 
;; an the focal agent starts choosing the action she likes. This is repeated for all agents
;; OJO: given the inequality/equality in 0 or 100% there is still a chance for liked/disliked action????

to setup_color
  ask bops [
    ifelse action = liked_action
    [set color pink]  
    [set color cyan]  
  ]
  ask bips [
    ifelse action = liked_action
    [set color cyan]
    [set color pink]
  ]
end 
;; this sets the initial color of the agents given their initial choice
;; action 0 is assigned color pink (independently of who is choosing it)
;; action 1 is assigned color cyan (independently of who is choosing it)


;;;;;;;;;;;;;;;;;;;;;;
;;; Here starts GO ;;;
;;;;;;;;;;;;;;;;;;;;;;

to go
  if not any? turtles [stop]            ;; if there are no nodes in the network the model stops
  if ticks >= max_iterations [stop]     ;; if the maximum_iterations is reached the model stops
    set_threshold_high                  ;; sets the threshold_high for every agent
    set_threshold_low                   ;; sets the threshold_low for every agent
    set_A1_choice                       ;; makes a set of turtles choosing action 1
    set_A0_choice                       ;; makes a set of turtles choosing action 0
    set_happy                           ;; makes a set of turtles choosing the action they like
    set_A0_neighbors                    ;; makes a set of neighbors choosing action 0, for the focal agent
    set_A1_neighbors                    ;; makes a set of neighbors choosing action 1, for the focal agent
    check_nash                          ;; sets if an agent's choice is stable (nash)
    set_nash_set                        ;; makes a set of agents whose choice is nash
    report_nash                         ;; displays a label 1 if an agent is nash, and 0 otherwise
    check_nash_network                  ;; checks wether all agents are in the nash set (1) or not (0)
  if nash_network = 1 [stop]            ;; if all agents are in the nash set the model stops
    choose_action                       ;; agents that are not in nash change their action
    set_color                           ;; the color is set of all agents given their choice
  tick                                  ;; a new tick (period of time) runs
end 

to set_threshold_high
  ask turtles [
    ifelse links_in_network = 0
    [set threshold_high 0 ]
    [ifelse total_ties = 0
      [set threshold_high 0]
    [set threshold_high (((total_ties * alpha) + alpha - beta ) / (alpha + beta ))]
    ]
  ]
end 
;; The threshold_high is a function of an agents connections. It determines the tipping point to choose the disliked action.

to set_threshold_low
  ask turtles [
    ifelse links_in_network = 0
    [set threshold_low 0 ]
    [ifelse total_ties = 0
      [set threshold_low 0]
    [set threshold_low (((total_ties * beta) - alpha + beta ) / (alpha + beta ))]
    ]
  ]
end 
;; The threshold_low is a function of an agents connections. It determines the tipping point to choose the liked action.

to set_A1_choice
  ask bops [
    ifelse action = liked_action
    [set set_A1 0]
    [set set_A1 1]
  ]
  ask bips [
  ifelse action = liked_action
  [set set_A1 1]
  [set set_A1 0]
]
end 
;; The set_A1 is composed by all agents choosing action 1. It is defined given the agents' breed and liked/disliked actions

to set_A0_choice
  ask bops [
    ifelse action = liked_action
    [set set_A0 1]
    [set set_A0 0]
  ]
  ask bips [
  ifelse action = liked_action
  [set set_A1 1]
  [set set_A1 0]
]
end 
;; The set_A0 is composed by all agents choosing action 0. It is defined given the agents' breed and liked/disliked actions

to set_happy
  ask turtles [
    ifelse action = liked_action
    [set happy 1]
    [set happy 0]
  ]
end 
;; The happy is composed by all agents choosing the action they like

to set_A0_neighbors
  ask turtles [
    set A0_neighbors link-neighbors with [set_A0 = 1]
    set total_A0_neighbors count A0_neighbors
  ]
end 
;; The set_A0_neighbors is composed by all neighbors of the focal agents choosing action 0. Its cardinality is total_A0_neighbors

to set_A1_neighbors
  ask turtles [
    set A1_neighbors link-neighbors with [set_A1 = 1]
    set total_A1_neighbors count A1_neighbors
  ]
end 
;; The set_A1_neighbors is composed by all neighbors of the focal agents choosing action 1. Its cardinality is total_A1_neighbors

to check_nash
  ask turtles[
  ifelse complements?
  [
  ask bops[
    ifelse action = liked_action  
    [ifelse total_A0_neighbors >= threshold_low
      [set nash 1]
      [set nash 0]
    ]
    [ifelse total_A1_neighbors > threshold_high
      [set nash 1]
      [set nash 0]
    ]
  ]
  ask bips[
    ifelse action = liked_action  
    [ifelse total_A1_neighbors >= threshold_low
      [set nash 1]
      [set nash 0]
    ]
    [ifelse total_A0_neighbors > threshold_high
      [set nash 1]
      [set nash 0]
    ]
  ]
  ]
   [
  ask bops[
    ifelse action = liked_action  
    [ifelse total_A1_neighbors >= threshold_low
      [set nash 1]
      [set nash 0]
    ]
    [ifelse total_A0_neighbors > threshold_high
      [set nash 1]
      [set nash 0]
    ]
  ]
  ask bips[
    ifelse action = liked_action  
    [ifelse total_A0_neighbors >= threshold_low
      [set nash 1]
      [set nash 0]
    ]
    [ifelse total_A1_neighbors > threshold_high
      [set nash 1]
      [set nash 0]
    ]
  ]
  ]
  ]
end 
;; An agent is nash depending on the relation between her neighbors' choices and the thresholds.

to set_nash_set
  ask turtles [ 
    set set_nash turtles with [nash = 1]
    set total_set_nash count set_nash
  ]
end 
;; All agents that are nash are part of the nash set. The cardinality of the set is total_set_nash

to report_nash
  ask turtles[set label nash]
end 
;; This displays a label (1) on top if every agent when nash, and 0 otherwise

to check_nash_network
   ask turtles [
   ifelse total_set_nash = number_nodes
   [set nash_network 1]
   [set nash_network 0]
   ]
end   
;; The nash_network takes value 1 if all agents are part of the nash set. If at least one agent is not nash, it takes value 0 

to choose_action
  ask turtles[
    ifelse action = liked_action
    [ifelse nash = 1
      [set action liked_action]
      [set action disliked_action]
    ]
    [ifelse nash = 1
      [set action disliked_action]
      [set action liked_action]
    ]
  ]
end 
;; Agents that are not in the nash set change their action. Agents in the nash set keep their same choice as in the previous period.

to set_color
  ask bops [
    ifelse action = liked_action
    [set color pink]
    [set color cyan]
  ]
  ask bips [
    ifelse action = liked_action
    [set color cyan]
    [set color pink]
  ]
end 
;; If an agent changed her action her color is updated, otherwise her color is kept the same.

;;;;;;;;;;;;;;;;;;;;;;;;
;;; End of the model ;;;
;;;;;;;;;;;;;;;;;;;;;;;;
    
    
    

 

There is only one version of this model, created over 12 years ago by Manu Muñoz Herrera.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.