This page was automatically generated by NetLogo 5.0.3.

The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Oracle's Java site.


In order for this to work, this file, your model file (HNG.nlogo), and the files NetLogoLite.jar and NetLogoLite.jar.pack.gz must all be in the same directory. (You can copy NetLogoLite.jar and NetLogoLite.jar.pack.gz from the directory where you installed NetLogo.)

On some systems, you can test the applet locally on your computer before uploading it to a web server. It doesn't work on all systems, though, so if it doesn't work from your hard drive, please try uploading it to a web server.

You don't need to include everything in this file in your page. If you want, you can just take the HTML code beginning with <applet> and ending with </applet>, and paste it into any HTML file you want. It's even OK to put multiple <applet> tags on a single page.

If the NetLogoLite files and your model are in different directories, you must modify the archive= and value= lines in the HTML code to point to their actual locations. (For example, if you have multiple applets in different directories on the same web server, you may want to put a single copy of the NetLogoLite files in one central place and change the archive= lines of all the HTML files to point to that one central copy. This will save disk space for you and download time for your users.)

powered by NetLogo

view/download model file: HNG.nlogo

WHAT IS IT?

This model studies social influence in randomly formed networks for two classes of games. Games with strategic complements where agents want to coordinate in the same action, and games with strategic substitutes, where agents want to anti-coordinate.

Agents in the model can be of two types: bips and bops. Bips are agents that prefer action 1 and are represented as triangles. Bops prefer action 0 and are represented as circles. Independently of the type, if an agent chooses action 1 her color will be cyan, and if 0 her color will be pink.

The first choice made is randomly assigned to players. From there, in every period of time, an agent myopically best responds to the choices made by her neighbors in the previous period. When an agent has no incentives to change her choice, she is in the nash set and will display the number 1, otherwise she displays 0. If all agents reach nash the simulation stops, if not, it will continue until the maximum number of iterations is reached.

Agents that choose the action they prefer are said to be happy. This is used to characterize the final outcome (most likely in equilibrium) as satisfactory if all agents are happy, and frustrated if at least one is not. Also as specialize if all agents choose the same action, or hybrid if both actions coexist.

HOW TO USE IT

There are 6 parameters you can decide on before initializing the model. (1) The COMPLEMENTS? switch that sets games as strategic complements if ON and sets games as strategic substitutes if OFF. (2) The NUMER_NODES slider controls the size of the network. (3) The NUMBER_BIPS slider controls how many of the total agents are bips. Note that if the number of bips you choose is greater than the total number of agents, by default all agents will be bops.(4) The PROPORTION_OF_LINKS slider controls the level of connectivity in the network. You cannot decide the exact number of links you want, but the percentage of the total possible links [(n*(n-1))/2]. (5) The I_LIKE_FIRST_CHOICE slider controls the probability that all agents first choice is their preferred action. If 100% all agents will choose with probability 1 the action they like: bips choose 1 and bops choose 0. (6) The MAX_ITERATIONS monitor controls the number of iterations the model will run in case it has not reached equilibrium. Choose the values for the five controllers and then press SETUP.

Pressing the GO ONCE button sets the revision of the first initial choice. To repeatedly make agents revise their choices, press GO.

The FORMED_LINKS monitors shows the exact number of connections formed by the proportion of links you determined. This is a fixed value along the run of the model. A1 and A0 monitors show how many agents choose action 1 or 0 repectively, in each round. Monitors HAPPY and NASH, show how many agents choose the action they like and how many agents are in the nash set and don’t want to change their choice in the next round, respectively.

The ACTION and EQUILIBRIUM plots illustrate the entire path of choices 1 and 0 and of happy and nash agents along the run of the model.

THINGS TO TRY

Let the model run until the end. Does it always stop before the maximum iterations? Does it always reach an equilibrium where all agents are in the nash set?

Run the model again, this time slowly, a step at a time. Watch how agents change their choices. What is happening when the network is highly connected? What is happening when there are no links in the network?

Run it with a small proportion of bips (or bops). What happens when all agents are identical? What happens when there is a large majority of one type and few agents of the other type? What happens when both types of agents are close to 50%?

EXTENDING THE MODEL

Right now the probability of any two nodes getting connected to each other is the same. Can you think of ways to making any two nodes more attractive to be connected to each other? Perhaps (1) that the more connected an agent is the more likely to create a new link, or (2) the more likely two nodes to be connected if their types is the same, or (3) or the more likely to nodes to be connected if their type is the opposite, or (4) even that all agents will necessarily have the same number of connections. How would that impact the likelihood of reaching equilibrium? How would that impact the class of equilibria reached?

RELATED MODELS

See other models in the Networks section of the Models Library.

CREDITS AND REFERENCES

This model is adapted from:
Hernandez, Penalope, Munoz-Herrera, Manuel, Sanchez, Angel, 2013. Heterogeneous Network Games: Conflicting Preferences. Games and Economic Behavior. Forthcoming.

CODE

;;;;;;;;;;;;;;;;;;;;;;;;
;;; 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 ;;;
;;;;;;;;;;;;;;;;;;;;;;;;