Class Module
- All Implemented Interfaces:
Runnable
,MilestoneListener
,Features
,CLOProvider
- Direct Known Subclasses:
Continuous
,Discrete
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested classes/interfaces inherited from interface Features
Features.Groups, Features.Pairs, Features.Static
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean[]
The array indicating which traits are active.final CLOption
Command line option to set death rate for ecological population updates.final CLOption
Command line option to set the geometry (interaction and competition graphs identical).final CLOption
Command line option to set the size of interaction groups.final CLOption
Command line option to set the population size.final CLOption
Command line option to set the traits on phase plane axis.final CLOption
Command line option to set the relative rate for updating each population/species.final CLOption
Command line option to set the color of traits.final CLOption
Command line option to disable individual traits.final CLOption
Command line option to assign trait names.protected Geometry
The geometry of competition structureprotected double
Death rate for ecological population updates.protected static Color[]
The array with default colors for traits.protected EvoLudo
The pacemaker of all models.(package private) IBSPopulation
The field point to the IBSPopulation that represents this module in individual based simulations.(package private) final int
In multi-species modules each species is represented by a Module, seespecies
.protected Geometry
The geometry of interaction structureprotected Logger
Logger for keeping track of and reporting events and issues.protected Map2Fitness
Map to convert score/payoff to fitnessprotected Markers
Markers for annotating graphical represenations of the state of the model.protected Model
Reference to current model.protected int
The number of active traits.protected String
The name of the species.protected int
The interaction group size.protected int
The population size.protected int
The number of traits in this module(package private) Module
Reference to Module of opponent.protected PlayerUpdate
Map to convert score/payoff to fitnessList with all species in module including this one.protected double
Update rate for this species.protected Geometry
The geometry of population (interaction and competition graphs are the same)protected Color[]
The array with trait colors.(package private) String[]
Names of traits.protected Color
Color for trajectories.int
The index for the vacant type (empty site) or-1
if Module does not admit empty sites. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
check()
Check all parameters.void
collectCLO
(CLOParser parser) All providers of command line options must implement this method to collect their options.Opportunity to supplyGeometry
, in case interaction and competition graphs are the same.Opportunity to supply custom individual based simulations.boolean[]
Gets an array indicating which traits are active.Returns a string with information about the authors of the module.Gets the competition geometry.double
Gets the death rate for ecological population updates.int
Get the index of dependent type or-1
if Module does not have an dependent type.Gets the geometry of the population.Gets the IBSPopulation that represents this module in individual based simulations ornull
for all other types of models.int
getID()
Gets unique identifierID
of species.Gets the interaction geometry.getKey()
Returns identifier of the active module.Gets the score/payoff to fitness map.ArrayList
<double[]> Get the list of markers.abstract double
Calculates and returns the maximum payoff/score of an individual.abstract double
Calculates and returns the maximum payoff/score of individuals in monomorphic populations.Color[]
Gets the colors for the mean values of traits.abstract double
Calculates and returns the minimum payoff/score of an individual.abstract double
Calculates and returns the minimum payoff/score of individuals in monomorphic populations.Type[]
Return array of Model types that this Module supports.abstract Mutation
Gets the mutation type.int
Gets the number of active traits.getName()
Gets the name of this speciesint
Gets the interaction group size.int
Gets the population size.int
Gets the numberof roles that an individual can adopt.int
Gets the number of different species in this module.int
Gets the number of traits in this Module.Gets the opponent of this module/population.Gets the score/payoff to fitness map.Gets list with all species.getSpecies
(int idx) Gets module of species at indexidx
.double
Gets the update rate of this species.abstract String
getTitle()
Returns title of active module, e.g.getTraitColor
(int trait) Gets the color for the trait with indextrait
.Color[]
Gets the colors for all traits.getTraitName
(int trait) Gets the name of the trait with indextrait
.String[]
Gets the names of all traits.Gets the color of trajectories.int
Get the index for the vacant type or-1
if Module does not admit empty sites.void
init()
Initialize Module based on current parameters.boolean
Checks whether dynamic is neutral, i.e.void
load()
Load new module and perform basic initializations.<T> ColorMap
<T> processColorMap
(ColorMap<T> colorMap) void
reset()
Reset Module based on current parameters.void
run()
void
setActiveTraits
(boolean[] active) Sets which traits are currently active.boolean
setDeathRate
(double rate) Sets the death rate for ecological population updates.void
setGeometries
(Geometry interaction, Geometry competition) Sets different geometries for interactions and competition.void
Sets the reference to the IBSPopulation that represents this module in individual based simulations.void
Set the current model.void
Sets the name of this species.boolean
setNGroup
(int size) Sets the interaction group size.boolean
setNPopulation
(int size) Sets the population size.void
setNTraits
(int nTraits) Sets the number of traits in this Module.void
setOpponent
(Module opponent) Sets the opponent of this module/population.boolean
setSpeciesUpdateRate
(double rate) Sets the species update rate torate
.boolean
setTraitColors
(Color[] colors) Sets trait colors specified incolors
.void
setTraitNames
(String[] names) Set trait names.boolean
setTrajectoryColor
(Color color) Sets color of trajectories.void
unload()
Unload module and free all resources.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface CLOProvider
adjustCLO
Methods inherited from interface Features
isPairwise, isStatic
Methods inherited from interface MilestoneListener
modelDidInit, modelDidReset, modelLoaded, modelRelaxed, modelRunning, modelSettings, modelStopped, modelUnloaded, moduleLoaded, moduleRestored, moduleUnloaded
-
Field Details
-
name
The name of the species. Mainly used in multi-species modules. -
engine
The pacemaker of all models. Interface with the outside world. -
logger
Logger for keeping track of and reporting events and issues. -
model
Reference to current model. -
species
List with all species in module including this one.Important:
List should be shared with other populations (to simplify bookkeeping) but the species list CANNOT be static! Otherwise it is impossible to run multiple instances of modules/models concurrently! -
ID
final int IDIn multi-species modules each species is represented by a Module, seespecies
. TheID
provides a unique identifier for each species. -
markers
Markers for annotating graphical represenations of the state of the model. -
ibs
IBSPopulation ibsThe field point to the IBSPopulation that represents this module in individual based simulations.null
for all other model types. -
VACANT
public int VACANTThe index for the vacant type (empty site) or-1
if Module does not admit empty sites. -
nTraits
protected int nTraitsThe number of traits in this module -
active
boolean[] activeThe array indicating which traits are active. -
nActive
protected int nActiveThe number of active traits.nActive <= nTraits
must hold. -
traitName
String[] traitNameNames of traits. -
defaultColor
The array with default colors for traits. Important: ifdefaultColor
is set already here (static allocation), headless mode for simulations is prevented. In order to avoid this, simply allocate and assign the colors in the constructor. -
traitColor
The array with trait colors. Important: iftraitColor
is set already here (static allocation), headless mode for simulations is prevented. In order to avoid this, simply allocate and assign the colors in the constructor. -
trajectoryColor
Color for trajectories. Important: iftrajectoryColor
is set already here, headless mode for simulations is prevented. In order to avoid this, simply allocate and assign the colors in the constructor. -
opponent
Module opponentReference to Module of opponent. For Modules referring to intra-species interactionsopponent == this
must hold. -
structure
The geometry of population (interaction and competition graphs are the same) -
interaction
The geometry of interaction structure -
competition
The geometry of competition structure -
speciesUpdateRate
protected double speciesUpdateRateUpdate rate for this species. Only used in multi-species modules. -
nPopulation
protected int nPopulationThe population size. -
deathRate
protected double deathRateDeath rate for ecological population updates. -
map2fitness
Map to convert score/payoff to fitness -
playerUpdate
Map to convert score/payoff to fitness -
nGroup
protected int nGroupThe interaction group size. -
cloSpeciesUpdateRate
Command line option to set the relative rate for updating each population/species. Only relevant for multi-species interactions. -
cloGeometry
Command line option to set the geometry (interaction and competition graphs identical).- See Also:
-
cloNPopulation
Command line option to set the population size. -
cloDeathRate
Command line option to set death rate for ecological population updates. -
cloNGroup
Command line option to set the size of interaction groups. -
cloTraitDisable
Command line option to disable individual traits. Any module offering this capability needs to add cloTrai to the set of available options. By default all traits are activated. -
cloTraitColors
Command line option to set the color of traits. -
cloTraitNames
Command line option to assign trait names. -
cloPhase2DAxis
Command line option to set the traits on phase plane axis.Note: option not automatically added. Modules that supports multiple traits should load it in
collectCLO(CLOParser)
.
-
-
Constructor Details
-
Module
Instantiate a new Module withengine
andpartner
. Ifpartner == null
this is a single species module and interactions within species (opponent == this
holds).- Parameters:
engine
- the pacemaker for running the modelpartner
- the module of the partner species ornull
for single species modules
-
-
Method Details
-
getName
Gets the name of this species- Returns:
- the name of the species
-
setName
Sets the name of this species. Ifname == null
the name is cleared.- Parameters:
name
- the new name of the species
-
getID
public int getID()Gets unique identifierID
of species.- Returns:
- the unique identifier of the species.
-
getMarkers
Get the list of markers. This serves to mark special values in different kinds of graphs.- Returns:
- the list of markers
-
setModel
Set the current model. This is available before the model get loaded. Useful for custom implementations of models.- Parameters:
model
- the current model
-
getSpecies
Gets module of species at indexidx
.- Parameters:
idx
- the index of species to retrieve- Returns:
- the module of species
-
getSpecies
Gets list with all species.- Returns:
- the list with all species
-
getNSpecies
public int getNSpecies()Gets the number of different species in this module.- Returns:
- the number of species in this module
-
getKey
Returns identifier of the active module. For example, 2x2 games inTBT
return "2x2". This corresponds to the argument for the--module
option to load a particular module. The default is to use the class name.- Returns:
- the identifying key of this module
-
getAuthors
Returns a string with information about the authors of the module.- Returns:
- the names of the authors
-
getTitle
Returns title of active module, e.g. 2x2 games inTBT
returns "2x2 Games".- Returns:
- the title of active module
-
load
public void load()Load new module and perform basic initializations.- See Also:
-
unload
public void unload()Unload module and free all resources.- See Also:
-
check
public boolean check()Check all parameters. After this call all parameters must be consistent. If parameter adjustments require a reset then this method must returntrue
.Note: All parameter changes that don't require a reset can be made on the fly, in particular also while a model is running.
- Returns:
true
to trigger reset- See Also:
-
init
public void init()Initialize Module based on current parameters. This requires that parameters are consistent, i.e.check()
has been called before.Note: The difference between
init()
andreset()
is thatinit()
leaves population structures untouched and only initializes the strategies.- See Also:
-
reset
public void reset()Reset Module based on current parameters. This requires that parameters are consistent, i.e.check()
has been called before.Note: The difference between
init()
andreset()
is thatinit()
leaves population structures untouched and only initializes the strategies.- See Also:
-
run
public void run()Default run-loop for modules. Opportunity to override in subclasses for running customized simulations. Currently only called from
EvoLudoJRE.simulation()
if custom simulation class is specified injar
file. -
getModelTypes
Return array of Model types that this Module supports.- Returns:
- the array of supported Model types
-
setIBSPopulation
Sets the reference to the IBSPopulation that represents this module in individual based simulations.- Parameters:
ibs
- the individual based population
-
getIBSPopulation
Gets the IBSPopulation that represents this module in individual based simulations ornull
for all other types of models.- Returns:
- the IBSPopulation that represents this module or
null
-
createIBSPop
Opportunity to supply custom individual based simulations.- Returns:
- the custom IBSPopulation or
null
to use default.
-
getVacant
public int getVacant()Get the index for the vacant type or-1
if Module does not admit empty sites. InDiscrete
modules this is the index of the vacant type e.g. in the name or color vectors. Currently unused inContinuous
modules.- Returns:
- the index of the vacant type
-
getDependent
public int getDependent()Get the index of dependent type or-1
if Module does not have an dependent type.Notes:
- Dependent types are used by replicator type models where the frequencies of all types must sum up to one. Currently only used by Discrete modules.
- Density modules do not have dependent types.
- By default use vacant type as the dependent
- Returns:
- the index of the vacant type
-
getNTraits
public int getNTraits()Gets the number of traits in this Module. For example, in 2x2 GamesTBT
this returns2
.- Returns:
- the number of traits
-
getNRoles
public int getNRoles()Gets the numberof roles that an individual can adopt. For example the role of a proposer or a responder in the Ultimatum game or the first or second movers in the Centipede game.- Returns:
- the number of roles of an individual
-
setNTraits
public void setNTraits(int nTraits) Sets the number of traits in this Module.Note:
Changing the number of traits is a fairly involved change because it requires re-allocating most memory. Most Modules setnTraits
early on and leave it unchanged.- Parameters:
nTraits
- the number of traits
-
setActiveTraits
public void setActiveTraits(boolean[] active) Sets which traits are currently active.- Parameters:
active
- the array indicating active traits (ornull
if all traits are active)
-
getActiveTraits
public boolean[] getActiveTraits()Gets an array indicating which traits are active.- Returns:
- the array of active traits
-
getNActive
public int getNActive()Gets the number of active traits.- Returns:
- the number of active traits
-
getTraitName
Gets the name of the trait with indextrait
.- Parameters:
trait
- the index of the trait- Returns:
- the name of the trait
-
getTraitNames
Gets the names of all traits. By default returns{ "Trait A", "Trait B",...}
.- Returns:
- the array with the names of all traits
-
setTraitNames
Set trait names. Underscores, '_', are converted to spaces.Note: If
names == null
ornames.length < nTraits
then additional traits are named "Trait A", "Trait B", etc. Ifnames.length > nTraits
then excess names are ignored.- Parameters:
names
- the names of the traits
-
getTraitColor
Gets the color for the trait with indextrait
.- Parameters:
trait
- the index of the trait- Returns:
- the color of the trait
-
getTraitColors
Gets the colors for all traits.- Returns:
- the array of trait colors
-
getMeanColors
Gets 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.- Returns:
- the array of mean value colors
-
setTraitColors
Sets trait colors specified incolors
. If less thannTraits
colors are specified, additional traits are colored using the default colors. If still not enough, random colors are generated. BothDiscrete
andContinuous
modules require2*nTraits
colors. The meaning of the second set ofnTraits
colors depends on the trait type:- discrete
- the colors of individuals that switched strategy since the last update
- continuous
- the colors for the mean ± standard deviation, see e.g.
Mean
.
- Parameters:
colors
- the array of colors for the different traits- Returns:
true
always signal that colors have changed (too difficult and of too little importance to check whether colors remained the same)
-
getTrajectoryColor
Gets the color of trajectories.- Returns:
- the trajectory color (defaults to black)
-
setTrajectoryColor
Sets color of trajectories. Default color is black. Ifcolor
isnull
reverts to default.Note: Using transparent colors is useful for models with noise (simulations or SDE's) to identify regions of attraction (e.g. stochastic limit cycles) as darker shaded areas because the population spends much of its time there while less frequently visited areas of the phase space are lighter in color.
- Parameters:
color
- the color for the trajectories- Returns:
true
if color changed
-
processColorMap
Opportunity for modules to make adjustments to the color map in graphs such asPop2D
orPop3D
. By default no changes are made.- Type Parameters:
T
- the type of the color map- Parameters:
colorMap
- the color map- Returns:
- the processed color map
- See Also:
-
getMinGameScore
public abstract double getMinGameScore()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.- Returns:
- the minimum payoff/score
- See Also:
-
getMaxGameScore
public abstract double getMaxGameScore()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.- Returns:
- the maximum payoff/score
- See Also:
-
getMinMonoGameScore
public abstract double getMinMonoGameScore()Calculates and returns the minimum payoff/score of individuals in monomorphic populations.- Returns:
- the minimum payoff/score in monomorphic populations
-
getMaxMonoGameScore
public abstract double getMaxMonoGameScore()Calculates and returns the maximum payoff/score of individuals in monomorphic populations.- Returns:
- the maximum payoff/score in monomorphic populations
-
isNeutral
public boolean isNeutral()Checks whether dynamic is neutral, i.e. no selection acting on the different traits.- Returns:
true
if all payoffs identical
-
getOpponent
Gets the opponent of this module/population. By default, for intra-species interactions, simply returns this module/population, i.eopponent == this
.- Returns:
- the opponent of this population
-
setOpponent
Sets the opponent of this module/population. By default, for intra-species interactions,opponent == this
holds.- Parameters:
opponent
- the opponent of this population
-
getGeometry
Gets the geometry of the population.- Returns:
- the geometry of the population
-
createGeometry
Opportunity to supplyGeometry
, in case interaction and competition graphs are the same.- Returns:
- the new geometry
-
setGeometries
Sets different geometries for interactions and competition.- Parameters:
interaction
- the geometry for interactionscompetition
- the geometry for competition- See Also:
-
getInteractionGeometry
Gets the interaction geometry.- Returns:
- the interaction geometry
- See Also:
-
getCompetitionGeometry
Gets the competition geometry.- Returns:
- the competition geometry
- See Also:
-
setSpeciesUpdateRate
public boolean setSpeciesUpdateRate(double rate) Sets the species update rate torate
. Only used in multi-species modules. Determines the relative rate at which this species is picked as compared to others.- Parameters:
rate
- the update rate of this species- Returns:
true
if species update rate changed- See Also:
-
getSpeciesUpdateRate
public double getSpeciesUpdateRate()Gets the update rate of this species. Only used in multi-species modules. Determines the relative rate at which this species is picked as compared to others.- Returns:
- the species update rate
- See Also:
-
setNPopulation
public boolean setNPopulation(int size) Sets the population size. For models with vacancies this is the maximum population size. Currently this only affects IBS and SDE models. For SDE's it determines the magnitude of noise. For IBS this is a fundamental change, which mandates requesting to reset the model.- Parameters:
size
- the population size- Returns:
true
if population size changed- See Also:
-
getNPopulation
public int getNPopulation()Gets the population size.Note: Without vacant sites the population size is fixed. For ecological models with vacant sites this corresponds to the maximum population size.
- Returns:
- the population size
-
setDeathRate
public boolean setDeathRate(double rate) Sets the death rate for ecological population updates.- Parameters:
rate
- the death rate- Returns:
true
if the death rate changed
-
getDeathRate
public double getDeathRate()Gets the death rate for ecological population updates.- Returns:
- the death rate
-
getMutation
Gets the mutation type.- Returns:
- the mutation type
-
getMapToFitness
Gets the score/payoff to fitness map.- Returns:
- the score-to-fitness map
-
getPlayerUpdate
Gets the score/payoff to fitness map.- Returns:
- the score-to-fitness map
-
setNGroup
public boolean setNGroup(int size) Sets the interaction group size. Changes trigger a request to reset the module.- Parameters:
size
- the interaction group size- Returns:
true
if the group size changed
-
getNGroup
public int getNGroup()Gets the interaction group size.- Returns:
- the interaction group size
-
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
- Parameters:
parser
- the reference to parser that manages command line options- See Also:
-