Class TBT
- All Implemented Interfaces:
Runnable,IBS.HasIBS,IBS.HasIBS.DPairs,MilestoneListener,Model.HasDE,Model.HasDE.DPairs,Model.HasDE.EM,Model.HasDE.ODE,Model.HasDE.PDE,Model.HasDE.PDEADV,Model.HasDE.PDERD,Model.HasDE.RK5,Model.HasDE.SDE,Features,Features.Pairs,Features.Payoffs,HasHistogram,HasHistogram.Degree,HasHistogram.Fitness,HasHistogram.StatisticsProbability,HasHistogram.StatisticsStationary,HasHistogram.StatisticsTime,HasMean,HasMean.Fitness,HasMean.Traits,HasPop2D,HasPop2D.Fitness,HasPop2D.Traits,HasPop3D,HasPop3D.Fitness,HasPop3D.Traits,CLOProvider
2×2 games. The prisoner's dilemma and the snowdrift game are
popular instances of 2×2 games. The ranking of the payoffs
determines the characteristics of the game. Consider the payoff matrix
\begin{align}
\begin{matrix} &
\begin{matrix} &\hspace{-3ex} C &\hspace{-1ex} D \end{matrix} \\
\begin{matrix} C\\ D \end{matrix} & \hspace{-1ex}
\begin{pmatrix}R & S\\ T & P\end{pmatrix}
\end{matrix}
\end{align}
where \(R\) refers to the payoff for mutual cooperation, \(S\) to the
sucker's payoff to a cooperator facing a defector, \(T\) to the temptation to
defect for a defector facing a cooperator and \(P\) to the punishment for
mutual defection. The notation and terminology go back to Robert Axelrod who
popularised the prisoner's dilemma in the early '80s. The prisoner's dilemma
is characterized by the ranking \(T>R>P>S\), which means that a
defector is always better off regardless of what the opponent plays, i.e.
\(T>R\) and \(P>S\), yet the payoff for mutual cooperation exceeds that
of mutual defection, i.e. \(R>P\). This results in a classical conflict of
interest between the individual and the group, which is the essence of social
dilemmas. As a consequence cooperation is doomed in the prisoner's dilemma in
the absence of supporting mechanisms, such as structured populations with
limited local interactions
Similarly, the snowdrift game is characterized by \(T>R>S>P\) and now the best trait depends on the opponent. Against a cooperator it is still better to defect but against a defector it pays to cooperate. The snowdrift game is still a social dilemma because individuals are tempted to move away from mutual cooperation but the dilemma is relaxed because cooperation is not necessarily doomed in the absence of supporting mechanisms.
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThe extension for IBS simulations specific to populations engaging in2×2games.Nested classes/interfaces inherited from interface Features
Features.Groups, Features.Multispecies, Features.Pairs, Features.Payoffs, Features.StaticNested classes/interfaces inherited from interface HasHistogram
HasHistogram.Degree, HasHistogram.Fitness, HasHistogram.StatisticsProbability, HasHistogram.StatisticsStationary, HasHistogram.StatisticsTime, HasHistogram.StrategyNested classes/interfaces inherited from interface HasMean
HasMean.Fitness, HasMean.TraitsNested classes/interfaces inherited from interface HasPop2D
HasPop2D.Fitness, HasPop2D.TraitsNested classes/interfaces inherited from interface HasPop3D
HasPop3D.Fitness, HasPop3D.TraitsNested classes/interfaces inherited from interface IBS.HasIBS
IBS.HasIBS.CGroups, IBS.HasIBS.CPairs, IBS.HasIBS.DGroups, IBS.HasIBS.DPairs, IBS.HasIBS.MCGroups, IBS.HasIBS.MCPairsNested classes/interfaces inherited from interface Model.HasDE
Model.HasDE.DGroups, Model.HasDE.DPairs, Model.HasDE.DualDynamics, Model.HasDE.EM, Model.HasDE.ODE, Model.HasDE.PDE, Model.HasDE.PDEADV, Model.HasDE.PDERD, Model.HasDE.RK5, Model.HasDE.SDE -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal CLOptionCommand line option to set the2×2payoff matrix for interactions between cooperators and defectors.static final intThe trait (and index) value of cooperators.static final intThe trait (and index) value of defectors.(package private) double[][]The2×2payoff matrix for interactions between cooperators and defectors.Fields inherited from class Discrete
cloMonoStop, monoStop, mutation, speciesFields inherited from class Module
active, cloDeathRate, cloGeometry, cloNGroup, cloNPopulation, cloPhase2DAxes, cloTraitColors, cloTraitDisable, cloTraitNames, competition, deathRate, defaultColor, engine, ibs, ID, interaction, logger, map2fitness, markers, model, nActive, name, nGroup, nPopulation, nTraits, opponent, playerUpdate, structure, traitColor, traitName, trajectoryColor, VACANT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidProviders of command line options may want to remove certain options that other providers provided by overriding this method.voidavgScores(double[] density, double[] avgscores) Calculate the average payoff for the frequency of traits specified in the arraystatefor pairwise interactions.voidcollectCLO(CLOParser parser) All providers of command line options must implement this method to collect their options.Opportunity to supply custom individual based simulations.Returns a string with information about the authors of the module.intFor replicator dynamics the frequencies of all traits must sum up to one.getKey()Returns identifier of the active module.doubleCalculates and returns the maximum payoff/score of an individual.Color[]Gets the colors for the mean values of traits.doubleCalculates and returns the minimum payoff/score of an individual.doublegetMonoPayoff(int type) Calculate and return the payoff/score of individuals in monomorphic populations with traittype.doublegetPayoff(int me, int you) Get the payoff for typemeagainst typeyou.double[][]Get the payoffs as a2×2matrix.getTitle()Returns title of active module, e.g.getTraitName(int idx) Gets the name of the trait with indextrait.voidload()Load new module and perform basic initializations.voidmixedScores(int[] traitCount, double[] traitScore) Calculate the average payoff/score in a finite population with the number of each trait provided incountfor pairwise interactions.doublepairScores(int me, int[] traitCount, double[] traitScore) Calculate and return total (accumulated) payoff/score for pairwise interactions of the focal individual with traitmeagainst opponents with different traits.voidsetPayoff(double payoff, int me, int you) Set the payoff for typemeagainst typeyoutopayoff.voidsetPayoffs(double[][] payoffs) Set the payoffs from the2×2matrixpayoffs.voidunload()Unload module and free all resources.Methods inherited from class Discrete
add, getMaxMonoPayoff, getMinMonoPayoff, getMonoStop, getMutation, setMonoStopMethods inherited from class Module
check, createGeometry, createModel, getActiveTraits, getCompetitionGeometry, getDeathRate, getGeometry, getIBSPopulation, getID, getInteractionGeometry, getMap2Fitness, getMarkers, getModelTypes, getNActive, getName, getNGroup, getNPopulation, getNRoles, getNSpecies, getNTraits, getOpponent, getPlayerUpdate, getSpecies, getSpecies, getTraitColor, getTraitColors, getTraitNames, getTrajectoryColor, getVacant, init, processColorMap, reset, run, setActiveTraits, setDeathRate, setGeometries, setIBSPopulation, setModel, setName, setNGroup, setNPopulation, setNTraits, setOpponent, setTraitColors, setTraitNames, setTrajectoryColorMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Features
isMultispecies, isStaticMethods inherited from interface Features.Pairs
isPairwiseMethods inherited from interface Features.Payoffs
getMap2Fitness, getMaxMonoPayoff, getMinMonoPayoff, isNeutralMethods inherited from interface HasHistogram
getCustomLevels, getNTraits, getTraitColorsMethods inherited from interface IBS.HasIBS
createIBSMethods inherited from interface MilestoneListener
modelDidInit, modelDidReset, modelLoaded, modelRelaxed, modelRunning, modelSettings, modelStopped, modelUnloaded, moduleLoaded, moduleRestored, moduleUnloaded
-
Field Details
-
COOPERATE
public static final int COOPERATEThe trait (and index) value of cooperators.- See Also:
-
DEFECT
public static final int DEFECTThe trait (and index) value of defectors.- See Also:
-
payoffs
double[][] payoffsThe2×2payoff matrix for interactions between cooperators and defectors. -
cloPayoffs
Command line option to set the2×2payoff matrix for interactions between cooperators and defectors.
-
-
Constructor Details
-
TBT
Create a new instance of the module for2×2games.- Parameters:
engine- the manager of modules and pacemaker for running the model
-
-
Method Details
-
load
public void load()Description copied from class:ModuleLoad new module and perform basic initializations. -
unload
public void unload()Description copied from class:ModuleUnload module and free all resources. -
getKey
Description copied from class:ModuleReturns identifier of the active module. For example, 2x2 games inTBTreturn "2x2". This corresponds to the argument for the--moduleoption to load a particular module. The default is to use the class name. -
getAuthors
Description copied from class:ModuleReturns a string with information about the authors of the module.- Overrides:
getAuthorsin classModule- Returns:
- the names of the authors
-
getTitle
Description copied from interface:FeaturesReturns title of active module, e.g. 2x2 games inTBTreturns "2x2 Games". -
getTraitName
Description copied from class:ModuleGets the name of the trait with indextrait.- Overrides:
getTraitNamein classModule- Parameters:
idx- the index of the trait- Returns:
- the name of the trait
-
getMeanColors
Description copied from class:ModuleGets the colors for the mean values of traits. By default this is the same as the trait colors. Opportunity for subclasses to return different sets of colors for plotting mean values.- Overrides:
getMeanColorsin classModule- Returns:
- the array of mean value colors
-
getDependent
public int getDependent()Description copied from interface:Model.HasDEFor replicator dynamics the frequencies of all traits must sum up to one. Hence, fornTraitstraits there are onlynTraits-1degrees of freedom. The index returned bygetDependent()marks the one rate of change that is derived from all the others.Notes:
- Dependent traits are used by models where the frequencies of all types must sum up to one.
- Density modules do not have dependent traits and
getDependent()should return-1. - Currently differential equations implementations are only provided for Discrete modules.
- Specified by:
getDependentin interfaceModel.HasDE- Returns:
- the index of the dependent trait (or
-1if there is none)
-
getMinPayoff
public double getMinPayoff()Description copied from interface:Features.PayoffsCalculates 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:
getMinPayoffin interfaceFeatures.Payoffs- Returns:
- the minimum payoff/score
- See Also:
-
getMaxPayoff
public double getMaxPayoff()Description copied from interface:Features.PayoffsCalculates 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:
getMaxPayoffin interfaceFeatures.Payoffs- Returns:
- the maximum payoff/score
- See Also:
-
getMonoPayoff
public double getMonoPayoff(int type) Description copied from class:DiscreteCalculate and return the payoff/score of individuals in monomorphic populations with traittype.Note: Optional implementation. Returns
Double#NaNif not defined or not implemented.- Overrides:
getMonoPayoffin classDiscrete- Parameters:
type- the index of the trait- Returns:
- payoff/score in monomorphic population with trait
type
-
pairScores
public double pairScores(int me, int[] traitCount, double[] traitScore) Description copied from interface:IBS.HasIBS.DPairsCalculate and return total (accumulated) payoff/score for pairwise interactions of the focal individual with traitmeagainst opponents with different traits. The respective numbers of each of thenTraitsopponent traits are provided in the arraytCount. The payoffs/scores for each of thenTraitsopponent traits must be stored and returned in the arraytScore.Important: must be overridden and implemented in subclasses that define game interactions between pairs of individuals (
nGroup=2,pairwise=true), otherwise seeIBS.HasIBS.DGroups.groupScores(int[], double[]).- Specified by:
pairScoresin interfaceIBS.HasIBS.DPairs- Parameters:
me- the trait index of the focal individualtraitCount- number of opponents with each traittraitScore- array for returning the scores of each opponent trait- Returns:
- score of focal individual
meaccumulated over all interactions
-
avgScores
public void avgScores(double[] density, double[] avgscores) Description copied from interface:Model.HasDE.DPairsCalculate the average payoff for the frequency of traits specified in the arraystatefor pairwise interactions. The average payoffs for each of thenTraitstraits must be stored and returned in the arrayscores.- Specified by:
avgScoresin interfaceModel.HasDE.DPairs- Parameters:
density- the frequency/density of each traitavgscores- the array for storing the average payoffs/scores of each trait
-
mixedScores
public void mixedScores(int[] traitCount, double[] traitScore) Description copied from interface:IBS.HasIBS.DPairsCalculate the average payoff/score in a finite population with the number of each trait provided incountfor pairwise interactions. The payoffs/scores for each of thenTraitstraits must be stored and returned in the arraytraitScores.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[])orIBS.HasIBS.DGroups.groupScores(int[], double[]), respectively.Note: If explicit calculations of the well-mixed scores are not available, interactions with everyone in well-mixed populations should checked for and excluded with a warning in
IBS.check()(seeCXPopulationfor an example).- Specified by:
mixedScoresin interfaceIBS.HasIBS.DPairs- Parameters:
traitCount- number of individuals for each traittraitScore- array for returning the payoffs/scores of each trait
-
setPayoffs
public void setPayoffs(double[][] payoffs) Set the payoffs from the2×2matrixpayoffs.- Parameters:
payoffs- the payoff matrix
-
getPayoffs
public double[][] getPayoffs()Get the payoffs as a2×2matrix.- Returns:
- the payoff matrix
-
setPayoff
public void setPayoff(double payoff, int me, int you) Set the payoff for typemeagainst typeyoutopayoff.- Parameters:
payoff- the payoff tomeme- the trait index of the row playeryou- the trait index of the column player
-
getPayoff
public double getPayoff(int me, int you) Get the payoff for typemeagainst typeyou.- Parameters:
me- the trait index of the row playeryou- the trait index of the column player- Returns:
- the payoff to
me
-
collectCLO
Description copied from interface:CLOProviderAll 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, theparserissues a warning and ignores the option. Thus, in general, implementing subclasses should first register their options and callsuper.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:
collectCLOin interfaceCLOProvider- Overrides:
collectCLOin classDiscrete- Parameters:
parser- the reference to parser that manages command line options- See Also:
-
adjustCLO
Description copied from interface:CLOProviderProviders of command line options may want to remove certain options that other providers provided by overriding this method. After all command line options are collected, all providers get a chance to adjust the collection. In particular, options should be removed that do not make sense in present context. Overriding methods usually callCLOParser.removeCLO(String[])or variants thereof.- Specified by:
adjustCLOin interfaceCLOProvider- Parameters:
parser- the reference to parser that manages command line options- See Also:
-
createIBSPop
Description copied from class:ModuleOpportunity to supply custom individual based simulations.- Overrides:
createIBSPopin classModule- Returns:
- the custom IBSPopulation or
nullto use default.
-