Software Accompaniment 1 with short network biology paper

No preview image

1 collaborator

Default-person Indra Gesink (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 5.3.1 • Viewed 56 times • Downloaded 3 times • Run 0 times
Download the 'Software Accompaniment 1 with short network biology paper' modelDownload this modelEmbed this model

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


WHAT IS IT?

This model (and Cooperation and Divide the Cake) are part of the EACH unit ("Evolution of Altruistic and Cooperative Habits: Learning About Complexity in Evolution"). See http://ccl.northwestern.edu/rp/each/index.shtml for more information on the EACH unit. The EACH unit is embedded within the BEAGLE (Biological Experiments in Adaptation, Genetics, Learning and Evolution) evolution curriculum. See http://ccl.northwestern.edu/rp/beagle/index.shtml.

This is an evolutionary biology model. It models population genetics with respect to the fitness of traits that are affected by social and environmental conditions. The model has two types of patch agents: altruistic agents and selfish agents.

The basic premise of the model is that the selfish agents and the altruistic agents are competing for each spot in the world by entering into a genetic lottery. You can imagine these agents as plants who "seed" for a spot, and the dominant seed generally wins. The details of the lottery are explained below in HOW IT WORKS.

Under normal (non-interfering) environmental conditions, the selfish agents win, and the altruistic population is driven to extinction. However, as outlined in HOW TO USE IT, when the environmental conditions are made more harsh, the altruistic population is able to survive, and even dominate the selfish population.

HOW IT WORKS

  1. Patches live in five-cell, plus-sign-shaped neighborhoods. Whenever a patch is calculating something about its fitness, it is the center of the neighborhood. For another patch, when that patch is calculating, it becomes merely one of the neighbors.

  2. Each patch is an agent that has a fitness. Each patch is also the location of a lottery for its space. The patch and the four surrounding patches put in "seeds" to try to get the patch turned to their type of patch, altruist or selfish. Being successful in the lottery is getting patches to turn to your type. We're assuming here that the type (altruistic or selfish) is the important genetic trait.

  3. Each patch calculates its own fitness using equation: if it is A (altruist): 1 - cost + (Number Altruists in Neighborhood / 5 * benefit from Altruists) if it is S (selfish): 1 + (Number Altruists in Neighborhood / 5 * benefit from Altruists) Thus, the fitness of the S patch will be higher than the fitness of the A's. If the cost is 0.2 and benefit is 0.5, for an A surrounded by two S's and two A's, then the fitness of this spot is 1 - 0.2 + (3/5 * 0.5) = 1.1.

  4. After each patch has calculated its fitness, it looks to its four neighbors. Each of the five patches, including itself, puts a weighted seed into a genetic lottery for this center spot. So, for example, if the neighborhood is ASASA, each of the three A's register their fitness value, and each of the two S's put in their fitness. The A's are added, and the S's are added. Let us assume that the A's add up to 3.2 (this includes the A in the center spot), and the S's add up to 2.6. These two numbers are the altruist weight and selfish weight respectively, in the lottery for the center spot. Now, the larger number, whichever it is, is called the Major seed; it is divided by the sum of all the fitnesses. Thus, 3.2/(3.2 + 2.6) = .552. This number is the Altruism seed in the lottery. The minor seed is 2.6/(3.2 + 2.6) = .448. (Notice that the Altruism seed of the parent is 3/5 = .600, while the child's is .552. Even though altruism is dominating, it is losing ground.)

  5. There are a number of ways of doing the lottery itself. Currently, we choose a random number between 0 and 1. Now, if the Number is below the Minor seed, the minor weight gets the spot, and if it is above the major seed, the major seed gets the spot. So, in the example, if the random number is anywhere from .449 to 1, then the Major seed gets it. If it is between 0 and .448, the minor seed gets it.

HOW TO USE IT

SETUP button --- sets up the model by creating the agents.

GO button --- runs the model

ALTRUISTIC-PROBABILITY slider --- lets you determine the initial proportion of altruists

SELFISH-PROBABILITY slider --- determines the initial proportion of selfish agents.

ALTRUISM-COST slider --- determines the value of cost in the above fitness equations.

BENEFIT-FROM-ALTRUISM slider --- determines the value of benefit in the above fitness equations.

There are two sliders for controlling environmental variables:

HARSHNESS slider --- sets the value for the resistance of empty patch spots to being populated by agents. The value for this slider determines a corresponding value in the lottery for each empty (black) spot on the grid; the higher this value, the more difficult it is to populate.

DISEASE slider --- sets the value for the possibility that the agents in occupied spots will die. The value for this slider is factored into the genetic lottery, and determines the percentage chance that each agent will die out from their spot.

THINGS TO TRY

  1. At first, run the model with Harshness and Disease both at 0. Notice that the selfish population quickly dominates the world, driving the altruistic population to extinction. How do respective population sizes affect the outcome?

  2. Play with the values of cost and benefit. What are realistic values for actual genetic competition? How does initial population size effect the significance of these values?

  3. Increase the Harshness and Disease values, independently, and with respect to one another. What are the effects of the Harshness Model? of Disease? How are the values dependent on one another? At what values does the altruistic population begin to have greater success?

  4. Consider why the introduction of Harshness and Disease conditions affects the success of the altruistic population. How does each population, run alone, respond to the Harshness and Disease conditions? If you imagine the black spots as Voids (a third type of competing agent), what is the fitness relationship between Altruists and Voids? Selfish agents and Voids?

  5. Can you find slider values that maximize the advantage of the altruistic agents?

  6. Try running BehaviorSpace on this model to explore the model's behavior under a range of initial conditions.

EXTENDING THE MODEL

The model can be extended in a number of interesting directions, including adding new environmental variables, adding different types of agents, and changing the altruistic and selfish weighting under different environmental conditions.

This model does not address the behaviors of individuals, only the relative weights of genetic traits. A next step in considering the evolution of altruism is to model altruistic behaviors. (See the related model: Cooperation.)

NETLOGO FEATURES

This model uses patches as its basic agents. Can you design an "equivalent" model using turtles? How would the model dynamics be affected?

RELATED MODELS

Cooperation

CREDITS AND REFERENCES

This model, the Cooperation model and the Divide the Cake model are part of the curriculum unit "Evolution of Altruistic and Cooperative Habits: Learning About Complexity in Evolution". See http://ccl.northwestern.edu/rp/each/index.shtml for more information. The EACH unit is embedded within the BEAGLE (Biological Experiments in Adaptation, Genetics, Learning and Evolution) evolution curriculum. See http://ccl.northwestern.edu/rp/beagle/index.shtml.

This model is based on a paper by Mitteldorf and Wilson, 2000, "Population Viscosity and the Evolution of Altruism", Journal of Theoretical Biology, v.204, pp.481-496.

Thanks also to Damon Centola and Scott Styles.

HOW TO CITE

If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

Please cite the NetLogo software as:

COPYRIGHT AND LICENSE

Copyright 1998 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

This model was created as part of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). The project gratefully acknowledges the support of the National Science Foundation (Applications of Advanced Technologies Program) -- grant numbers RED #9552950 and REC #9632612.

This model was converted to NetLogo 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. Converted from StarLogoT to NetLogo, 2001.

Comments and Questions

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

Click to Run Model

;; The Info tab is from the original program. I might write something here or there myself on this program in the future.
;; - Indra Gesink, indragesink@gmail.com

globals [
  ;;PayoffMatrix values:
  P11
  P12
  P21
  P22
  ;;PayoffMatrix B's values, i.e. the non-spatial equivalence:
  P'11
  P'12
  P'21
  P'22
  ;;Interface A and interface B:
  CP11
  CP12
  CP21
  CP22
  CP'11
  CP'12
  CP'21
  CP'22
  ;;The interior NE, which function as basin of attraction, if there is one.
  BoA
  BoA'
  CABoA'
  CBBoA'
  ;;Interaction variables:
  IB11
  IB22
  IB12
  ICA11
  ICA12
  ICA22
  ICB11
  ICB12
  ICB22
  ;;Summary measurements:
  asymmetry
  correlationB
  skewnessB
  correlationCB
  skewnessCB
  clumpy?
  clumpy?C
]

patches-own [
  R?                 ;; 1=yes=R, 0=no=S
  ;; Possible in the future: to change all if requests w.r.t. color to requests on R?
  c                  ;; c=1 in the interface, plays along! c=0; outside of the interface!
  nRNs               ;; number of Resistant Neighbors.
  S-fitness
  R-fitness
  R-weight
]

to payoff  ;; Setting the payoff matrix values. Minimum element set to 1.
  if(Fitness-matrix = "Base2")[set P11 1 set P12 1 set P21 1  set P22 1]
  if(Fitness-matrix = "Divide the Cake (H/D)")[set P11 1 set P12 4 set P21 2 set P22 3]
  if(Fitness-matrix = "Competition-S")[set P11 2 set P12 1 set P21 1  set P22 2]
  if(Fitness-matrix = "Competition-A")[set P11 2 set P12 1 set P21 1  set P22 3]
  if(Fitness-matrix = "Competition-A'")[set P11 1.3 set P12 1.2 set P21 1  set P22 1.1]
  if(Fitness-matrix = "Predator-Prey-S")[set P11 2 set P12 3 set P21 1  set P22 2]
  if(Fitness-matrix = "Predator-Prey-A")[set P11 2 set P12 3 set P21 2  set P22 2]
  if(Fitness-matrix = "Mutualism-S")[set P11 1 set P12 2 set P21 2  set P22 1]
  if(Fitness-matrix = "Mutualism-A")[set P11 1 set P12 2 set P21 3  set P22 1]
  if(Fitness-matrix = "Manual")[
    set P11 3
    set P12 1
    set P21 1
    set P22 2
  ]
end 

to setup
  clear-all
  payoff
  resize-world 0 (World-Size - 1) (World-Size * -1 + 1) 0
  ask patches [ initialize ]
  calculate_InC
  calculate_SMnBnC
  ;;;;
  EGT
  ;ask patches [ EGT ]
  ask patches [ find-lottery-weights ]
  reset-ticks
end 

to switchcolor
  ifelse(pcolor = red)[ ;;w/o the else operation 1 was overwritten by operation 2 ! ;)
    set pcolor green
    set R? 0
    ]
  [if(pcolor = green)[
    set pcolor red
    set R? 1
    ]
  ]
end 

to initialize  ;; patch procedure
  if (Initial-State = "Random") [
    let ptype random-float 1.0
    let itype random-float 1.0
    ifelse (ptype < number-of-resistant-cells) [
      set R? 1
      set pcolor red
    ] [
      set R? 0
      set pcolor green
    ]
  ]
  if (Initial-State = "Segregated")[ ;; alt-prob 0.50
    ifelse (pxcor < World-Size * number-of-resistant-cells)[
      set R? 1
      set pcolor red
    ] [
      set R? 0
      set pcolor green
    ]
  ]
  if (Initial-State = "Surrounded")[
    ;; TO DO make layers calleable in the monitor (for consistency between surrounded and surrounding)
    let layers 2 * ceiling (( World-Size * number-of-resistant-cells ) / 2) ;; a rough and dirty conversion of alt-prob to #rings*2: the latter part biases downwards, the first upwards.
    ;; use of (2n)^2 for more precision.
    set R? 0
    set pcolor green
    ;;No loop needed!:
    if(((World-Size - layers) / 2) <= pxcor and pxcor < ((World-Size + layers) / 2) and ((World-Size - layers) / -2) >= pycor and pycor > ((World-Size + layers) / -2))[
    set R? 1
    set pcolor red
    ]
  ]
  if (Initial-State = "Surrounding")[
    let selfish-probability (1 - number-of-resistant-cells)
    let layers 2 * ceiling (( World-Size * selfish-probability) / 2) ;; a rough and dirty conversion of alt-prob to #rings*2: the latter part biases downwards, the first upwards.
    ;; use of (2n)^2 for more precision.
    set R? 1
    set pcolor red
    ;;No loop needed!:
    if(((World-Size - layers) / 2) <= pxcor and pxcor < ((World-Size + layers) / 2) and ((World-Size - layers) / -2) >= pycor and pycor > ((World-Size + layers) / -2))[
    set R? 0
    set pcolor green
    ]
  ]
  if (Initial-State = "Dispersed")[ ;; alt-prob 0.25 / 0.75
    ;;works for both sides (versatile) and depends on alt-prob >0.5 or not.
    ifelse(number-of-resistant-cells <= 0.5)[ ;;initalizing with the majority. Then below: switchcolors to create the minority.
      set pcolor green
      set R? 0
    ] [
       set pcolor red
       set R? 1
    ]
    ;; for divisions close to 50/50
    if(abs(number-of-resistant-cells - 0.5) <= 0.25)[ ;; If alt-prob is in the middle half a checkerboard is made on the odd cors.
      if(((pxcor - 1) mod 2 = 0) and ((pycor - 1) mod 2 = 0))
      [ switchcolor ]
    ]
    ;; under any condition on the even cors:
    let amount' (World-Size * World-Size * ((0.5 - abs(number-of-resistant-cells - 0.5)) mod 0.25))
    if(number-of-resistant-cells = 0.5)[set amount' (World-Size * World-Size * ((0.5 - abs(number-of-resistant-cells - 0.5)) / 2))]
    let xmax ((amount' mod (World-Size / 2)) * 2)
    let ymax ((amount' - (xmax / 2)) / (World-Size / 2) * -2)
    if((pxcor mod 2 = 0) and (pycor mod 2 = 0) and (pycor >= ymax))[
      ifelse(pycor = ymax)[
        if(pxcor < xmax)[ switchcolor ]
        ]
      [ switchcolor ]
    ]
  ]
  if (Initial-State = "Checkerboard")[
    ifelse ((pxcor + pycor) mod 2 = 0)[
      set R? 1
      set pcolor red
    ] [
      set R? 0
      set pcolor green
    ]
  ]
   if (Initial-State = "Lines-h")[
    ifelse (pycor mod 2 = 0)[
      set R? 1
      set pcolor red
    ] [
      set R? 0
      set pcolor green
    ]
  ]
  if (Initial-State = "Lines-v")[
    ifelse (pxcor mod 2 = 0)[
      set R? 1
      set pcolor red
    ] [
      set R? 0
      set pcolor green
    ]
  ]
  if (Initial-State = "Fixation")[
    ifelse(number-of-resistant-cells > 0.5)[
      set pcolor red
      set R? 1
    ] [
      set R? 0
      set pcolor green
    ]
  ]
end 

to invade
  if(Stochastic-Mutant-Invaders)[
    let one-in-hundred random-float 1.0
    if(one-in-hundred <= prob-one-mutant)[
      ask patch floor(random-float World-Size) floor(random-float World-Size)
      [ switchcolor ]
    ]
  ]
end 

to calculate_InC
 ;; Initialize / reset
 set IB11 0
 set IB12 0
 set IB22 0
 ;;counting # neighbours (on either of 4 sides) per type per cell / 2:
 foreach (reverse (n-values (1 + max-pycor - min-pycor) [ min-pycor + ? ])) [
    let y ?
    foreach (n-values (1 + max-pxcor - min-pxcor) [ min-pxcor + ? ]) [
      let x ?
      ask patch x y [
        if(pcolor = green)[
          set IB11 IB11 + sum [(1 - R?)] of neighbors4 ;;#sensitive.
          set IB12 IB12 + sum [R?] of neighbors4 ;;#R.
          ifelse(sum [1 - R?] of neighbors4 = 4)[set c 0][set c 1]
        ]
        if(pcolor = red)[
           set IB22 IB22 + sum [R?] of neighbors4
           ifelse(sum [R?] of neighbors4 = 4)[set c 0][set c 1]
        ]
      ]
    ]
  ]
 set IB11 IB11 / (4 * World-Size * World-Size) ;;4 for number of neighbors!
 set IB22 IB22 / (4 * World-Size * World-Size)
 set IB12 IB12 / (4 * World-Size * World-Size)
 ;;Now IC:
 set ICA11 0
 set ICA12 0
 set ICA22 0
 if(count patches with [c = 1] > 0)[
 set ICA11 (count patches with [pcolor = green and c = 1] / (count patches with [c = 1])) ^ 2
 set ICA12 (count patches with [pcolor = green and c = 1] / count patches with [c = 1]) * (count patches with [pcolor = red and c = 1] / count patches with [c = 1])
 set ICA22 (count patches with [pcolor = red and c = 1] / (count patches with [c = 1])) ^ 2
 ]
 set ICB11 0
 set ICB12 0
 set ICB22 0
 foreach (reverse (n-values (1 + max-pycor - min-pycor) [ min-pycor + ? ])) [
    let y ?
    foreach (n-values (1 + max-pxcor - min-pxcor) [ min-pxcor + ? ]) [
      let x ?
      ask patch x y [
        if(pcolor = green and c = 1)[
          set ICB11 ICB11 + c * (sum [(1 - R?)] of neighbors4) ;;#sensitive.
          set ICB12 ICB12 + c * (sum [R?] of neighbors4) ;;#R.
        ]
        if(pcolor = red and c = 1)[
          set ICB22 ICB22 + c * (sum [R?] of neighbors4)
        ]
      ]
    ]
  ]
 if(count patches with [c = 1] > 0)[
 ;; gaurd against division by zero:
 let temp ((ICB11 + ICB12 + ICB12 + ICB22) / 4)
 set ICB11 ICB11 / (4 * temp)
 set ICB12 ICB12 / (4 * temp)
 set ICB22 ICB22 / (4 * temp)
 ]
end 

to calculate_SMnBnC  ;; (For now ignores blue.)
  set asymmetry 0 ; in the design of my program this cannot be different. There is also no practical reason to have it otherwise.
  let fog (count patches with [pcolor = green] / World-Size ^ 2) ;; fraction of..
  let for (count patches with [pcolor = red] / World-Size ^ 2)
  ;;I here fix off-diagonal elements first, as opposed to lowest on-diagonal element!.
  if(fog * for != 0)[
    ifelse((2 * IB12) < (2 * fog * for))[
      set correlationB (1 - (IB12) / (fog * for)) ; +
    ] [
      set correlationB -1 * (1 - (IB11 + IB22) / (fog ^ 2 + for ^ 2)) ; -
    ] ;; so far so simple.
  ]
  ;;; and payofmatrix B (with control to prevent division by zero). If there would be division by zero, the predicted (theoretical) interaction frequencies is zero and then the observed is as well. Both are then thus equal and the factor in between the two 1 with which the conversion is made.
  ;; B = A * IB / IA
 ifelse(fog != 0)[
   set P'11 P11 * IB11 / (fog ^ 2)] [set P'11 P11]
 ifelse(fog != 0 and for != 0)[
    set P'12 P12 * IB12 / (fog * for)] [set P'12 P12]
 ifelse(for != 0 and fog != 0)[
    set P'21 P21 * IB12 / (for * fog)] [set P'21 P21]
 ifelse(for != 0)[
    set P'22 P22 * IB22 / (for ^ 2)] [set P'22 P22]
    ;;nC: (silly ^^)
      ;; CA = A * ICA / IA !!
 ifelse(fog != 0)[
   set CP11 P11 * ICA11 / (fog ^ 2)] [set CP11 0] ;;?
 ifelse(fog != 0 and for != 0)[
    set CP12 P12 * ICA12 / (fog * for)] [set CP12 0]
 ifelse(for != 0 and fog != 0)[
    set CP21 P21 * ICA12 / (for * fog)] [set CP21 0]
 ifelse(for != 0)[
    set CP22 P22 * ICA22 / (for ^ 2)] [set CP22 0]
      ;; CB = CA * ICB / ICA !!
 ifelse(ICA11 != 0)[
   set CP'11 CP11 * ICB11 / ICA11] [set CP'11 0]
 ifelse(ICA12 != 0)[
    set CP'12 CP12 * ICB12 / ICA12] [set CP'12 0]
 ifelse(ICA12 != 0)[
    set CP'21 CP21 * ICB12 / ICA12] [set CP'21 0]
 ifelse(ICA22 != 0)[
    set CP'22 CP22 * ICB22 / ICA22] [set CP'22 0]
 ;;
 let temppp (count patches with [pcolor = green] / World-Size ^ 2) * (count patches with [pcolor = red] / World-Size ^ 2)
 ifelse(temppp != 0)[
 if(IB22 != 0)[
  ifelse(IB11 / IB22 >= fog ^ 2 / for ^ 2)[ ;+  ;IB's not squared!.
    ifelse(correlationB > 0)[
      let temp for ^ 2 + (fog * for * 2 * correlationB) * for ^ 2 / (fog ^ 2 + for ^ 2)
      set skewnessB 1 - IB22 / temp][
      set skewnessB 1 - IB22 / (for ^ 2 * (1 + correlationB))]][ ;-
   ifelse(correlationB > 0)[
      let temp fog ^ 2 + (for * fog * 2 * correlationB) * fog ^ 2 / (fog ^ 2 + for ^ 2)
      set skewnessB -1 + IB11 / temp][
      set skewnessB -1 + IB11 / (fog ^ 2 * (1 + correlationB))]]
  ]
  ][
    set skewnessB 0
    set correlationB 0
    set skewnessCB 0
    set correlationCB 0
    ] ; In this connected world fog * for = 0 implies one of them equals zero and thus fixation!.

      ; Now how to reverse calculate stuff!?
      ; Or how to write it into simpler form!?

    ifelse((fog - for) * skewnessB < 0)[ ;; favoring the weakest.
    set clumpy? "YES"
  ] [ ifelse((fog - for) * skewnessB > 0) [
    set clumpy? "NO"
  ] [
    set clumpy? "-"
  ]]

  ;;;;set correlationCB 0
  ;;;;set skewnessCB 0
   if(ICA12 != 0)[
    ifelse((2 * ICB12) < (2 * ICA12))[
      set correlationCB 1 - ICB12 / ICA12 ; +
    ] [
      set correlationCB -1 * (1 - (ICB11 + ICB22) / (ICA11 + ICA22)) ; -
    ] ;; so far so simple.
  ]
   if(fog * for != 0)[
 if(ICB22 != 0)[
  ifelse(ICB11 / ICB22 >= ICA11 / ICA22)[ ; +
    ifelse(correlationCB > 0)[
      let temp ICA22 + (ICA12 * 2 * correlationCB) * ICA22 / (ICA11 + ICA22)
      set skewnessCB 1 - ICB22 / temp][
      set skewnessCB 1 - ICB22 / (ICA22 * (1 + correlationCB))]][ ; -
   ifelse(correlationB > 0)[
      let temp ICA11 + (ICA12 * 2 * correlationCB) * ICA11 / (ICA11 + ICA22)
      set skewnessCB -1 + ICB11 / temp][
      set skewnessCB -1 + ICB11 / (ICA11 * (1 + correlationCB))]]
  ]
  ]

  ifelse((count patches with [c = 1]) > 0)[
  ifelse((count patches with [pcolor = green and c = 1] / (count patches with [c = 1]) - count patches with [pcolor = red and c = 1] / (count patches with [c = 1])) * skewnessCB < 0)[
    set clumpy?C "YES"
  ] [ ifelse((count patches with [pcolor = green and c = 1] / (count patches with [c = 1]) - count patches with [pcolor = red and c = 1] / (count patches with [c = 1])) * skewnessCB > 0) [
    set clumpy?C "NO"
  ] [
    set clumpy?C "-"
  ]]
  ][set clumpy?C "-"]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  EGT
  lottery
  invade
  calculate_InC
  calculate_SMnBnC
  ;;Calculation of BoA and BoA'
  if(P12 - P22 + P21 - P11 != 0)[
  set BoA World-Size * World-Size * (P12 - P22) / (P12 - P22 + P21 - P11) ;unefficient ^^. ; case of drift causes an error.
  set BoA max (list 0 BoA)
  set BoA min (list 1600 BoA)
  set BoA' World-Size * World-Size * (P'12 - P'22) / (P'12 - P'22 + P'21 - P'11)
  set BoA' max (list 0 BoA')
  set BoA' min (list 1600 BoA')
  ]
  if(CP12 - CP22 + CP21 - CP11 != 0)[
  set CABoA' World-Size * World-Size * (CP12 - CP22) / (CP12 - CP22 + CP21 - CP11) ;unefficient ^^. ; case of drift causes an error.
  set CABoA' max (list 0 CABoA')
  set CABoA' min (list 1600 CABoA')
  set CBBoA' World-Size * World-Size * (CP'12 - CP'22) / (CP'12 - CP'22 + CP'21 - CP'11)
  set CBBoA' max (list 0 CBBoA')
  set CBBoA' min (list 1600 CBBoA')
  ]
  tick
end 

to EGT
  ask patches [
    set nRNs sum [R?] of neighbors4
    if(pcolor = green)[
      set S-fitness P11 * (4 - nRNs)
      set R-fitness P21 * nRNs
      if(Inert-EGT)[
        set S-fitness S-fitness + P11
        ]
    ]
    if(pcolor = red)[
      set R-fitness P22 * nRNs ; it is the neighbor interact with this cell!! (a "reversal of perspective" - breaking with the original program!!)
      set S-fitness P12 * (4 - nRNs)
      if(Inert-EGT)[
        set R-fitness R-fitness + P22
        ]
    ]
  ]
end 

to lottery
  ask patches [ find-lottery-weights ]
  ask patches [ next-generation ]
end 

to find-lottery-weights ;; patch procedure
  if (R-fitness + S-fitness != 0)[
    set R-weight (R-fitness / (R-fitness + S-fitness)) ;; for this the split was made.
  ]
end 

to next-generation ;; patch procedure
  let breed-chance random-float 1.0
  ifelse (breed-chance = R-weight) [][  ;;IMPORTANT LINE!. (else bias towards red was observed in the situation of drift.)
    ifelse (breed-chance < R-weight) [
      set pcolor red
      set R? 1
    ] [
      set pcolor green
      set R? 0
    ]
  ]
end 

to clear-patch ;; patch procedure
  set nRNs 0
  set R-fitness 0
  set S-fitness 0
  set R-weight 0
end 
; Copyright see info tab.

There are 2 versions of this model.

Uploaded by When Description Download
Indra Gesink 4 months ago An extra plot in the interface Download this version
Indra Gesink 4 months ago Initial upload Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.