Pietro della Briotta Parolo Daniela Perrotta Stefania Pezzoli

Simulation models for economics

Project work on

"Modified Deffuant Basic Model."

 

An introduction to A Modified Deffuant Model - Multiopinion and Network Structure.


Go to the modified Deffuant network model.


powered by NetLogo

view/download model file: modified_deffuant_basic_model.nlogo

WHAT IS IT?

This is a model of opinion dynamics.The agents adjust their opinion on the occasion of random binary encounters whenever their opinion difference is below a given threshold. We add some news: the introduction of extremists with fixed opinion, the possibility to restrict the interacting region, the possibility to discuss about more topics, choosing randomly one or following a particular order.


HOW IT WORKS

Click the setup button to set up the agent with opinion in range 0-100.
Click the go button to start the simulation.
With the chooser button you can select what type of interaction you want to simulate. You have also to give a value (through the slider buttons) to d and mu parameter.
If you want to include extremists, set “on” the relative button and select how many of them you need.
With Place “on”, the interaction takes place only if the two agents are in the range defined by slider.


HOW TO USE IT

The interaction among agents follows the equation defined by Deffuant. With the “Multi-by-one-one” option the agents discuss about one topic at time and the discussion goes on only if the two agents are agree on the previous topics (the order is: color, size and position); with the “Multi-Random” instead the agents discuss about only one, randomly chosen, topic if they are agree at least on two topics.
Mu is the parameter which controls the convergence in opinion, d is that which describes the tolerance of agents.


THINGS TO NOTICE

There are two graphics for each topic: the first one give a visual description of what it’s happened (each colored bar represents an opinion range and the width shows how many agents have that opinion); the second one is similar to the first one but presents the results in a histogram.
There are then three counters that shows how many interactions take place.


THINGS TO TRY

Holding the same parameter it’s possible to compare the results for different interaction types. It’s also possible to study how the parameter influence the dynamics: mu is related only with convergence time; d, instead, is responsible for the number of final opinion.


EXTENDING THE MODEL

It could be interesting add some other restrictions on the interaction or to study the dynamics with more topics for discussion. It could also be developed a similar model, in which not only the opinions are up-to-date but also the value of parameter d for each agent.


CREDITS AND REFERENCES

The starting point for this work is the following article:
"Mixing beliefs among interacting agents", G. Deffuant, D. Neau, F. Amblard and G. Weisbuch


PROCEDURES

globals [interactions2 interactions1 interactions3 temp1 temp2 temp3 templace]
turtles-own [opinion1 opinion2 opinion3  place]
breed [extremists100]
breed[extremists0]



;;;;;;;;;;;;;;;;;;;
;;;SETTING UP;;;;;;
;;;;;;;;;;;;;;;;;;;


to setup
  
  ca
  set-default-shape turtles "person"
  
  create-turtles Number-of-Agents [
    
    
    set interactions1 0   
    set interactions2 0
    set interactions3 0
    set size 5
    set place random 100  ; auxiliary variable used when "place" button is on, we create a "parallel" world
                          ; where the turtles move
    set opinion1 random 100 
    setxy opinion1 opinion1 ; each turtle is placed on the square diagonal according to its opinion 
     
    ifelse InteractionType = "Multi-OneByOne" or InteractionType = "Multi-Random" 
    
    ; initializing opinion values
    
        [set opinion2 random 100
         set opinion3 random 100]
        [set opinion2  -10 ; so they are not counted in the graphs for opinion 2 and opinion 3
         set opinion3  -10]
       
    ]
  
  if Extremists [
    
    create-extremists100 Extremists-100 [ ; the slider indicates the number of extremists
     
     set place random 100 
     set opinion1 100 
     setxy opinion1 opinion1
     set shape "face happy" ; 100 is better than 0
     set size 5
     set color white
    
    ifelse InteractionType = "Multi-OneByOne" or InteractionType = "Multi-Random" 
    
       ; in order to avoid plotting graphs of opinion 2/3
    
      [set opinion2  100
       set opinion3  100]
      [set opinion2  -10 
       set opinion3  -10]
     ]
    
    create-extremists0 Extremists-0  [
    
    set place random 100
    set opinion1 0 
    setxy opinion1 opinion1
    set size 5
    set shape "face sad"
    set color white
        
    ifelse InteractionType = "Multi-OneByOne" or InteractionType = "Multi-Random"
    
      [set opinion2 0
       set opinion3 0]
      [set opinion2  -10
      set opinion3  -10]    
    ]    
  
  
  ] ;end create
    
end

;;;;;;;;;;;;;;;;;;
;;;;;LET'S GO;;;;;
;;;;;;;;;;;;;;;;;;


to go

  if InteractionType = "Basic" [
  
  ask one-of turtles  [
  
      set temp1 opinion1  ;saves variables of the interatcting turtle in order to use it later in other procedures
      set templace place 
  
      interact
  
      set opinion1 temp1 ;completed the interaction, we update the old values
  
      setxy opinion1 opinion1 ; we graphically show the new opinion
      set color opinion1
  

  ]
  
  ; we reset the values for the extremists before plotting because they cannot change opinion,
  ; we chose to modify it temporarily and then to move them back to the original value
  
  if Extremists [
         ask extremists100 [set opinion1 100 setxy 100 100 set color white] 
         ask extremists0 [set opinion1 0 setxy 0 0 set color white ]
         ]
  
        
  ] ;end basic
  
if InteractionType = "Multi-OneByOne"[
  
  ask one-of turtles  [
  
      set temp1 opinion1 
      set temp2 opinion2
      set temp3 opinion3   
      set templace place 
     
      multi-interact-onebyone
  
      set opinion1 temp1
      set opinion2 temp2
      set opinion3 temp3
      
      setxy opinion3 opinion3
      set color opinion1
      set size (opinion2 / 10)
     
  ] ;endask
  
  if Extremists
                    [
                      ask extremists100 [set opinion1 100 set opinion2 100 set opinion3 100 set size 5 setxy 100 100 set color white] ; we reset the values for the extremists before plotting
                      ask extremists0 [set opinion1 0 set opinion2 0 set opinion3 0  set size 5 setxy 0 0 set color white ]
                      ]
  
  ];endif interaction
     
  if InteractionType = "Multi-Random"
  
  [
    ask one-of turtles  [
        set temp1 opinion1 
        set temp2 opinion2
        set temp3 opinion3  
        set templace place 
    
        multi-interact-random
    
        set opinion1 temp1
        set opinion2 temp2
        set opinion3 temp3
        
        setxy opinion3 opinion3
        set color opinion1
        set size (opinion2 / 10)
  

    
       
    ];endask
    
    if Extremists 
           [
           ask extremists100 [set opinion1 100 set opinion2 100 set opinion3 100 set size 5 setxy 100 100 set color white] ; we reset the values for the extremists before plotting
           ask extremists0 [set opinion1 0 set opinion2 0 set opinion3 0  set size 5 setxy 0 0 set color white ]
              ]
             
  ]    ;endif interaction 
  
  do-plots
  tick
  
end






;;;;;;;;;;;;;;;;;;;
;;; Interacting ;;;
;;;;;;;;;;;;;;;;;;;




 to interact
   
   ;with the place button on the turtles interact only with neighbouring turtles
   ifelse Place?
   
   [let partner one-of other turtles with  [ place < templace + range and place > templace - range ] ;range given by slider
   
     ifelse partner != nobody [
   
       ask partner [
      
         if  abs (temp1 - opinion1) < d [
        
           set opinion1 (opinion1 + mu *(temp1 - opinion1))   ; interaction equations
           set temp1 (temp1 + mu * (opinion1 - temp1)) 
           
           setxy opinion1 opinion1 ;we update the values of the partner
           set color opinion1
           
           set interactions1 (interactions1 + 1) ; we count the interaction number
           
          
      ] ; endif
     ] ;ask
    ] ;ifelse partner first option
   
   
   [ set place random 100] ; if in range there are no other turtles, the turtle moves on 
   ;if else partner second option
   
   ] ;ifelse Place?
   
   ; without "place" the turtles interact randomly
   [ ask one-of other turtles [  
   
     if abs (temp1 - opinion1) < d  [
     
      set opinion1 (opinion1 + mu *(temp1 - opinion1))   
      set temp1 (temp1 + mu * (opinion1 - temp1)) 
      setxy opinion1 opinion1
      set color opinion1
      set interactions1 (interactions1 + 1)
      ] ;endif
    ] ;endask
   ]; end block second ifelse Place?
      
 end
 
 
 to multi-interact-onebyone
      
   ifelse Place?
   
   [let partner one-of other turtles with  [ place < templace + range and place > templace - range ] 
   
     ifelse partner != nobody [
   
       ask partner [ 
       ;if-chain to take into consideration that the following opinion is discussed
       ; only if the previous one has been discussed before. The cylce is interrupted at the first "diasgreement"
      
         if  abs (temp1 - opinion1) < d [
        
           set opinion1 (opinion1 + mu *(temp1 - opinion1))   
           set temp1 (temp1 + mu * (opinion1 - temp1)) 
           set color opinion1
           set interactions1 (interactions1 + 1)
           
      
         
            if  abs (temp2 - opinion2) < d [
            
               set opinion2 (opinion2 + mu *(temp2 - opinion2))   
               set temp2 (temp2 + mu * (opinion2 - temp2)) 
               set size ( opinion2 / 10 ) ; we lose "resolution", but we need to rescale in order to avoid excessively huge turtles
               set interactions2 (interactions2 + 1)            
            
                                 
               if  abs (temp3 - opinion3) < d [
            
                  set opinion3 (opinion3 + mu *(temp3 - opinion3))   
                  set temp3 (temp3 + mu * (opinion3 - temp3)) 
                  setxy opinion3 opinion3
                  set interactions3 (interactions3 + 1)         

           ]; endif 3   
          ]; endif 2
         ] ; endif 1
         

      ] ;ask
     ] ;ifelse partner first option
   
   
   [ set place random 100] ;if else partner second option
   
   ] ;ifelse Place?
   
   [ ask one-of other turtles [  
   
    
         if  abs (temp1 - opinion1) < d [
        
           set opinion1 (opinion1 + mu *(temp1 - opinion1))   
           set temp1 (temp1 + mu * (opinion1 - temp1)) 
           set color opinion1
           set interactions1 (interactions1 + 1)
           
      
         
           if  abs (temp2 - opinion2) < d [
            
               set opinion2 (opinion2 + mu *(temp2 - opinion2))   
               set temp2 (temp2 + mu * (opinion2 - temp2)) 
               set size ( opinion2 / 10 )
               set interactions2 (interactions2 + 1)            
            
                   
              
               if  abs (temp3 - opinion3) < d [
            
                  set opinion3 (opinion3 + mu *(temp3 - opinion3))   
                  set temp3 (temp3 + mu * (opinion3 - temp3)) 
                   setxy opinion3 opinion3

                  set interactions3 (interactions3 + 1)            
            
            

           ]; endif 3   
          ]; endif 2 
        ] ; endif 1
     ] ;endask
   ]; end block second ifelse Place?
   
   
 end
 
 
 to multi-interact-random
  
 ; turtles interact in one opinion only if they agree on at least two opinions
   
   
   ifelse Place?
   
   [ let partner one-of other turtles with  [ place < templace + range and place > templace - range ] 
   
       ifelse partner != nobody [
   
       ask partner [
           let agreement 0 ; variable that counts the number of  opinions in range d
   
            if abs( temp1 - opinion1) < d [ set agreement (agreement + 1)]
            if abs( temp2 - opinion2) < d [ set agreement (agreement + 1)]
            if abs( temp3 - opinion3) < d [ set agreement (agreement + 1)]
            
            if agreement >= 2 [
            
            let numberopinion random 3 ; the interacting opinion is chosen at random
            
              if numberopinion = 0 [
                
                 set opinion1 (opinion1 + mu *(temp1 - opinion1))   
                 set temp1 (temp1 + mu * (opinion1 - temp1)) 
                 set color opinion1
                 set interactions1 (interactions1 + 1)

              
                   ];if 1
            
              if numberopinion = 1 [
                 set opinion2 (opinion2 + mu *(temp2 - opinion2))   
                 set temp2 (temp2 + mu * (opinion2 - temp2)) 
                 set size ( opinion2 / 10)
                 set interactions2 (interactions2 + 1)

                  ] ;if 2
            
            
             if numberopinion = 2  [
                 set opinion3 (opinion3 + mu *(temp3 - opinion3))   
                 set temp3 (temp3 + mu * (opinion3 - temp3)) 
                 setxy opinion3 opinion3
                 set interactions3 (interactions3 + 1)

                  ] ; if3
                        
            ];ifagreement    
       ];endask
   ];ifelse partner 1
              
       [set place random 100] ;ifelse partner 2
   ]    ;ifplace 1
   
   
   [
     
     ask one-of other turtles [
     
     let agreement 0
   
            if abs( temp1 - opinion1) < d [ set agreement (agreement + 1)]
            if abs( temp2 - opinion2) < d [ set agreement (agreement + 1)]
            if abs( temp3 - opinion3) < d [ set agreement (agreement + 1)]
            
            if agreement >= 2 [
            
            let numberopinion random 3
            
              if numberopinion = 0 [
                
                 set opinion1 (opinion1 + mu *(temp1 - opinion1))   
                 set temp1 (temp1 + mu * (opinion1 - temp1)) 
                 set color opinion1
                 set interactions1 (interactions1 + 1)
                 set place random 100                                                           ;DA TOGLIERE????????
              
                   ];if 1
            
              if numberopinion = 1 [
                 set opinion2 (opinion2 + mu *(temp2 - opinion2))   
                 set temp2 (temp2 + mu * (opinion2 - temp2)) 
                 set size ( opinion2 / 10)
                 set interactions2 (interactions2 + 1)
                 set place random 100 
                  ] ;if 2
            
            
             if numberopinion = 2  [
                 set opinion3 (opinion3 + mu *(temp3 - opinion3))   
                 set temp3 (temp3 + mu * (opinion3 - temp3)) 
                 setxy opinion3 opinion3
                 set interactions3 (interactions3 + 1)
                 set place random 100 
                  ] ; if3
                        
            ];ifagreement 
        ] ;endask
      ] ;ifplace 2 
   
   
   
 end
 
 
 





;;;;;;;;;;;;;;;;
;;; Plotting ;;;
;;;;;;;;;;;;;;;;


to do-plots
  
  set-current-plot "Topic1"
  
  set-plot-y-range 0 count turtles   

  let partial 0 ; remembers the number of turtles in the previous set in order to build a continuous coloured column
  set-current-plot-pen "5"
  plot-pen-up plotxy ticks partial
  set partial partial + count turtles with [opinion1 >= 0 and opinion1 <=  10]
  plot-pen-down plotxy ticks partial
  set-current-plot-pen "15"
  plot-pen-up plotxy ticks partial
  set partial partial + count turtles with [opinion1 > 10 and opinion1 <=  20]
  plot-pen-down plotxy ticks partial
   set-current-plot-pen "25"
  plot-pen-up plotxy ticks partial
  set partial partial + count turtles with [opinion1 > 20 and opinion1 <=  30]
  plot-pen-down plotxy ticks partial
   set-current-plot-pen "35"
  plot-pen-up plotxy ticks partial
  set partial partial + count turtles with [opinion1 > 30 and opinion1 <=  40]
  plot-pen-down plotxy ticks partial
   set-current-plot-pen "45"
  plot-pen-up plotxy ticks partial
  set partial partial + count turtles with [opinion1 > 40 and opinion1 <=  50]
  plot-pen-down plotxy ticks partial
  set-current-plot-pen "55"
  plot-pen-up plotxy ticks partial
  set partial partial + count turtles with [opinion1 > 50 and opinion1 <=  60]
  plot-pen-down plotxy ticks partial
   set-current-plot-pen "65"
  plot-pen-up plotxy ticks partial
  set partial partial + count turtles with [opinion1 > 60 and opinion1 <=  70]
  plot-pen-down plotxy ticks partial
   set-current-plot-pen "75"
  plot-pen-up plotxy ticks partial
  set partial partial + count turtles with [opinion1 > 70 and opinion1 <=  80]
  plot-pen-down plotxy ticks partial
   set-current-plot-pen "85"
  plot-pen-up plotxy ticks partial
  set partial partial + count turtles with [opinion1 > 80 and opinion1 <=  90]
  plot-pen-down plotxy ticks partial
   set-current-plot-pen "95"
  plot-pen-up plotxy ticks partial
  set partial partial + count turtles with [opinion1 > 90 and opinion1 <=  101]
  plot-pen-down plotxy ticks partial
  
  
  
  set-current-plot "Topic2"  
  
  set-plot-y-range 0 count turtles  

  let partial2 0
  set-current-plot-pen "5"
  plot-pen-up plotxy ticks partial2
  set partial2 partial2 + count turtles with [opinion2 >= 0 and opinion2 <=  10]
  plot-pen-down plotxy ticks partial2
  set-current-plot-pen "15"
  plot-pen-up plotxy ticks partial2
  set partial2 partial2 + count turtles with [opinion2 > 10 and opinion2 <=  20]
  plot-pen-down plotxy ticks partial2
   set-current-plot-pen "25"
  plot-pen-up plotxy ticks partial2
  set partial2 partial2 + count turtles with [opinion2 > 20 and opinion2 <= 30]
  plot-pen-down plotxy ticks partial2
   set-current-plot-pen "35"
  plot-pen-up plotxy ticks partial2
  set partial2 partial2 + count turtles with [opinion2 > 30 and opinion2 <= 40]
  plot-pen-down plotxy ticks partial2
   set-current-plot-pen "45"
  plot-pen-up plotxy ticks partial2
  set partial2 partial2 + count turtles with [opinion2 > 40 and opinion2 <= 50]
  plot-pen-down plotxy ticks partial2
  set-current-plot-pen "55"
  plot-pen-up plotxy ticks partial2
  set partial2 partial2 + count turtles with [opinion2 > 50 and opinion2 <= 60]
  plot-pen-down plotxy ticks partial2
   set-current-plot-pen "65"
  plot-pen-up plotxy ticks partial2
  set partial2 partial2 + count turtles with [opinion2 > 60 and opinion2 <= 70]
  plot-pen-down plotxy ticks partial2
   set-current-plot-pen "75"
  plot-pen-up plotxy ticks partial2
  set partial2 partial2 + count turtles with [opinion2 > 70 and opinion2 <= 80]
  plot-pen-down plotxy ticks partial2
   set-current-plot-pen "85"
  plot-pen-up plotxy ticks partial2
  set partial2 partial2 + count turtles with [opinion2 > 80 and opinion2 <= 90]
  plot-pen-down plotxy ticks partial2
   set-current-plot-pen "95"
  plot-pen-up plotxy ticks partial2
  set partial2 partial2 + count turtles with [opinion2 > 90 and opinion2 <= 100]
  plot-pen-down plotxy ticks partial2
  
   
  set-current-plot "Topic3"  
  
  set-plot-y-range 0 count turtles  

  let partial3 0
  set-current-plot-pen "5"
  plot-pen-up plotxy ticks partial3
  set partial3 partial3 + count turtles with [opinion3 >= 0 and opinion3 <= 10]
  plot-pen-down plotxy ticks partial3
  set-current-plot-pen "15"
  plot-pen-up plotxy ticks partial3
  set partial3 partial3 + count turtles with [opinion3 > 10 and opinion3 <= 20]
  plot-pen-down plotxy ticks partial3
   set-current-plot-pen "25"
  plot-pen-up plotxy ticks partial3
  set partial3 partial3 + count turtles with [opinion3 > 20 and opinion3 <= 30]
  plot-pen-down plotxy ticks partial3
   set-current-plot-pen "35"
  plot-pen-up plotxy ticks partial3
  set partial3 partial3 + count turtles with [opinion3 > 30 and opinion3 <= 40]
  plot-pen-down plotxy ticks partial3
   set-current-plot-pen "45"
  plot-pen-up plotxy ticks partial3
  set partial3 partial3 + count turtles with [opinion3 > 40 and opinion3 <= 50]
  plot-pen-down plotxy ticks partial3
  set-current-plot-pen "55"
  plot-pen-up plotxy ticks partial3
  set partial3 partial3 + count turtles with [opinion3 > 50 and opinion3 <= 60]
  plot-pen-down plotxy ticks partial3
   set-current-plot-pen "65"
  plot-pen-up plotxy ticks partial3
  set partial3 partial3 + count turtles with [opinion3 > 60 and opinion3 <= 70]
  plot-pen-down plotxy ticks partial3
   set-current-plot-pen "75"
  plot-pen-up plotxy ticks partial3
  set partial3 partial3 + count turtles with [opinion3 > 70 and opinion3 <= 80]
  plot-pen-down plotxy ticks partial3
   set-current-plot-pen "85"
  plot-pen-up plotxy ticks partial3
  set partial3 partial3 + count turtles with [opinion3 > 80 and opinion3 <= 90]
  plot-pen-down plotxy ticks partial3
   set-current-plot-pen "95"
  plot-pen-up plotxy ticks partial3
  set partial3 partial3 + count turtles with [opinion3 > 90 and opinion3 <= 100]
  plot-pen-down plotxy ticks partial3
  
  
  set-current-plot "Turtles-Opinion1"
    
   
    histogram [opinion1] of turtles
    set-histogram-num-bars 10
  
 set-current-plot "Turtles-Opinion2"
    
   
    histogram [opinion2] of turtles
    set-histogram-num-bars 10
 
 set-current-plot "Turtles-Opinion3"
    
   
    histogram [opinion3] of turtles
    set-histogram-num-bars 10
end