This page was automatically generated by NetLogo 5.0.4.

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 (criminality_prog_18.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: criminality_prog_18.nlogo

WHAT IS IT?

Criminal behavior has been explained by rational or normative arguments. This is a game theoretical framework of criminal behavior integrating both concepts. Specifically the modeling includes three factors which are the gain from criminality, norm abiding behavior and social pressure from peers.

HOW IT WORKS

Pseudo code

Basically each period, a sub-population of agents (slider = acting-agent) choose an action $red = taking a criminal action$ or $green = staying honest$. An agent i choose the action having the maximum average utility. Utility is composed of the relative gain from criminality (G) and an emotional part depending of the actions of other players in agent’s i neighborhood.

                                                     Other player
                                             Stay honest      Take an illegal action
           Stay honest   (green)                   0               -X   
agent i   
             Take an illegal action (red)          G - Y              G 

X is a idiosyncratic random variable for agent i with a Bernouilli distribution with probability of succes (X=1) = p. If not X=0. X= 0 corresponds thus to an individual not sensitive to criminal pressure whereas X=1 to sensitive individuals. The higher p the more individual sensitive to criminals’ pressure. p could thus mimick the impact of population concentration on parental control. The higher population concentration the less control. Think on residential areas versus suburbs. Y has a uniform distribution on [0,1] and corresponds to the guilt an agent i has by taking a illegal action if he faces a honest neighbor.
Average utility is computed by taking the effective proportion of honest agents in i’s neighborhood. The optimal action is the one maximizing average utility. Each period, a number of acting-agents choose their action given the rate of criminality in their neighborhood. They are happy if criminality in their neighborhood is less than their tolerance rate. If agents are allowed to move, then an unhappy agent moves to a new place with a lower criminality rate if available. A new period starts.

Honest agents are happy if the rate of criminality in their neighborhood is less than their tolerance for criminality. They are unhappy otherwise. Criminals are happy if the rate of criminality in their neighborhood is between a minimal and maximal tolerance rate for criminality. The minimal and maximal tolerance rate for criminals is set to mimick the fact that criminals may be interested in having some criminals around them (to create a ghetto for criminality or to escape police attention for example) but not to much (because it may end up in rivalry about competitive groups for example). In a first step we fix the minimal tolerance rate for criminals to zero and the maximal.
Only unhappy agents move if move is allowed. Honests agents move to a nex place if criminality there is lower than criminality of the current place. Criminals move to a new place if criminality there is within their minimum and maximum tolerance rate of criminals as given by sliders Crm-tol-min and Crim-tol-max.

The general procedure for one period is the following:

HOW TO USE IT

You can choose to let criminal move or not (button move on or off). Fix the relative gain from criminality: if positive then criminality pays more than honesty. Choose p which is the proportion of agent sensitive to social pressure from criminals. p may be thought as a good proxy for the degree of parental control relative to the quality of the living environments. For example, in a suburb with high rises it may be more difficult to exert effective parental control and p may then be higher than in residential areas.

THINGS TO NOTICE

Polymorphic equilibria, i.e. coexistence of criminals and honest people, may exist with the result that higher gain from criminality, lower adherence to the legal norm or higher social pressure from peers never lowers criminality. In addition, the spatial structure of interaction is one factor of segregative criminality. Interactions within a fixed small number of neighbors leads to higher spatial inequality than within larger groups.

THINGS TO TRY

Change the neighborhood size of agents:
- look at the effect of neighborhood size on the level of honests compared to the expected equilibrium
- look at the segregation level as a function of neighborhood size.
- allow agents to move and look at segregation and criminality levels
- test different levels of social pressure p or gain from criminality G.

EXTENDING THE MODEL

NETLOGO FEATURES

This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features. Acting agents are the number of agents plying the game each period.

RELATED MODELS

Segregated cooperation in a prisoner’s dilemma.

CREDITS AND REFERENCES

The segregation and interaction procedure has been inspired from Sebastian Grauwin
http://ccl.northwestern.edu/netlogo/models/community/Segreg-vs-coord . All errors my own.
seed-procedure by Uri Wilensky.

PROCEDURES

CODE

; WRITTEN BY Roger Waldeck


globals [

list-happy?
radius-n 
my-seed1
honest
%-honest
k
%-happy-turtles
random-mixed-pairs
mixed-pairs
segregation
; mean-segreg
GL
GI
gain-of-sI
gain-of-sL
moving-turtle
tab-strategy
tab-X
tab-Y
happy-list
criminal-list
potential-criminality
G
mean-X-of-honest
mean-Y-of-honest
 mean-X-of-criminals
  mean-Y-of-criminals
  eta* ; expected equilibrium
  eta1
  eta2
]

turtles-own [
 
  X                    ; emotion of one turtle
  Y                    ; emotion of one turtle
  decision
  similar-nearby              ; how many neighboring patches have a turtle with my color?
  other-nearby                ; how many  turtles of a different  color in the sample of the calling turtle
  red-nearby                  ; count of red turtles in the sample
  green-nearby                ; count of green turtles in the sample
    tot-nearby              ;  red-nearby   + green-nearby 
  %red-nearby 
  %green-nearby 
  happy?                     ; if = 1 turtle is unhappy and if equal to 0 the turtle is happy    
   

]

;;;;;;;;;;;;;; SETUP PROCEDURE ;;;;;;;;;;;

to setup 
  ;; (for this model to work with NetLogo's new plotting features,
  ;; __clear-all-and-reset-ticks should be replaced with clear-all at
  ;; the beginning of your setup procedure and reset-ticks at the end
  ;; of the procedure.)
  ;set Ymax 1
  __clear-all-and-reset-ticks
  ifelse seed-procedure [  use-seed-from-user ][ use-new-seed ]
   set list-happy? []
   set G   relative-gain-from-criminality         ; ( GI - GL)
  create-population
  choose-size
  setup-list
  update-globals
  Compute-expected-equilibrium
   do-plots
   end

to use-seed-from-user
 ; set my-seed read-from-string user-input "Enter a random seed (an integer):"
  ; output-print word "User-entered seed: " my-seed  ;; print it out
  random-seed my-seed             ;; use the new seed
end

to use-new-seed
  set my-seed1 new-seed            ;; generate a new seed
  output-print word "Generated seed: " my-seed1  ;; print it out
  random-seed my-seed1             ;; use the new seed
end

to choose-size

if (neighborhood-size = "8-cells") [set radius-n 1.5 set  k  8 ]

if (neighborhood-size = "24-cells") [set radius-n 2.9 set k  24 ]
     
if (neighborhood-size = "44-cells") [set radius-n 3.9 set k  44 ]   

if (neighborhood-size = "100-cells") [set radius-n 5.7 set k  100 ]  ; CARE WHEN population = 100 k= 90 due to border effects: probably the distance between patches at opposite side (which are in touch indeed if wrap) is not 1
 

end

To  create-population 
  set-default-shape turtles "circle"  
    ask n-of population patches
    [sprout 1 [set color red  set Y (random-float  Ymax) if (social-pressure)[  let alea (random-float 1) ifelse ( alea < p)  [set X  1][set X  0]  ] ] ]       
  ask n-of   (population * %-honest-at-setup / 100) turtles [ set color green ] 
       
end
 

to  setup-list ; OK
  set tab-strategy n-values population  [0] ;turtles list of 1 (cooperator) and 0 (defectors)
  set tab-X n-values population  [0] ; turtles list of emotions
  set tab-Y n-values population  [0] ; turtles list of emotions
  set happy-list n-values population  [0]
  set criminal-list n-values population  [0]
  

  foreach sort  turtles [ask  ? [
    ifelse [color] of self = green [set decision 1][set decision 0] ; for counts the number of green B= 1 and number of red B=0
    set red-nearby (count (other turtles-on patches in-radius radius-n) with [color = red])
     set green-nearby (count (other turtles-on patches in-radius radius-n) with [color = green] )
     set tot-nearby (red-nearby + green-nearby)   
    ifelse tot-nearby != 0 [  set %green-nearby  ( green-nearby / tot-nearby) set %red-nearby  ( red-nearby / tot-nearby) ][ set %green-nearby  0 set %red-nearby 0] 
      
     set tab-strategy  replace-item who tab-strategy decision    ;  the array are ranged according to who numbers and value = numberB for all turtles
     set  tab-X replace-item who tab-X  X   ; creates the array of turtles emotions ordered by who numbers
     set  tab-Y replace-item who tab-Y  Y
     set  happy-list replace-item who happy-list  0   
     set  criminal-list replace-item who criminal-list  %red-nearby    ;  la liste pour tous les turtles de leur % de criminel dans le voisinage
     
     
     ] ]
  end 




;;;;; GO PROCEDURE ;;;;;; 

to go
ask n-of acting-agents turtles [ choose-strategy   update-tab-strategy   ] ; play-lottery 
update-unhappy ; the procedure updtates two lists of turtles parameters by who number:1. the happiness of turtles 2. The %  of criminal nearby.


;ifelse (all? turtles [happy? = 1] and (ticks >= number-ticks)    or ( %-honest = 100 or %-honest = 0 )  ) [ stop ]   [  if move and   (%-happy-turtles != 1) [ move-unhappy-turtles  ]] ; j'ai remplacer par la ligne suivante pour behavior space 
if (move and   (%-happy-turtles != 1 )) [ move-unhappy-turtles  ]
update-globals
  do-plots
  tick
  end


to choose-strategy ; turtle procedure
            
            set gain-of-sI ( %red-nearby * ( G + X)) 
      set gain-of-sL (   (1 - %red-nearby) * (Y - G) )
      let alea  random-float 1
          ifelse alea < epsilon 
                [let randomNumber1 random 2   ifelse (randomNumber1 = 1) [set decision 1 set color green][set decision 0 set color red]  ]                               
                       
                [ ifelse (gain-of-sL = gain-of-sI ) 
          [let randomNum 2  ifelse ( randomNum = 1 ) [set decision 1 set color green ][set decision 0 set color red]]
          [if  (gain-of-sL  > gain-of-sI ) [set decision 1 set color green]  
          if  (gain-of-sL  < gain-of-sI )  [set decision 0 set color red]]] 
  end

;to play-lottery ;turtle procedure
; ask turtles with [color = brown]  [ let alea1  random-float 1 ifelse (alea1 < f)  [set decision 0 set color green ][set happy? 1]] 
;  ask turtles with [color = red] 
 ;     [ let alea  random-float 1 ifelse (alea < q) [set color brown ][set happy? 0]] 
; set Prisoners  count turtles with [color  = brown] 
;end


to update-tab-strategy
  set tab-strategy replace-item who tab-strategy decision   
      
end


to update-globals 
  update-honest 
  updtate-emotions-of-agents
   report-segreg 
   
end


to update-honest
  set honest sum  tab-strategy 
  set %-honest (honest * 100 / population)  ; scale 100
end


to updtate-emotions-of-agents
Ifelse ((social-pressure) and (p != 0)) 
  [ Ifelse (%-honest != 0 ) [set mean-X-of-honest (   sum   [X] of turtles with [decision = 1]) /  honest ][ set mean-X-of-honest "NA"] ]  ; émotions moyenne des honest
[ set mean-X-of-honest "NA"]

  Ifelse (Ymax != 0) 
    [Ifelse (%-honest != 0)[set mean-Y-of-honest (sum   [Y] of turtles with [decision = 1]) / honest][set mean-Y-of-honest "NA"] ]
    [ set mean-Y-of-honest "NA"]
    
 Ifelse ((social-pressure) and (p != 0))
 [Ifelse (%-honest != 100 )  [  set mean-X-of-criminals (  sum   [X] of turtles with [decision = 0]) /  (population - honest)] [set mean-X-of-criminals "NA"] ] ; émotions moyenne des criminels
 [ set mean-X-of-criminals "NA"]

 Ifelse (Ymax != 0)
 [ Ifelse ( %-honest != 100 )   [  set mean-Y-of-criminals (sum   [Y] of turtles with [decision = 0]) / (population - honest) ] [ set mean-Y-of-criminals "NA"] ]
   [ set mean-Y-of-criminals "NA"]
 end





to update-unhappy ;  the procedure updtates two lists of turtles parameters by who number:1. the happiness of turtles 2. The %  of criminal nearby.
  ask-concurrent turtles  [
    set red-nearby (count (other turtles-on patches in-radius radius-n) with [color = red])
     set green-nearby (count (other turtles-on patches in-radius radius-n) with [color = green] )
     set tot-nearby (red-nearby + green-nearby)   
    ifelse tot-nearby != 0 [ set  %green-nearby (green-nearby / tot-nearby)  set %red-nearby  ( red-nearby / tot-nearby) ][ set  %green-nearby 0 set %red-nearby 0] 
             
           ifelse ([color] of self = red ) [  ifelse (Crim-Tol-min <= %red-nearby) and (Crim-Tol-max >= %red-nearby) [set happy? 1] [set happy? 0]  ] 
             [  ifelse %red-nearby <= Honest-Tol-max [set happy? 1] [set happy? 0]  ]
  set happy-list  replace-item who happy-list happy?     
   set  criminal-list replace-item who criminal-list  %red-nearby 
 ]  
  set %-happy-turtles (sum happy-list / population )         
end

 

to move-unhappy-turtles ; code 
   
 ifelse ( any? patches with [(not any? turtles-here)]  )   
 [
 let potential-new-place one-of  patches with [(not any? turtles-here)  ] 
  ask  potential-new-place [
    
     
   let red-nearby-new-place (count ( turtles-on patches in-radius radius-n) with [color = red]) 
   let green-nearby-new-place (count ( turtles-on patches in-radius radius-n) with [color = green]) 
   
   ifelse (red-nearby-new-place  + green-nearby-new-place) != 0 
  [ set potential-criminality (red-nearby-new-place / (red-nearby-new-place  + green-nearby-new-place ))][set potential-criminality 0]
    ] 
           
    let potential-mover   one-of   turtles  with [ happy? = 0 ] 
   ifelse [color] of potential-mover = green 
   [ ifelse (potential-criminality <  [%red-nearby] of  potential-mover)
     [  ask potential-mover  [  move-to potential-new-place ] update-unhappy ] 
     []
   ]
   [ ifelse ((crim-tol-max >= potential-criminality) AND (potential-criminality >= crim-tol-min) )
     [ ask potential-mover  [ move-to potential-new-place ] update-unhappy] 
     [  ]]
            
                       
 ]
 
  [    output-write   "No space free to move"   ]

end
 
  
 
to report-segreg 
   
   ifelse (%-honest != 0)   and (100 - %-honest  != 0)  
   [ set random-mixed-pairs ( ( k * (%-honest / 100) * (1 - (%-honest / 100)) * population ^ 2  )/ ((max-pxcor + 1) * (max-pycor + 1))  )
        ask turtles [ set other-nearby (count other turtles in-radius radius-n with [color != [color] of myself]) ]
        set mixed-pairs  (sum [other-nearby] of turtles) / 2   
    set  segregation  100 * (1 - (mixed-pairs /  random-mixed-pairs)) ]
   [set  segregation 0]
   

  end 
       
   
to Compute-expected-equilibrium
  if (social-pressure = false ) [ set p  0] 
  
  if (G <= 0) [ 
    
    let eta-  100 * 0.5 * (p + 1 - ( (1 + p  ) ^ 2 - 4 * p * ( G + 1  ) ) ^ 0.5 )  print eta- 
     
      
  ifelse (p < 1 / 2 - G / 2 ) [ set eta* 100]
      
      [ 
    ifelse      ( %-honest-at-setup <  eta-  )    [set eta* 100 * (1 - p)][set eta* 100 ]            ]
    
    
    
    
    ] 
 
 
 
  
  if (G > 0 ) 
      [ let delta1 ( (1 - p  )^ 2 - 4 * G * (1 - p  ) )  let delta2    (1 + p  )^ 2 - 4 * (G + p  ) 
            if   ( (delta1  >= 0 )  and   ( delta2  >= 0 ) ) 
                   [ set eta1   100 * 0.5 * ( (1 - p  ) - delta1 ^ 0.5 )   
                     set eta2   100 *  0.5 * ( (1 + p  ) -  delta2 ^ 0.5 ) 
                                ifelse (%-honest-at-setup  > eta2 )   
                                     [set  eta*     100 * 0.5 * ( (1 + p  ) + delta2 ^ 0.5 )  ]
                                     [ifelse (%-honest-at-setup > eta1 ) [set  eta*   100 * 0.5 * ( (1 - p ) + delta1 ^ 0.5 )][set eta*   0]]
                   ]
             if   ( (delta1  >= 0 )  and   ( delta2  < 0 ) ) 
                   [ set eta1   100 * 0.5 * ( (1 - p  ) - delta1 ^ 0.5 )   
                      
                           ifelse (%-honest-at-setup > eta1 ) [set  eta*   100 * 0.5 * ( (1 - p ) + delta1 ^ 0.5 )][set eta*   0]
                           ]
                         
             
             if   ( (delta1  < 0 )  and   ( delta2  >= 0 ) ) 
                   [ set eta2   100 *  0.5 * ( (1 + p  ) -  delta2 ^ 0.5 )   
                      
                           ifelse (%-honest-at-setup > eta2 ) [set  eta*   100 * 0.5 * ( (1 + p  ) + delta2 ^ 0.5 ) ] [set eta*   0]
                    ]
             
             if   ( (delta1  < 0 )  and   ( delta2  < 0 ) ) 
                   [set eta*   0]
                    
                      
  
     ]
end 

 
to do-plots
  
        
  
  
  set-current-plot "happy-turtles"
  ;set-plot-x-range 0   number-ticks
   set-current-plot-pen "%-happy-turtles"
  if ticks >= 1 [ plot %-happy-turtles]
  
  ; set-current-plot-pen "unhappy-turtles"
  ; plot unhappy-turtles
  
   set-current-plot "Segregation"
  ;set-plot-x-range 0   number-ticks
 set-current-plot-pen "segregation"
  plot segregation
  ; set-current-plot-pen "mean-segreg"
 ; plot mean-segreg
  
  set-current-plot "honest"
   set-current-plot-pen "% of honests"
   plot %-honest
   set-current-plot-pen "eta*"
   plot eta* 
   
  ; set-current-plot "histogram emotions"
   ;  set-histogram-num-bars 10
   ;  histogram [emotion] of turtles
  
  set-current-plot "emotions"
  ;set-plot-x-range 0   number-ticks
  set-current-plot-pen "Av. X-of-honest"
   If ((social-pressure) and (p != 0) and (%-honest != 0 )) [plot mean-X-of-honest] 
  set-current-plot-pen "Av. Y-of-honest"
  If (%-honest != 0) [plot mean-Y-of-honest]
 set-current-plot-pen "Av. Y-of-criminals"
 If (%-honest != 100) [ plot mean-Y-of-criminals ]
  set-current-plot-pen "Av. X-of-criminals"
If ((social-pressure) and (p != 0) and (%-honest != 100 ))  [plot  mean-X-of-criminals]
  
  
  
  
 ; set-current-plot "honest X"
 ;    set-histogram-num-bars 5
;If ((social-pressure) and (p != 0)) [  histogram   [X] of turtles with [color = green]]
     
       set-current-plot "Histogram  Y of Honests"
     set-histogram-num-bars 10
   If (Ymax != 0) [ histogram   [Y] of turtles with [color = green] ]
     
   ;   set-current-plot "Criminal X"
   ;  set-histogram-num-bars 5
 ;  If ((social-pressure) and (p != 0)) [   histogram   [X] of turtles with [color = red]]
     
       set-current-plot "Histogram  Y of Criminals"
     set-histogram-num-bars 10
      If (Ymax != 0) [ histogram   [Y] of turtles with [color = red]]
  
 
   
end