MLS demo 3.2

MLS demo 3.2 preview image

1 collaborator

Default-person William Driscoll (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.0.4 • Viewed 92 times • Downloaded 14 times • Run 0 times
Download the 'MLS demo 3.2' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Info tab cannot be displayed because of an encoding error

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [global-ticks within-group-var among-group-var freqA binsA wg5 wg4 wg3 wg2 wg1 ag5 ag4 ag3 ag2 ag1]
patches-own [grid quality Kp mean-A var-A]
turtles-own [A reproductive?]

to Setup
  clear-all
  crt (count patches * p * K * (1 - survival))
  [set size t-size face one-of patches fd (1 + random (5 * max-pycor)) set shape "dot" set A (random-float 1) set-turtle-color]
  ask patches [set quality 0 set grid 1]
  if grid? = 1 [ask patches [let n ((pycor + pxcor) / 2) ifelse round n = n [set grid 1] [set grid 0]]] ; Create a grid pattern by choosing patches with even products of x and y coordinates
  ask n-of (p * count patches with [grid = 1]) patches with [grid = 1] [set quality 1 set Kp (quality * K)]
  ask patches [assign-colors]
  ask turtles [ifelse [quality] of patch-here = 0 [die] [move-to patch-here]]
  if Discrete? = 1 [ask turtles [set A round A set-turtle-color]]
  initial-math
  set global-ticks 0
  reset-ticks
end 

to Go
  ask turtles [set reproductive? 1 set-turtle-color]
  interact
  migrate?
  ;assign-colors
  if ticks > duration [reshuffle reset-ticks]
  do-math
  set global-ticks (global-ticks + 1)
  tick
end 

to set_A=0
  ask turtles [set A 0 set shape "dot" set size t-size set-turtle-color]
  ask patches [set Kp (K * quality) assign-colors]
end 

to set_A=1
  ask turtles [set A 1 set shape "dot" set size t-size set-turtle-color]
  ask patches [set Kp (K * quality) assign-colors]
end 

to summon_altruist
  ;crt 1 [set size t-size * 1 set shape "dot" move-to one-of patches with [quality = 0] ask patch-here [set quality 1 set Kp K] set A 1 set-turtle-color follow-me]
  crt 1 [set size t-size * 1 set shape "dot" move-to one-of patches with [quality = 1 and grid = 1]
    ask patch-here [set quality 1 set Kp K set pcolor blue] set A 1 set-turtle-color ask turtles-here with [A < 0.5] [die]]
end 

to summon_cheater
  crt 1 [set size t-size * 1 set shape "dot" move-to one-of patches with [quality = 1 and grid = 1] ask patch-here [set quality 1 set Kp K set pcolor red] set A 0 set-turtle-color ask turtles-here with [A > 0.5] [die] ]
end 

to interact
  ask turtles [if [quality] of patch-here = 0 [die] if count turtles-here > Kp [die]]
  ask turtles [if reproductive? > 0 [move-to patch-here ifelse random-float 2 < A [nudge set reproductive? 0 ask patch-here [set Kp (Kp + b)]] [nudge reproduce]]]
  ;ask turtles [face one-of patches fd random-float 0.5]
  ;ask turtles [if [quality] of patch-here = 0 [carefully [move-to one-of neighbors with [quality = 1]] []]]
  ask patches with [quality > 0] [if count turtles-here < 1 [set Kp K assign-colors]]
  ask patches with [quality > 0] [if Kp > (5 * K * b) [set Kp (5 * K * b)] assign-colors]
end 

to migrate?
  ;ask turtles [if random-float 1 < migration [move-to one-of patches with [quality > 0]]]
  ask turtles [if random-float 1 < migration [move-to one-of neighbors with [quality > 0]]]
  ask turtles-on patches with [quality = 0] [die]
end 

to reproduce
  ifelse count turtles-on patch-here < Kp [hatch 1 [mutate set reproductive? 0] set reproductive? 0] [ask patch-here [set pcolor brown]]
end 

to nudge
  face one-of patches fd random-float 0.5
end 

to mutate
  ifelse Discrete? = 1
  [if random-float 1 < mutation [set A (1 - A) set-turtle-color]]
  [if random-float 1 < mutation [set A (A + (random-normal 0 0.5)) if A < 0 [set A 0] if A > 1 [set A 1] set-turtle-color]]
end 

to set-turtle-color
  ifelse Discrete? = 1
  [ifelse A < 0.5 [set color red] [set color blue]]
  [ifelse A < 0.5 [set color (scale-color red A -0.15 0.75)] [set color (scale-color blue A 0.25 1.15)]]
end 

to initial-math
  ;let increment (1 / nbins)
  ;set binsA [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] calc-freq
end 

to do-math
  ask patches with [quality = 1 and count turtles-here > 1] [set mean-A mean [A] of turtles-here set var-A variance [A] of turtles-here]
  set among-group-var variance [mean-A] of patches with [quality = 1]
  set within-group-var mean [var-A] of patches with [quality = 1]
  set ag5 ag4 set ag4 ag3 set ag3 ag2 set ag2 ag1 set ag1 among-group-var
  set wg5 wg4 set wg4 wg3 set wg3 wg2 set wg2 wg1 set wg1 within-group-var
end 

;to calc-freq
  ;set freqA [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1]
 ; set freqA map [ x -> count turtles with [A = x]] [binsA]
;  precision 1
;end

to reshuffle

  ask patches [set quality 0 set Kp 0 assign-colors]
  ask n-of (p * count patches) patches [set quality 1 set Kp (quality * K) assign-colors]
  ask turtles [ifelse random-float 1 < survival [die] [face one-of patches jump (1 + random (5 * max-pycor))
    if count turtles-here > 1 [die] if Kp < 0.5 [die]]]
  stop-inspecting-dead-agents
end 

to assign-colors
  ;ask patches with [quality = 1] [set pcolor white]
  ;set pcolor scale-color green (1 - (Kp / (5 * K))) -0.3 1.0
  ifelse grid = 0 [set quality 0 set pcolor white] [
    ifelse quality > 0 [set pcolor scale-color green (Kp / (5 * K)) -0.5 5] [set pcolor black]]
end 

There are 3 versions of this model.

Uploaded by When Description Download
William Driscoll almost 4 years ago Format update Download this version
William Driscoll almost 4 years ago Re-formatted for browser viewing Download this version
William Driscoll almost 4 years ago Initial upload Download this version

Attached files

File Type Description Last updated
MLS demo 3.2.png preview Preview for 'MLS demo 3.2' almost 4 years ago, by William Driscoll Download

This model does not have any ancestors.

This model does not have any descendants.