powered by NetLogo
view/download model file: GeneralEvolutionaryModel.nlogo
This is a generic evolutionary game theoretic model.
100 turtles are present intially, with initial-S number of them playing the "S" strategy
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.
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. For simplicity, when a new turtle is created, another randomly selected turtle dies.
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: INITIAL S: set number of players playing S
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
Try different games: prisoner's dilemma, presentation-exam, dove-hawk. Is there an evolutionarily stable strategy?
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.
globals [ ;;number of turtles with each strategy num-S num-T ] turtles-own [ score 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 virus set a 4 set b 3 set c 8 set d 2 ask turtles [set shape "monster"] end to hawk-dove set a 0 set b 5 set c 1 set d 3 ask turtles with [strategy = "T"] [set shape "bird"] ask turtles with [strategy = "S"] [set shape "bird side"] end to hunter set a 4 set b 0 set c 3 set d 3 ask turtles with [strategy = "T"] [set shape "rabbit"] ask turtles with [strategy = "S"] [set shape "sheep 2"] end to mod-hunter set a 4 set b 0 set c 4 set d 3 ask turtles with [strategy = "T"] [set shape "rabbit"] ask turtles with [strategy = "S"] [set shape "sheep 2"] 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 let initial-S (initial-S-percent / 100 * num-turtles) crt initial-S [ set strategy "S" set color red ] crt (num-turtles - initial-S) [ set strategy "T" set color blue ] end ;;set the variables that all turtles share to setup-common-variables ask turtles [ set score 5 set partnered? false set partner nobody setxy random-xcor random-ycor ] end ;;;;;;;;;;;;;;;;;;;;;;;; ;;;Runtime Procedures;;; ;;;;;;;;;;;;;;;;;;;;;;;; to go clear-last-round 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] ask one-of turtles [die] ] 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 "" 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") [ ifelse ([strategy] of partner = "S") [ set score (score + a) set label a ] [ set score (score + b) set label b ] ] [ 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.