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.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 GeometryThe geometry of competition structureprotected doubleDeath rate for ecological population updates.protected static Color[]The array with default colors for traits.protected EvoLudoThe pacemaker of all models.(package private) IBSPopulationThe 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 GeometryThe geometry of interaction structureprotected 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) ModuleReference to Module of opponent.protected PlayerUpdateMap to convert score/payoff to fitnessList with all species in module including this one.protected GeometryThe 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.intThe index for the vacant type (empty site) or-1if Module does not admit empty sites. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheck()Check all parameters.voidcollectCLO(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.createModel(Type 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.Gets the competition geometry.doubleGets the death rate for ecological population updates.Gets the geometry of the population.Gets the IBSPopulation that represents this module in individual based simulations ornullfor all other types of models.intgetID()Gets unique identifierIDof species.Gets the interaction geometry.getKey()Returns identifier of the active module.Default implementation of Payoffs interface.ArrayList<double[]> Get the list of markers.Color[]Gets the colors for the mean values of traits.Type[]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.voidinit()Initialize Module based on current parameters.voidload()Load new module and perform basic initializations.<T> ColorMap<T> processColorMap(ColorMap<T> 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.voidsetGeometries(Geometry interaction, Geometry competition) Sets different geometries for interactions and competition.voidSets the reference to the IBSPopulation that represents this module in individual based simulations.voidSet the current model.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.voidsetOpponent(Module 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 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. TheIDprovides 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.nullfor all other model types. -
VACANT
public int VACANTThe 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. -
opponent
Module opponentReference to Module of opponent. For Modules referring to intra-species interactionsopponent == thismust 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 -
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
Gets the name of this species- Returns:
- the name of the species
-
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
-
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
-
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 inTBTreturn "2x2". This corresponds to the argument for the--moduleoption 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
-
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
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 traits.- 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 traits.- 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 injarfile. -
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
-
createIBSPop
Opportunity to supply custom individual based simulations.- Returns:
- the custom IBSPopulation or
nullto use default.
-
getVacant
public int getVacant()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
-
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
-
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
-
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 thannTraitscolors are specified, additional traits are colored using the default colors. If still not enough, random colors are generated. BothDiscreteandContinuousmodules require2*nTraitscolors. The meaning of the second set ofnTraitscolors depends on the trait 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:
truealways 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. 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
Opportunity for modules to make adjustments to the color map in graphs such asPop2DorPop3D. 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:
-
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
-
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:
-
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
Gets the mutation type.- Returns:
- the mutation type
-
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:
-