Class Mutualism
- All Implemented Interfaces:
Runnable, LifecycleListener, Model.HasDE, Model.HasDE.DPairs, Model.HasDE.EM, Model.HasDE.ODE, Model.HasDE.RK5, Model.HasIBS, Model.HasIBS.DPairs, RunListener, Features, Features.Pairs, Features.Payoffs, HasHistogram, HasHistogram.Degree, HasHistogram.Fitness, HasHistogram.StatisticsStationary, HasMean, HasMean.Fitness, HasMean.Traits, HasPhase2D, HasPop2D, HasPop2D.Fitness, HasPop2D.Traits, HasPop3D, HasPop3D.Fitness, HasPop3D.Traits, CLOProvider
2×2 games in interactions
between species, while competition remains within species.
For example, with two well-mixed populations of size N and M
all individuals of the first species interact with all M members of
the second species. Converely, the members of the second species interact
with N members of the first species.
Structured populations are represented by two separate but aligned geometries
such that interactions happen between geometries while competition happens
within each geometry. For example, lattice structured populations are
represented by two layers, one for each species with interactions between
them and competition within. Thus, on a regular lattice with k
neighbours an individual with index i interacts with k+1
individuals, namely it's k neighbours plus the one at the same
location i on the other layer.
Notes:
- The population sizes of each species needs to be the same. Except for well-mixed populations.
- The competition and interaction structures can be different within and/or between species.
- Author:
- Christoph Hauert
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThe map for translating the data of the ecological public goods game models into 2D phase plane representation.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 HasPhase2D
HasPhase2D.Data2PhaseNested 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 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.SDENested classes/interfaces inherited from interface Model.HasIBS
Model.HasIBS.CGroups, Model.HasIBS.CPairs, Model.HasIBS.DGroups, Model.HasIBS.DPairs, Model.HasIBS.MCGroups, Model.HasIBS.MCPairs -
Field Summary
FieldsModifier and TypeFieldDescription(package private) doubleThe payoff for mutual cooperation.(package private) doubleThe payoff to a cooperator when facing a defector.final CLOptionCommand line option to set the payoffs for the host species (when interacting with the mutualist species).final CLOptionCommand line option to set the payoffs for the mutualist species (when interacting with the host species).static final intThe trait (and index) value of cooperators.static final intThe trait (and index) value of defectors.(package private) doubleThe payoff for mutual defection.(package private) doubleThe payoff to a defector when facing a cooperator.(package private) Mutualism.MutualismMapThe map for translating the model data into 2D phase plane representation.(package private) MutualismThe reference to the partner species withpartner.partner == this.Fields inherited from class Discrete
cloMonoStop, monoStop, mutationFields inherited from class Module
active, birthRate, cloBirthRate, cloCompRate, cloDeathRate, cloGeometry, cloModel, cloNGroup, cloNPopulation, cloPhase2DAxes, cloTraitColors, cloTraitDisable, cloTraitNames, competitionRate, competitionRates, deathRate, defaultColor, engine, ibspop, id, logger, map2fitness, model, nActive, name, nGroup, nPopulation, nTraits, opponent, playerUpdate, species, structure, traitColor, traitName, trajectoryColor, VACANT_COLOR, VACANT_NAME, vacantIdx -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidavgScores(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.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.doubleCalculates and returns the minimum payoff/score of an individual.doublegetMonoPayoff(int mono) Calculate and return the payoff/score of individuals in monomorphic populations with traittype.doublegetPayoff(int me, int you) Get the payoff when traitmeinteracts withyou(in the other species).double[][]Get the payoffs in the form of a2×2matrix for the species represented by this module (identified byModule.id).Get the map that transforms the data of the module to a 2D phase plane (projection).getTitle()Returns title of active module, e.g.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 when traitmeinteracts withyou(in the other species).voidsetPayoffs(double[][] payoffs) Set the payoffs from the2×2matrixpayoffsfor the species represented by this module (identified byModule.id).voidunload()Unload module and free all resources.Methods inherited from class Discrete
createModel, getMaxMonoPayoff, getMinMonoPayoff, getMonoStop, getMutation, setMonoStopMethods inherited from class Module
add, check, createIBSPopulation, getActiveTraits, getBirthRate, getCompetitionRate, getCompetitionRates, getDeathRate, getGeometry, getIBSPopulation, getId, getMap2Fitness, getMeanColors, getModelType, getModelTypes, getNActive, getName, getNGroup, getNPopulation, getNRoles, getNSpecies, getNTraits, getOpponent, getPlayerUpdate, getSpecies, getSpecies, getTraitColor, getTraitColors, getTraitName, getTraitNames, getTrajectoryColor, getVacantIdx, hasVacant, init, preprocessModelOption, processColorMap, reset, run, setActiveTraits, setBirthRate, setCompetitionRates, setDeathRate, setIBSPopulation, setModel, setName, setNGroup, setNPopulation, setNTraits, setNTraits, setOpponent, setTraitColors, setTraitNames, setTrajectoryColorMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CLOProvider
adjustCLOMethods 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 HasPhase2D
setPhase2DMapMethods inherited from interface LifecycleListener
modelLoaded, modelUnloaded, moduleLoaded, moduleRestored, moduleUnloadedMethods inherited from interface Model.HasIBS
createIBSMethods inherited from interface RunListener
modelDidInit, modelDidReset, modelRelaxed, modelRunning, modelSettings, modelStopped
-
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:
-
alpha
double alphaThe payoff for mutual cooperation. -
beta
double betaThe payoff to a cooperator when facing a defector. -
gamma
double gammaThe payoff to a defector when facing a cooperator. -
delta
double deltaThe payoff for mutual defection. -
partner
Mutualism partnerThe reference to the partner species withpartner.partner == this. -
map
The map for translating the model data into 2D phase plane representation. -
cloPayHost
Command line option to set the payoffs for the host species (when interacting with the mutualist species). -
cloPayMutualist
Command line option to set the payoffs for the mutualist species (when interacting with the host species).
-
-
Constructor Details
-
Mutualism
Create a new instance of the module for inter-species2×2games.Important:
This instantiates only the skeleton and only of one species. The other species is created only whenloading this module.- Parameters:
engine- the manager of modules and pacemaker for running the model
-
Mutualism
Create a new instance of the second, partner species for inter-species2×2games.- Parameters:
partner- the reference to the partner species
-
-
Method Details
-
load
public void load()Load new module and perform basic initializations.Notes:
- Because the
HostandMutualistspecies are identical (potentially apart from interaction parameters) almost everything can be allocated and set in theload()method. - Otherwise, species specific settings can be moved to the constructor. In
case the species differ more and e.g. use different variables additional
species can be defined as inner classes that extend the outer class (here
Mutualism), seeEcoMutualismfor an example.
- Because the
-
unload
public void unload()Unload module and free all resources.Important:
This method is only called for the first created instance (seeMutualism(EvoLudo)) but not it's partner (seeMutualism(Mutualism)). In order to properly unload both speciespartner.unload()needs to be called. However, to avoid infinite loops, use, e.g.if (partner != null) { partner.partner = null; partner.unload(); partner = null; } -
getKey
-
getAuthors
Description copied from class:ModuleReturns a string with information about the authors of the module.- Overrides:
getAuthorsin classModule<Discrete>- Returns:
- the names of the authors
-
getTitle
-
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 mono) Calculate and return the payoff/score of individuals in monomorphic populations with traittype.Note: Optional implementation. Returns
Double#NaNif not defined or not implemented.Note: mono score is ill defined as the homogeneous states of the population and its opponent is required!
- Overrides:
getMonoPayoffin classDiscrete- Parameters:
mono- the index of the trait- Returns:
- payoff/score in monomorphic population with trait
type
-
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) Calculate 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
Model.HasIBS.DPairs.pairScores(int, int[], double[])orModel.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
Model.check()(seeCXPopulationfor an example).Note:
countrefers to opponent (here a different species)- Specified by:
mixedScoresin interfaceModel.HasIBS.DPairs- Parameters:
traitCount- number of individuals for each traittraitScore- array for returning the payoffs/scores of each trait
-
pairScores
public double pairScores(int me, int[] traitCount, double[] traitScore) Description copied from interface:Model.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 seeModel.HasIBS.DGroups.groupScores(int[], double[]).- Specified by:
pairScoresin interfaceModel.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
-
setPayoffs
public void setPayoffs(double[][] payoffs) Set the payoffs from the2×2matrixpayoffsfor the species represented by this module (identified byModule.id).- Parameters:
payoffs- the payoff matrix
-
getPayoffs
public double[][] getPayoffs()Get the payoffs in the form of a2×2matrix for the species represented by this module (identified byModule.id).- Returns:
- the payoff matrix
-
setPayoff
public void setPayoff(double payoff, int me, int you) Set the payoff when traitmeinteracts withyou(in the other species).- Parameters:
payoff- the payoff tomeme- the trait index of the row playeryou- the trait index of the column player (refers to other species)
-
getPayoff
public double getPayoff(int me, int you) Get the payoff when traitmeinteracts withyou(in the other species).- Parameters:
me- the trait index of the row playeryou- the trait index of the column player (refers to other species)- Returns:
- the payoff to
me
-
getPhase2DMap
Description copied from interface:HasPhase2DGet the map that transforms the data of the module to a 2D phase plane (projection).- Specified by:
getPhase2DMapin interfaceHasPhase2D- Returns:
- the map
-
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:
-