Class RSP
- 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.StatisticsStationary
,HasMean
,HasMean.Fitness
,HasMean.Traits
,HasPop2D
,HasPop2D.Fitness
,HasPop2D.Traits
,HasPop3D
,HasPop3D.Fitness
,HasPop3D.Traits
,HasS3
,CLOProvider
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
The extension for IBS simulations specific to3×3
games.Nested classes/interfaces inherited from interface Features
Features.Groups, Features.Multispecies, Features.Pairs, Features.Payoffs, Features.Static
Nested classes/interfaces inherited from interface HasHistogram
HasHistogram.Degree, HasHistogram.Fitness, HasHistogram.StatisticsProbability, HasHistogram.StatisticsStationary, HasHistogram.StatisticsTime, HasHistogram.Strategy
Nested classes/interfaces inherited from interface HasMean
HasMean.Fitness, HasMean.Traits
Nested classes/interfaces inherited from interface HasPop2D
HasPop2D.Fitness, HasPop2D.Traits
Nested classes/interfaces inherited from interface HasPop3D
HasPop3D.Fitness, HasPop3D.Traits
Nested classes/interfaces inherited from interface IBS.HasIBS
IBS.HasIBS.CGroups, IBS.HasIBS.CPairs, IBS.HasIBS.DGroups, IBS.HasIBS.DPairs, IBS.HasIBS.MCGroups, IBS.HasIBS.MCPairs
Nested 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 CLOption
Command line option to set the payoff matrix.static final int
The trait (and index) value of the trait 'paper'.(package private) double[][]
The3×3
payoff matrix for interactions between the three types.static final int
The trait (and index) value of the trait 'rock'.static final int
The trait (and index) value of the trait 'scissors'.Fields inherited from class Discrete
cloMonoStop, monoStop, mutation, species
Fields 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
Fields inherited from interface HasS3
CORNER_LEFT, CORNER_RIGHT, CORNER_TOP, EDGE_BOTTOM, EDGE_LEFT, EDGE_RIGHT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Providers of command line options may want to remove certain options that other providers provided by overriding this method.void
avgScores
(double[] density, double[] avgscores) Calculate the average payoff for the frequency of traits specified in the arraystate
for pairwise interactions.void
collectCLO
(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.int
For replicator dynamics the frequencies of all traits must sum up to one.double
Calculates and returns the maximum payoff/score of an individual.double
Calculates and returns the minimum payoff/score of an individual.double
getMonoPayoff
(int type) Calculate and return the payoff/score of individuals in monomorphic populations with traittype
.double[][]
Get the payoff matrix.getTitle()
Returns title of active module, e.g.void
load()
Load new module and perform basic initializations.void
mixedScores
(int[] traitCount, double[] traitScore) Calculate the average payoff/score in a finite population with the number of each trait provided incount
for pairwise interactions.double
pairScores
(int me, int[] traitCount, double[] traitScore) Calculate and return total (accumulated) payoff/score for pairwise interactions of the focal individual with traitme
against opponents with different traits.void
setPayoffs
(double[][] payMatrix) Set the payoff matrix topayMatrix
.void
unload()
Unload module and free all resources.Methods inherited from class Discrete
add, getMaxMonoPayoff, getMinMonoPayoff, getMonoStop, getMutation, setMonoStop
Methods inherited from class Module
check, createGeometry, createModel, getActiveTraits, getCompetitionGeometry, getDeathRate, getGeometry, getIBSPopulation, getID, getInteractionGeometry, getKey, getMap2Fitness, getMarkers, getMeanColors, getModelTypes, getNActive, getName, getNGroup, getNPopulation, getNRoles, getNSpecies, getNTraits, getOpponent, getPlayerUpdate, getSpecies, getSpecies, getTraitColor, getTraitColors, getTraitName, getTraitNames, getTrajectoryColor, getVacant, init, processColorMap, reset, run, setActiveTraits, setDeathRate, setGeometries, setIBSPopulation, setModel, setName, setNGroup, setNPopulation, setNTraits, setOpponent, setTraitColors, setTraitNames, setTrajectoryColor
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface Features
isMultispecies, isStatic
Methods inherited from interface Features.Pairs
isPairwise
Methods inherited from interface Features.Payoffs
getMap2Fitness, getMaxMonoPayoff, getMinMonoPayoff, isNeutral
Methods inherited from interface HasHistogram
getCustomLevels, getNTraits, getTraitColors
Methods inherited from interface IBS.HasIBS
createIBS
Methods inherited from interface MilestoneListener
modelDidInit, modelDidReset, modelLoaded, modelRelaxed, modelRunning, modelSettings, modelStopped, modelUnloaded, moduleLoaded, moduleRestored, moduleUnloaded
-
Field Details
-
ROCK
public static final int ROCKThe trait (and index) value of the trait 'rock'.- See Also:
-
SCISSORS
public static final int SCISSORSThe trait (and index) value of the trait 'scissors'.- See Also:
-
PAPER
public static final int PAPERThe trait (and index) value of the trait 'paper'.- See Also:
-
payoff
double[][] payoffThe3×3
payoff matrix for interactions between the three types. -
cloPayoff
Command line option to set the payoff matrix.
-
-
Constructor Details
-
RSP
Create a new instance of the module for rock-scissors-paper 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. -
unload
public void unload()Description copied from class:Module
Unload module and free all resources. -
getAuthors
Description copied from class:Module
Returns a string with information about the authors of the module.- Overrides:
getAuthors
in classModule
- Returns:
- the names of the authors
-
getTitle
Description copied from interface:Features
Returns title of active module, e.g. 2x2 games inTBT
returns "2x2 Games". -
getDependent
public int getDependent()Description copied from interface:Model.HasDE
For replicator dynamics the frequencies of all traits must sum up to one. Hence, fornTraits
traits there are onlynTraits-1
degrees 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:
getDependent
in interfaceModel.HasDE
- Returns:
- the index of the dependent trait (or
-1
if there is none)
-
getMinPayoff
public double getMinPayoff()Description copied from interface:Features.Payoffs
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:
getMinPayoff
in interfaceFeatures.Payoffs
- Returns:
- the minimum payoff/score
- See Also:
-
getMaxPayoff
public double getMaxPayoff()Description copied from interface:Features.Payoffs
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:
getMaxPayoff
in interfaceFeatures.Payoffs
- Returns:
- the maximum payoff/score
- See Also:
-
getMonoPayoff
public double getMonoPayoff(int type) Description copied from class:Discrete
Calculate and return the payoff/score of individuals in monomorphic populations with traittype
.Note: Optional implementation. Returns
Double#NaN
if not defined or not implemented.- Overrides:
getMonoPayoff
in 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.DPairs
Calculate and return total (accumulated) payoff/score for pairwise interactions of the focal individual with traitme
against opponents with different traits. The respective numbers of each of thenTraits
opponent traits are provided in the arraytCount
. The payoffs/scores for each of thenTraits
opponent 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:
pairScores
in 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
me
accumulated over all interactions
-
avgScores
public void avgScores(double[] density, double[] avgscores) Description copied from interface:Model.HasDE.DPairs
Calculate the average payoff for the frequency of traits specified in the arraystate
for pairwise interactions. The average payoffs for each of thenTraits
traits must be stored and returned in the arrayscores
.- Specified by:
avgScores
in 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.DPairs
Calculate the average payoff/score in a finite population with the number of each trait provided incount
for pairwise interactions. The payoffs/scores for each of thenTraits
traits 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()
(seeCXPopulation
for an example).- Specified by:
mixedScores
in 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[][] payMatrix) Set the payoff matrix topayMatrix
.- Parameters:
payMatrix
- the new payoff matrix
-
getPayoffs
public double[][] getPayoffs()Get the payoff matrix.- Returns:
- the payoff matrix
-
collectCLO
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, theparser
issues 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:
collectCLO
in interfaceCLOProvider
- Overrides:
collectCLO
in classDiscrete
- Parameters:
parser
- the reference to parser that manages command line options- See Also:
-
adjustCLO
Description copied from interface:CLOProvider
Providers 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:
adjustCLO
in interfaceCLOProvider
- Parameters:
parser
- the reference to parser that manages command line options- See Also:
-
createIBSPop
Description copied from class:Module
Opportunity to supply custom individual based simulations.- Overrides:
createIBSPop
in classModule
- Returns:
- the custom IBSPopulation or
null
to use default.
-