powered by NetLogo

view/download model file: GeneralMixedEvolutionaryModel.nlogo

WHAT IS IT?

This is a generic evolutionary game theoretic model, that allows for mixed strategies.


HOW IT WORKS

100 turtles are present intially, with initial-S number of them playing the "S" strategy

Payoffs

The game is symmetric and the payoffs are as follows

             | Player 2's action
Player 1's |
Action | S T
------------|-----------------
S | a,a b,c
------------|-----------------
T | c,b d,d
------------|-----------------

Turtles move around randomly. If they find a partner close enough, they play a game, executing their strategies, and reap the payoff determined by the above matrix.

After each round, each turtle that had a partner checks to see if it has a high enough score to reproduce. If it reproduces, its score decreases by a fixed amount, which is then transferred to be the score of its offspring. The offspring copy the parents' strategy (the probability of playing "S"), but the mutate the probability a bit to allow the population to find the best mixed strategy. For simplicity, when a new turtle is created, another randomly selected turtle dies.


HOW TO USE IT

Buttons:

SETUP: Setup the world to begin playing.

GO: Have the turtles walk around the world and interact.

GO ONCE: Same as GO except the turtles only take one step.

Sliders:
FIXED-PROBABILITY: set every player's probability of playing strategy S to be this value. You have to press the "FIX-PROBS" button for this to take effect

REPRODUCTION-COST: how much it costs a player to reproduce (the offspring will start with a score equal to the REPRODUCTION-COST

NUM-TURTLES: the total number of turtles, which will take effect once you hit "SETUP"

Plots: STRATEGY-COUNT plots the number of turtles playing each strategy over time


THINGS TO TRY

Try and see if p = 1/3 is a stable equilibrium for a dove-hawk game.

Test other games: prisoner's dilemma, coordination, presentation/exam.


COPYRIGHT NOTICE

Copyright 2002 Uri Wilensky. All rights reserved.
Heavily modified by Lada Adamic 2011

Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed:
a) this copyright notice is included.
b) this model will not be redistributed for profit without permission from Uri Wilensky. Contact Uri Wilensky for appropriate licenses for redistribution for profit.

This model was created as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227.


PROCEDURES

globals [
  ;;number of turtles with each strategy
]

turtles-own [
  score
  prob-S
  strategy
  partnered?        ;;am I partnered?
  partner           ;;WHO of my partner (nobody if not partnered)
]


;;;;;;;;;;;;;;;;;;;;;;
;;;Setup Procedures;;;
;;;;;;;;;;;;;;;;;;;;;;

to setup
  ca
  make-turtles
  setup-common-variables
end

to hawk-dove
  set a 2
  set b 1
  set c 3
  set d 0
end


to virus
  set a 4
  set b 3
  set c 8
  set d 2
  ask turtles   [set shape "monster"]
end

;;setup the turtles and distribute them randomly
to setup-turtles
  make-turtles ;;create the appropriate number of turtles playing each strategy
  setup-common-variables ;;sets the variables that all turtles share
end

;;create the appropriate number of turtles playing each strategy
to make-turtles
  crt num-turtles
end

;;set the variables that all turtles share
to setup-common-variables
  ask turtles [
    set score 5
    set prob-S random 100
    set partnered? false
    set partner nobody
    setxy random-xcor random-ycor
    set color prob-S + 5
  ]
end

to fix-probabilities
  ask turtles [
    set prob-S fixed-probability * 100
    set color prob-S + 5
  ]
end

;;;;;;;;;;;;;;;;;;;;;;;;
;;;Runtime Procedures;;;
;;;;;;;;;;;;;;;;;;;;;;;;

to go
  clear-last-round
  ask turtles [
    ifelse random 100 <= prob-S 
    [ set strategy "S"]
    [ set strategy "T"]
  ]
  ask turtles [ partner-up ]                        ;;have turtles try to find a partner
  let partnered-turtles turtles with [ partnered? ]
  ask partnered-turtles [ 
    play-a-round
  ]
  ask partnered-turtles [
    reproduce
  ]
  do-plotting
  tick
end

to reproduce  ;; turtle procedure
  if score > (2 * reproduction-cost) [
    set score score - reproduction-cost
    hatch 1 [
      set score reproduction-cost
      if (random 100 < 50) [mutate]
      set color prob-S + 5
    ]
    ask one-of turtles [die]
  ]
end

to mutate
      set prob-S prob-S + (random 2) - 0.5
      if (prob-S < 0) [set prob-S 0]
      if (prob-S > 100) [set prob-S 100]
end

to clear-last-round
  let partnered-turtles turtles with [ partnered? ]
  ask partnered-turtles [ release-partners ]
end

;;release partner and turn around to leave
to release-partners
  set partnered? false
  set partner nobody
  rt 180
;  set label score
end

;;have turtles try to find a partner
;;Since other turtles that have already executed partner-up may have
;;caused the turtle executing partner-up to be partnered,
;;a check is needed to make sure the calling turtle isn't partnered.

to partner-up ;;turtle procedure
  if (not partnered?) [              ;;make sure still not partnered
    rt (random-float 90 - random-float 90) fd 1     ;;move around randomly
    set partner one-of (turtles-at -1 0) with [ not partnered? ]
    if partner != nobody [              ;;if successful grabbing a partner, partner up
      set partnered? true
      set heading 270                   ;;face partner
      ask partner [
        set partnered? true
        set partner myself
        set heading 90
      ]
    ]
  ]
end

to play-a-round ;;turtle procedure
  ifelse (strategy = "S") [
    set shape "bird side"
    set size  1
    ifelse ([strategy] of partner = "S") [
      set score (score + a) ;set label a
    ] [
      set score (score + b) ;set label b
    ]
  ] [
    set shape "bird"
    set size 0.9
    ifelse ([strategy] of partner = "S") [
      set score (score + c) ;set label c
    ] [
      set score (score + d) ;set label d
    ]
  ]
end


;; returns the total score for a strategy if any turtles exist that are playing it
to-report calc-score [strategy-type num-with-strategy]
  ifelse num-with-strategy > 0 [
    report (sum [ score ] of (turtles with [ strategy = strategy-type ]))
  ] [
    report 0
  ]
end

;;if a strategy has had any interactions, plot the average score per interaction
to do-plotting
  set-current-plot "strategy-count"
  set-current-plot-pen "S"
  plot count turtles with [strategy = "S"]
  set-current-plot-pen "T"
  plot count turtles with [strategy = "T"]
end


; Copyright 2002 Uri Wilensky. All rights reserved.
; The full copyright notice is in the Information tab.