Class Module<T extends Module<T>>
- Type Parameters:
T- the type of the module (self-referential generic)
- All Implemented Interfaces:
Runnable, LifecycleListener, RunListener, Features, CLOProvider
- Direct Known Subclasses:
Continuous, Discrete
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested classes/interfaces inherited from interface Features
Features.Groups, Features.Multispecies, Features.Pairs, Features.Payoffs, Features.Static -
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean[]The array indicating which traits are active.final CLOptionCommand line option to set death rate for ecological population updates.final CLOptionCommand line option to set the geometry (interaction and competition graphs identical).final CLOptionCommand line option to set the size of interaction groups.final CLOptionCommand line option to set the population size.final CLOptionCommand line option to set the traits on phase plane axes.final CLOptionCommand line option to set the color of traits.final CLOptionCommand line option to disable individual traits.final CLOptionCommand line option to assign trait names.protected doubleDeath rate for ecological population updates.protected static Color[]The array with default colors for traits.protected EvoLudoThe pacemaker of all models.(package private) IBSPopulation<?, ?> The field point to the IBSPopulation that represents this module in individual based simulations.(package private) final intIn multi-species modules each species is represented by a Module, seespecies.protected LoggerLogger for keeping track of and reporting events and issues.protected Map2FitnessMap to convert score/payoff to fitnessprotected MarkersMarkers for annotating graphical represenations of the state of the model.protected ModelReference to current model.protected intThe number of active traits.protected StringThe name of the species.protected intThe interaction group size.protected intThe population size.protected intThe number of traits in this module(package private) TReference to Module of opponent.protected PlayerUpdateMap to convert score/payoff to fitnessList with all species in module including this one.protected AbstractGeometryThe geometry of population (interaction and competition graphs are the same)protected Color[]The array with trait colors.(package private) String[]Names of traits.protected ColorColor for trajectories.static final ColorThe default name of the vacant type (empty site).static final StringThe default name of the vacant type (empty site).protected intThe index for the vacant type (empty site) or-1if Module does not admit empty sites. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAddpopto list of species.booleancheck()Check all parameters.voidcollectCLO(CLOParser parser) All providers of command line options must implement this method to collect their options.IBSPopulation<?, ?> Opportunity to supply custom individual based simulations.createModel(ModelType type) Creates a model of typetypeformodule.boolean[]Gets an array indicating which traits are active.Returns a string with information about the authors of the module.doubleGets the death rate for ecological population updates.Gets the geometry of the population.IBSPopulation<?, ?> Gets the IBSPopulation that represents this module in individual based simulations ornullfor all other types of models.intgetID()Gets unique identifierIDof species.getKey()Returns identifier of the active module.Default implementation of Payoffs interface.List<double[]> Get the list of markers.Color[]Gets the colors for the mean values of traits.Return array of Model types that this Module supports.abstract MutationGets the mutation type.intGets the number of active traits.getName()Gets the name of this speciesintGets the interaction group size.intGets the population size.intGets the number of roles that an individual can adopt.intGets the number of different species in this module.intGets 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.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.intGet the index for the vacant type or-1if Module does not admit empty sites.booleanCheck if module admits vacant type (empty sites).voidinit()Initialize Module based on current parameters.voidload()Load new module and perform basic initializations.private StringnameTrait(int trait) Get default name for trait with indextrait.<M> ColorMap<M> processColorMap(ColorMap<M> colorMap) voidreset()Reset Module based on current parameters.voidrun()voidsetActiveTraits(boolean[] active) Sets which traits are currently active.booleansetDeathRate(double rate) Sets the death rate for ecological population updates.voidsetIBSPopulation(IBSPopulation<?, ?> ibs) Sets the reference to the IBSPopulation that represents this module in individual based simulations.voidSet the current model.final voidSets the name of this species.booleansetNGroup(int size) Sets the interaction group size.booleansetNPopulation(int size) Sets the population size.voidsetNTraits(int nTraits) Sets the number of traits in this Module.voidsetNTraits(int nTraits, int vacantIdx) Sets the number of traits and the index of the vacant type (empty site).voidsetOpponent(T opponent) Sets the opponent of this module/population.booleansetTraitColors(Color[] colors) Sets trait colors specified incolors.voidsetTraitNames(String[] names) Set trait names.booleansetTrajectoryColor(Color color) Sets color of trajectories.voidunload()Unload module and free all resources.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CLOProvider
adjustCLOMethods inherited from interface Features
getTitle, isMultispecies, isPairwise, isStaticMethods inherited from interface LifecycleListener
modelLoaded, modelUnloaded, moduleLoaded, moduleRestored, moduleUnloadedMethods inherited from interface RunListener
modelDidInit, modelDidReset, modelRelaxed, modelRunning, modelSettings, modelStopped
-
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
-
ID
final int IDIn multi-species modules each species is represented by a Module, seespecies. TheIDprovides a unique identifier for each species. -
markers
Markers for annotating graphical represenations of the state of the model. -
opponent
-
ibspop
IBSPopulation<?,?> ibspopThe field point to the IBSPopulation that represents this module in individual based simulations.nullfor all other model types. -
VACANT_NAME
-
VACANT_COLOR
The default name of the vacant type (empty site). -
vacantIdx
protected int vacantIdxThe index for the vacant type (empty site) or-1if 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 <= nTraitsmust hold. -
traitName
String[] traitNameNames of traits. -
defaultColor
The array with default colors for traits. Important: ifdefaultColoris 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: iftraitColoris 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: iftrajectoryColoris set already here, headless mode for simulations is prevented. In order to avoid this, simply allocate and assign the colors in the constructor. -
structure
The geometry of population (interaction and competition graphs are the same) -
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. -
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. -
cloPhase2DAxes
Command line option to set the traits on phase plane axes.Note: option not automatically added. Modules that supports multiple traits should load it in
collectCLO(CLOParser).
-
-
Constructor Details
-
Module
Instantiate a new Module withengineandpartner. Ifpartner == nullthis is a single species module and interactions within species (opponent == thisholds).- Parameters:
engine- the pacemaker for running the modelpartner- the module of the partner species ornullfor single species modules
-
-
Method Details
-
getName
-
setName
Sets the name of this species. Ifname == nullthe name is cleared.- Parameters:
name- the new name of the species
-
getID
public int getID()Gets unique identifierIDof 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
-
add
Addpopto list of species. Duplicate entries are ignored. Allocate new list if necessary. Assign generic name to species if none provided.- Parameters:
pop- the module to add to species list.- Returns:
trueifdpopsuccessfully added;falseadding failed or already included in list.
-
createModel
Creates a model of typetypeformodule.Note: Override to provide custom model implementations.
Important: any custom model implementations that involve random numbers, must use the shared random number generator for reproducibility
- Parameters:
type- the type ofModelto create- Returns:
- the model for
moduleornullif the module does not support the requested model type - See Also:
-
setModel
Set the current model. This is available before the model get loaded. Useful for custom implementations of models.- Parameters:
model- the current model
-
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 == thisholds.- Parameters:
opponent- the opponent of this population
-
getSpecies
Gets module of species at indexidx.- Parameters:
idx- the index of species to retrieve- Returns:
- the module of species
-
getSpecies
-
getNSpecies
public int getNSpecies()Gets the number of different species in this module.- Returns:
- the number of species in this module
-
getKey
-
getAuthors
Returns a string with information about the authors of the module.- Returns:
- the names of the authors
-
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:
trueto trigger reset- See Also:
-
init
-
reset
-
run
-
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 ornullfor all other types of models.- Returns:
- the IBSPopulation that represents this module or
null
-
createIBSPopulation
Opportunity to supply custom individual based simulations.- Returns:
- the custom IBSPopulation or
nullto use default.
-
getVacantIdx
public int getVacantIdx()Get the index for the vacant type or-1if Module does not admit empty sites. InDiscretemodules this is the index of the vacant type e.g. in the name or color vectors. Currently unused inContinuousmodules.- Returns:
- the index of the vacant type
-
hasVacant
public boolean hasVacant()Check if module admits vacant type (empty sites).- Returns:
trueif module admits vacant sites
-
getNTraits
public int getNTraits()Gets the number of traits in this Module. For example, in 2x2 GamesTBTthis returns2.- Returns:
- the number of traits
-
getNRoles
public int getNRoles()Gets the number of 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 setnTraitsearly on and leave it unchanged.- Parameters:
nTraits- the number of traits
-
setNTraits
public void setNTraits(int nTraits, int vacantIdx) Sets the number of traits and the index of the vacant type (empty site).- Parameters:
nTraits- the number of traitsvacantIdx- the index of the vacant type
-
setActiveTraits
public void setActiveTraits(boolean[] active) Sets which traits are currently active.- Parameters:
active- the array indicating active traits (ornullif 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 == nullornames.length < nTraitsthen additional traits are named "Trait A", "Trait B", etc. Ifnames.length > nTraitsthen excess names are ignored.- Parameters:
names- the names of the traits
-
nameTrait
Get default name for trait with indextrait.- Parameters:
trait- the index of the trait- Returns:
- the default name for the trait
-
getTraitColor
Gets the color for the trait with indextrait.- Parameters:
trait- the index of the trait- Returns:
- the color of the trait
-
getTraitColors
-
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. Ifcolorsisnulldefault colors are used until exhausted and then complemented by random colors. Otherwise the number of colors must equalnTraitsor2 * nTraits. For modules that have vacant sites, the length may benTraits - 1or2 * (nTraits - 1), respectively. In the latter case the default colors for vacant sites are used.Note:The meaning of the second set of
nTraitscolors depends on the module type:- Discrete
- the colors of individuals that switched traits 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:
trueif colors successfuly set- See Also:
-
getTrajectoryColor
Gets the color of trajectories.- Returns:
- the trajectory color (defaults to black)
-
setTrajectoryColor
Sets color of trajectories. Default color is black. Ifcolorisnullreverts 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:
trueif color changed
-
processColorMap
-
getGeometry
Gets the geometry of the population.- Returns:
- the geometry of the population
-
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:
trueif 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:
trueif the death rate changed
-
getDeathRate
public double getDeathRate()Gets the death rate for ecological population updates.- Returns:
- the death rate
-
getMutation
-
getMap2Fitness
Default implementation of Payoffs interface.- Returns:
- the score-to-fitness map
- See Also:
-
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:
trueif the group size changed
-
getNGroup
public int getNGroup()Gets the interaction group size.- Returns:
- the interaction group size
-
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- Parameters:
parser- the reference to parser that manages command line options- See Also:
-