Class EcoPGG

All Implemented Interfaces:
Runnable, IBS.HasIBS, IBS.HasIBS.DGroups, IBS.HasIBS.DPairs, MilestoneListener, ODE.HasDE, ODE.HasODE, PDE.HasPDE, SDE.HasSDE, Features, Features.Groups, Features.Pairs, HasHistogram, HasHistogram.Degree, HasHistogram.Fitness, HasHistogram.StatisticsStationary, HasMean, HasMean.Fitness, HasMean.Strategy, HasPhase2D, HasPop2D, HasPop2D.Fitness, HasPop2D.Strategy, HasPop3D, HasPop3D.Fitness, HasPop3D.Strategy, HasS3, CLOProvider

Cooperation in ecological public goods interactions.
Author:
Christoph Hauert
  • Field Details

    • DEFECT

      public static final int DEFECT
      The trait (and index) value of defectors.
      See Also:
    • COOPERATE

      public static final int COOPERATE
      The trait (and index) value of cooperators.
      See Also:
    • rng

      protected RNGDistribution rng
      The shared random number generator to ensure reproducibility of results.
      See Also:
    • interest

      double interest
      The multiplication factor of the public good.
    • cost

      double cost
      The cost of cooperation or the individual contribution to the public good.
    • payLoneCoop

      double payLoneCoop
      The payoff to lone cooperators.
    • payLoneDefect

      double payLoneDefect
      The payoff to lone defectors.
    • map

      The map for translating the model data into 2D phase plane representation.
    • cloInterest

      public final CLOption cloInterest
      Command line option to set the multiplication factor for public good interactions.
    • cloCost

      public final CLOption cloCost
      Command line option to set the cost of cooperation, i.e. contributions to the public good.
    • cloLoneCooperator

      public final CLOption cloLoneCooperator
      Command line option to set the payoff to cooperators that failed to find any interaction partners.
    • cloLoneDefector

      public final CLOption cloLoneDefector
      Command line option to set the payoff to defectors that failed to find any interaction partners.
  • Constructor Details

    • EcoPGG

      public EcoPGG(EvoLudo engine)
      Create a new instance of the module for ecological public goods games.
      Parameters:
      engine - the manager of modules and pacemaker for running the model
  • Method Details

    • load

      public void load()
      Description copied from class: Module
      Load new module and perform basic initializations.
      Overrides:
      load in class Discrete
      See Also:
    • getKey

      public String getKey()
      Description copied from class: Module
      Returns identifier of the active module. For example, 2x2 games in TBT return "2x2". This corresponds to the argument for the --module option to load a particular module. The default is to use the class name.
      Overrides:
      getKey in class Module
      Returns:
      the identifying key of this module
    • getAuthors

      public String getAuthors()
      Description copied from class: Module
      Returns a string with information about the authors of the module.
      Overrides:
      getAuthors in class Module
      Returns:
      the names of the authors
    • getTitle

      public String getTitle()
      Description copied from class: Module
      Returns title of active module, e.g. 2x2 games in TBT returns "2x2 Games".
      Specified by:
      getTitle in class Module
      Returns:
      the title of active module
    • getMinGameScore

      public double getMinGameScore()
      Description copied from class: Module
      Calculates and returns the minimum payoff/score of an individual. This value is important for converting payoffs/scores into probabilities, for scaling graphical output and some optimizations.
      Specified by:
      getMinGameScore in class Module
      Returns:
      the minimum payoff/score
      See Also:
    • getMaxGameScore

      public double getMaxGameScore()
      Description copied from class: Module
      Calculates and returns the maximum payoff/score of an individual. This value is important for converting payoffs/scores into probabilities, for scaling graphical output and some optimizations.
      Specified by:
      getMaxGameScore in class Module
      Returns:
      the maximum payoff/score
      See Also:
    • getMonoGameScore

      public double getMonoGameScore(int type)
      Description copied from class: Discrete
      Calculate and return the payoff/score of individuals in monomorphic populations with trait/strategy type.

      Note: Optional implementation. Returns Double#NaN if not defined or not implemented.

      Overrides:
      getMonoGameScore in class Discrete
      Parameters:
      type - trait/strategy
      Returns:
      payoff/score in monomorphic population with trait/strategy type
    • createPDE

      public Model createPDE()
      Description copied from interface: PDE.HasPDE
      Provides opportunity for model to supply custom PDE implementation.

      Important: if the custom PDE implementation involves random numbers, the shared random number generator should be used for reproducibility.

      Specified by:
      createPDE in interface PDE.HasPDE
      Returns:
      custom PDE model or null to use use default
      See Also:
    • mixedScores

      public void mixedScores(int[] traitCount, int n, double[] traitScore)
      Calculate the average payoff/score in a finite population with the number of each trait/strategy provided in count for interaction groups of size n. The payoffs/scores for each of the nTraits traits/strategies must be stored and returned in the array traitScores.

      Notes:

      For payoff calculations:
      • each strategy sees one less of its own type in its environment
      • the size of the environment is nPopulation-1
      • the fact that the payoff of each strategy does not depend on its own type simplifies things
      If explicit calculations of the well-mixed scores are not available, interactions with everyone in well-mixed populations should be checked for and excluded with a warning in IBS.check() (see IBSMCPopulation for an example).

      Important:

      Must be overridden and implemented in subclasses that define game interactions in well-mixed populations where individuals interact with everyone else. Computationally it is not feasible to cover this scenario with IBS.HasIBS.DPairs.pairScores(int, int[], double[]) or IBS.HasIBS.DGroups.groupScores(int[], double[]), respectively.

      Proper sampling in finite populations (c.f. CDL): \begin{align*} f_L =& \sigma\\ f_D =& \frac{\binom z{N-1}}{\binom{M-1}{N-1}}\sigma+r\frac x{M-z-1}\\ & \left(1-\frac 1{N(M-z)} \left( M-(z-N+1)\frac{\binom z{N-1}}{\binom{M-1}{N-1}}\right)\right) c\\ f_C =& f_d-F(z)c\\ F(z) =& 1-\frac rN\frac{M-N}{M-z-1}+\frac{\binom z{N-1}}{\binom{M-1}{N-1}}\\ & \left(\frac rN \frac{z+1}{M-z-1}+r\frac{M-z-2}{M-z-1}-1\right) \end{align*}

      Specified by:
      mixedScores in interface IBS.HasIBS.DGroups
      Parameters:
      traitCount - number of individuals for each trait/strategy
      n - interaction group size
      traitScore - array for returning the payoffs/scores of each trait/strategy
    • avgScores

      public void avgScores(double[] dens, int n, double[] avgscores)
      Description copied from interface: ODE.HasDE
      Calculate the average payoff/score for the frequency of traits/strategies specified in the array density for interactions in groups of size n. The average payoffs/scores for each of the nTraits traits/strategies must be stored and returned in the array avgscores.

      Note: needs to be thread safe for parallel processing of PDE's.

      IMPORTANT: one of

      should be implemented in modules that advertise the model types ODE, SDE or PDE.

      Alternatively, the method ODE.getDerivatives(double, double[], double[], double[]) may be overridden in a subclass of ODE, which may prevent calls to avgScores(...) altogether.

      Specified by:
      avgScores in interface ODE.HasDE
      Parameters:
      dens - the frequency/density of each trait/strategy
      n - the size of interaction groups
      avgscores - the array for storing the average payoffs/scores for each strategic type
    • pairScores

      public double pairScores(int me, int[] traitCount, double[] traitScore)
      Description copied from interface: IBS.HasIBS.DPairs
      Calculate and return total (accumulated) payoff/score for pairwise interactions of the focal individual with trait/strategy me against opponents with different traits/strategies. The respective numbers of each of the nTraits opponent traits/strategies are provided in the array tCount. The payoffs/scores for each of the nTraits opponent traits/strategies must be stored and returned in the array tScore.

      Important: must be overridden and implemented in subclasses that define game interactions between pairs of individuals (nGroup=2, pairwise=true), otherwise see IBS.HasIBS.DGroups.groupScores(int[], double[]).

      Specified by:
      pairScores in interface IBS.HasIBS.DPairs
      Parameters:
      me - the trait index of the focal individual
      traitCount - number of opponents with each trait/strategy
      traitScore - array for returning the scores of each opponent trait/strategy
      Returns:
      score of focal individual me accumulated over all interactions
    • groupScores

      public void groupScores(int[] traitCount, double[] traitScore)
      Description copied from interface: IBS.HasIBS.DGroups
      Calculate the payoff/score for interactions in groups consisting of traits/strategies with respective numbers given in the array tCount. The interaction group size is given by the sum over tCount[i] for i=0,1,...,nTraits. The payoffs/scores for each of the nTraits traits/strategies must be stored and returned in the array tScore.

      Important: must be overridden and implemented in subclasses that define game interactions among groups of individuals (for groups with sizes nGroup>2, otherwise see IBS.HasIBS.DPairs.pairScores(int, int[], double[])).

      Specified by:
      groupScores in interface IBS.HasIBS.DGroups
      Parameters:
      traitCount - group composition given by the number of individuals with each trait/strategy
      traitScore - array for returning the payoffs/scores of each trait/strategy
    • setCostCoop

      public void setCostCoop(double aValue)
      Set the cost of cooperation.
      Parameters:
      aValue - the cost of cooperation
    • getCostCoop

      public double getCostCoop()
      Get the cost of cooperation.
      Returns:
      the cost of cooperation
    • setInterest

      public void setInterest(double aValue)
      Set the multiplication factor of the linear public goods game.
      Parameters:
      aValue - the new multiplication factor
    • getInterest

      public double getInterest()
      Get the multiplication factor of the linear public goods game.
      Returns:
      the multiplication factor
    • setPayLoneCoop

      public void setPayLoneCoop(double aValue)
      Set the payoff to lone cooperators. Defaults to loner payoff.
      Parameters:
      aValue - the payoff to lone cooperators.
    • getPayLoneCoop

      public double getPayLoneCoop()
      Get the payoff to lone cooperators.
      Returns:
      the payoff to lone cooperators.
    • setPayLoneDefect

      public void setPayLoneDefect(double aValue)
      Set the payoff to lone defectors. Defaults to loner payoff.
      Parameters:
      aValue - the payoff to lone defectors.
    • getPayLoneDefect

      public double getPayLoneDefect()
      Get the payoff to lone defectors.
      Returns:
      the payoff to lone defectors.
    • getPhase2DMap

      public HasPhase2D.Data2Phase getPhase2DMap()
      Description copied from interface: HasPhase2D
      Get the map that transforms the data of the module to a 2D phase plane (projection).
      Specified by:
      getPhase2DMap in interface HasPhase2D
      Returns:
      the map
    • collectCLO

      public void collectCLO(CLOParser parser)
      Description copied from interface: CLOProvider
      All providers of command line options must implement this method to collect their options.

      Each command line option is (uniquely) identified by it's name (see CLOption.getName()), which corresponds to the long version of the option. If an attempt is made to add an option with a name that already exists, the parser issues a warning and ignores the option. Thus, in general, implementing subclasses should first register their options and call super.collectCLO(CLOParser) at the end such that subclasses are able to override command line options specified in a parental class.

      Override this method in subclasses to add further command line options. Subclasses must make sure that they include a call to super.

      Specified by:
      collectCLO in interface CLOProvider
      Overrides:
      collectCLO in class Discrete
      Parameters:
      parser - the reference to parser that manages command line options
      See Also: