Class IBSDPopulation

Object
IBSPopulation
IBSDPopulation
Direct Known Subclasses:
CDL.IBSPop, NetGames.IBSPop, RSP.IBSPop, TBT.IBSPop

public class IBSDPopulation extends IBSPopulation
The core class for individual based simulations with discrete traits/strategies. Manages the strategies of the population, while delegating the management of the population and individual fitness as well as simulation steps to super.
Author:
Christoph Hauert
See Also:
  • Field Details Link icon

    • module Link icon

      protected Discrete module
      The discrete module associated with this model.

      Note: This deliberately hides IBSPopulation.module. The two variables point to the same object but this setup avoids unnecessary casts because only Discrete modules generate IBSDPopulation(s).

    • pairmodule Link icon

      protected IBS.HasIBS.DPairs pairmodule
      For pairwise interaction modules module==pairmodule holds and null otherwise. Convenience field to reduce the number of (unnecessary) casts.
      See Also:
    • groupmodule Link icon

      protected IBS.HasIBS.DGroups groupmodule
      For group interaction modules module==groupmodule holds and null otherwise. Convenience field to reduce the number of (unnecessary) casts.
      See Also:
    • opponent Link icon

      IBSDPopulation opponent
      The interaction partner/opponent of this population opponent.getModule()==getModule().getOpponent(). In intra-species interactions opponent==this. Convenience field.

      Note: This deliberately hides IBSPopulation.opponent. The two variables point to the same object but this setup avoids unnecessary casts because only Discrete modules generate IBSDPopulation(s).

    • optimizeMoran Link icon

      protected boolean optimizeMoran
      The flag to indicate whether optimizations of Moran processes are requested. true if optimizations for Moran process requested.

      Note: Link icon

      1. Optimizations are requested with the command line option --optimize (or -1), see IBSD.cloOptimize.
      2. Optimizations destroy the time line of events. Do not use if e.g. fixation times are of interest (but fine for fixation probabilities).
      3. Currently restricted to discrete strategies and structured populations, where Moran type processes can be optimized by skipping events involving individuals of the same type (see maybeMutateMoran(int, int)).
    • mutation Link icon

      protected Mutation.Discrete mutation
      The mutation parameters.
    • strategies Link icon

      public int[] strategies
      The array of individual strategies.
    • strategiesScratch Link icon

      protected int[] strategiesScratch
      The array for temporarily storing strategies during updates.
    • accuTypeScores Link icon

      protected double[] accuTypeScores
      The array with the total scores for each trait/strategic type.
    • strategiesTypeCount Link icon

      public int[] strategiesTypeCount
      The array with the total number of individuals of each trait/strategic type.
    • initTypeCount Link icon

      public int[] initTypeCount
      The array with the initial number of individuals of each trait/strategic type.
    • groupStrat Link icon

      private int[] groupStrat
      Temporary storage for strategies/traits of individuals in group interactions.
    • groupIdxs Link icon

      private int[] groupIdxs
      Temporary storage for indices of individuals in group interactions.
    • smallStrat Link icon

      private int[] smallStrat
      Temporary storage for strategies/traits of individuals in small sub-group interactions.
    • traitCount Link icon

      private int[] traitCount
      Temporary storage for the number of each strategy/type in group interactions.
    • traitScore Link icon

      private double[] traitScore
      Temporary storage for the scores of each strategy/type in group interactions.
    • traitTempScore Link icon

      private double[] traitTempScore
      Temporary storage for the scores of each strategy/type prior to the group interactions.
    • init Link icon

      protected IBSD.Init init
      Type of initial configuration.
      See Also:
  • Constructor Details Link icon

    • IBSDPopulation Link icon

      public IBSDPopulation(EvoLudo engine, Discrete module)
      Creates a population of individuals with discrete traits for IBS simulations.
      Parameters:
      engine - the pacemaker for running the model
      module - the module that defines the game
  • Method Details Link icon

    • setOpponentPop Link icon

      public void setOpponentPop(IBSPopulation opponent)
      Description copied from class: IBSPopulation
      Set the interaction partner/opponent of this population.
      Overrides:
      setOpponentPop in class IBSPopulation
      Parameters:
      opponent - the interaction partner/opponent
    • getPopulationSize Link icon

      public int getPopulationSize()
      Description copied from class: IBSPopulation
      Gets current population size. For most models with fixed population sizes this simply returns nPopulation. Ecological models with variable population sizes must override this method to return the actual population size.
      Overrides:
      getPopulationSize in class IBSPopulation
      Returns:
      current population size
    • reset Link icon

      public void reset()
      Reset the model. All parameters must be consistent at this point. Allocate memory and initialize the interaction and competition structures. If structures include random elements, e.g. random regular graphs, a new structure is generated. Generate initial configuration. Subclasses must override this method to allocate memory for the strategies and call super.

      Allocates memory for optimized Moran process.

      Discussions/extensions Link icon

      groupScores unused in IBSDPopulation. Merge with traitScore?
      Overrides:
      reset in class IBSPopulation
      See Also:
    • updatePlayerMoranBirthDeath Link icon

      public void updatePlayerMoranBirthDeath()
      Perform a single, Moran (Birth-death) update for a random individual selected with a probability proportional to fitness. This is the original Moran process where the offspring can replace the parent in well-mixed populations. For structured populations this corresponds to the spatial Moran process with Bd updating in Ohtsuki et al. Nature 2005.

      Optimized Moran process: a significant speed boost is achieved when restricting events along links that potentially result in an actual change of the population composition, i.e. by focussing on those links that connect individuals of different strategies/traits. This destroys the time scale.

      Overrides:
      updatePlayerMoranBirthDeath in class IBSPopulation
      See Also:
    • updatePlayerMoranImitate Link icon

      public void updatePlayerMoranImitate()
      Description copied from class: IBSPopulation
      Perform a single, Moran (imitate) update for a site selected uniformly at random. This corresponds to the imitate strategy in Ohtsuki et al. Nature 2005.
      Overrides:
      updatePlayerMoranImitate in class IBSPopulation
      See Also:
    • updatePlayerMoranDeathBirth Link icon

      public void updatePlayerMoranDeathBirth()
      Description copied from class: IBSPopulation
      Perform a single Moran (death-Birth) update for a site selected uniformly at random. This corresponds to the spatial Moran process with dB updating in Ohtsuki et al. Nature 2005.
      Overrides:
      updatePlayerMoranDeathBirth in class IBSPopulation
      See Also:
    • updatePlayerMoranDeathBirth Link icon

      protected void updatePlayerMoranDeathBirth(boolean withSelf)
      The optimized Moran process for death-Birth and imitation updatating. A significant speed boost is achieved when restricting events along links that potentially result in an actual change of the population composition, i.e. by focussing on those links that connect individuals of different strategies/traits. This destroys the time scale.
      Parameters:
      withSelf - the flag to indicate whether to include to focal individual
      See Also:
    • updatePlayerEcologyAt Link icon

      protected double updatePlayerEcologyAt(int me)
      Perform a single ecological update of the individual with index me:
      1. Focal individual dies with probability proportional to the death rate.
      2. Otherwise, draw a random neighbour and, if unoccupied, place clonal offspring on neighboring site with probability proportional to fitness.
      Overrides:
      updatePlayerEcologyAt in class IBSPopulation
      Parameters:
      me - the index of the focal individual
      Returns:
      time increment
    • updateFromModelAt Link icon

      public void updateFromModelAt(int index, int modelPlayer)
      Description copied from class: IBSPopulation
      Update individual with index me and adopt the strategy of individual with index you.

      Note: method must be subclassed to deal with different data types of strategies but should also include a call to super.

      Overrides:
      updateFromModelAt in class IBSPopulation
      Parameters:
      index - the index of the focal individual
      modelPlayer - the index of the model individual to adopt strategy from
      See Also:
    • mutateAt Link icon

      public double mutateAt(int focal)
      Description copied from class: IBSPopulation
      Mutate the strategy of the focal individual with index focal. The mutated strategy is committed and the scores updated.
      Specified by:
      mutateAt in class IBSPopulation
      Parameters:
      focal - the index of the focal individual
      Returns:
      the elapsed time in realtime units
    • maybeMutateAt Link icon

      protected boolean maybeMutateAt(int focal, boolean switched)
      Description copied from class: IBSPopulation
      Consider mutating the trait of the focal individual with index focal. The strategy of the focal individual is stored in the array strategies unless the focal individual switched strategy. In that case the current strategy is stored in the array strategyScratch.

      Important: The trait is not committed regardless of whether a mutation occurred.

      Specified by:
      maybeMutateAt in class IBSPopulation
      Parameters:
      focal - the index of the focal individual
      switched - true if the focal individual switched strategy
      Returns:
      true if the trait of the focal individual changed
    • maybeMutateMoran Link icon

      protected void maybeMutateMoran(int source, int dest)
      Description copied from class: IBSPopulation
      Consider mutating the trait of the parent individual with index source. The mutated strategy is committed and the scores updated.
      Specified by:
      maybeMutateMoran in class IBSPopulation
      Parameters:
      source - the index of the parent individual
      dest - the index of the location for the offspring placement
    • debugMarkChange Link icon

      protected void debugMarkChange()
      Description copied from class: IBSPopulation
      Override in subclass for example to mark those individuals in the GUI that were involved in the debug step.
      Overrides:
      debugMarkChange in class IBSPopulation
    • haveSameStrategy Link icon

      public boolean haveSameStrategy(int a, int b)
      Description copied from class: IBSPopulation
      Check if individuals with index a and index b have the same strategies.
      Specified by:
      haveSameStrategy in class IBSPopulation
      Parameters:
      a - the index of first individual
      b - the index of second individual
      Returns:
      true if the two individuals have the same strategies
    • isSameStrategy Link icon

      public boolean isSameStrategy(int a)
      Description copied from class: IBSPopulation
      Check if individual with index a has switched strategies.

      Note: this test is only meaningful before strategy gets committed.

      Specified by:
      isSameStrategy in class IBSPopulation
      Parameters:
      a - index of individual
      Returns:
      true if strategy remained the same
      See Also:
    • swapStrategies Link icon

      public void swapStrategies(int a, int b)
      Description copied from class: IBSPopulation
      Swap strategies of individuals with index a and index b.

      Note: the strategies still need to be committed.

      Specified by:
      swapStrategies in class IBSPopulation
      Parameters:
      a - the index of first individual
      b - the index of second individual
      See Also:
    • updateScoreAt Link icon

      public void updateScoreAt(int index, double newscore, int incr)
      Description copied from class: IBSPopulation
      Update the score of the individual with index index by adding (incr > 0 or removing, incr < 0) newscore as the result of incr interactions.

      Important: Link icon

      1. Strategies are already committed when adding scores (incr>0).
      2. Strategies are not committed when removing scores (incr<0).
      3. This routine is never called for the focal site (i.e. the one that may have changed strategy and hence where it matters whether strategies are committed).
      4. IBSPopulation.resetScoreAt(int) deals with the focal site.
      Overrides:
      updateScoreAt in class IBSPopulation
      Parameters:
      index - the index of the individual
      newscore - score/payoff to add (incr>0) or subtract (incr<0)
      incr - number of interactions
    • setScoreAt Link icon

      public void setScoreAt(int index, double newscore, int inter)
      Description copied from class: IBSPopulation
      Sets the score of individual with index index to newscore as the result of inter interactions. Also derives the corresponding fitness and adjusts sumFitness.

      Note: Assumes that IBSPopulation.resetScores() was called earlier (or at least IBSPopulation.resetScoreAt(int) for those sites that setScoreAt(int) is used for updating their score).

      Overrides:
      setScoreAt in class IBSPopulation
      Parameters:
      index - the index of the individual
      newscore - new score to set
      inter - number of interactions
    • getScoreAt Link icon

      public double getScoreAt(int idx)
      Description copied from class: IBSPopulation
      Gets the score of the individual with index idx.
      Overrides:
      getScoreAt in class IBSPopulation
      Parameters:
      idx - the index of the individual
      Returns:
      the score of the individual
    • getFitnessAt Link icon

      public double getFitnessAt(int idx)
      Description copied from class: IBSPopulation
      Gets the fitness of the individual with index idx.
      Overrides:
      getFitnessAt in class IBSPopulation
      Parameters:
      idx - the index of the individual
      Returns:
      the fitness of the individual
    • resetScoreAt Link icon

      public void resetScoreAt(int index)
      Description copied from class: IBSPopulation
      Reset score of individual at index index.

      Important: Strategies must not yet have been committed.

      Discussions/extensions: Link icon

      Revise the entire strategy updating procedure: it's inefficient to first reset scores then update strategies then update score...
      Overrides:
      resetScoreAt in class IBSPopulation
      Parameters:
      index - the index of the individual
    • resetScores Link icon

      public void resetScores()
      Description copied from class: IBSPopulation
      Reset scores and fitness of all individuals to zero.
      Overrides:
      resetScores in class IBSPopulation
    • updateScores Link icon

      public void updateScores()
      Update the scores of all individuals in the population.

      Note: Overridden to set scores in well-mixed populations more efficiently.

      Overrides:
      updateScores in class IBSPopulation
    • updatePlayerBestResponse Link icon

      public boolean updatePlayerBestResponse(int me, int[] group, int size)
      Best-response update.

      Important: Link icon

      1. The array group is untouchable because it may refer to the population structure. Any change would also permanently change the structure.
      2. The best-response update must be implemented in subclasses that override this method. By default throws an error.
      3. Instead of overriding the method, subclasses may remove PlayerUpdate.Type.BEST_RESPONSE from PlayerUpdate#clo.

      Note: Takes composition of entire population into account for Geometry.Type#MEANFIELD but only the reference neighborhood in structured populations.

      Overrides:
      updatePlayerBestResponse in class IBSPopulation
      Parameters:
      me - the index of individual to update
      group - the array with indices of reference group
      size - the size of the reference group
      Returns:
      true if strategy changed (signaling score needs to be reset)
    • preferredPlayerBest Link icon

      public boolean preferredPlayerBest(int me, int best, int sample)
      For deterministic updating with multiple strategies (more than two), it must be specified which strategy is the preferred one.

      Summary: does 'me' prefer 'sample' over 'best'?

      Here we introduce the convention of a cyclic preference where strategies with lower indices are always preferred. For example, with N strategic types, strategy 0 preferred over 1 preferred over 2 ... preferred over N-1 preferred over N preferred over 0, etc. This convention is arbitrary but seems to make sense for systems with cyclic dominance of strategies and such systems are most likely to produce evolutionary kaleidoscopes and only for those is this deterministic updating of crucial importance. For anything else, these are irrelevant quibbles.

      Specified by:
      preferredPlayerBest in class IBSPopulation
      Parameters:
      me - the index of the focal individual
      best - the index of the best performing individual
      sample - the index of the sample type
      Returns:
      true if sample is preferred over best
    • stripGroupVacancies Link icon

      protected void stripGroupVacancies(IBSGroup group, int[] gStrat, int[] gIdxs)
      Eliminate vacant sites from the assembled group.

      Important: group.group is untouchable! It may be a reference to Geometry.out[group.focal] and hence any changes would actually alter the geometry!

      Parameters:
      group - the group which potentially includes references to vacant sites
      gStrat - the array of strategies in the group
      gIdxs - the array of indices of the individuals in the group
    • stripVacancies Link icon

      protected int stripVacancies(int[] groupidx, int groupsize, int[] gStrat, int[] gIdxs)
      Process traits/strategic types while excluding vacant sites.
      Parameters:
      groupidx - the array of indices of the individuals in the group
      groupsize - the size of the group
      gStrat - the array to store/return the traits/strategic types
      gIdxs - the array to store/return the pruned indexes
      Returns:
      the size of the interaction group after pruning
    • playPairGameAt Link icon

      public void playPairGameAt(IBSGroup group)
      Description copied from class: IBSPopulation
      Play a pairwise interaction with the individuals in group.
      Specified by:
      playPairGameAt in class IBSPopulation
      Parameters:
      group - the group of individuals interacting in pairs
    • adjustScoreAt Link icon

      public void adjustScoreAt(int index, double before, double after)
      Description copied from class: IBSPopulation
      Adjust score of individual with index index from before to after and update all applicable helper variables, e.g. sumFitness.

      Important: Use only to adjust scores of individuals that did not change strategy.

      Specified by:
      adjustScoreAt in class IBSPopulation
      Parameters:
      index - the index of the individual
      before - the score before adjustments
      after - the score after adjustments
    • adjustScoreAt Link icon

      public void adjustScoreAt(int index, double adjust)
      Description copied from class: IBSPopulation
      Adjust score of individual with index index by adjust and update all applicable helper variables, e.g. sumFitness.
      Specified by:
      adjustScoreAt in class IBSPopulation
      Parameters:
      index - the index of the individual
      adjust - the score adjustment
    • adjustPairGameScoresAt Link icon

      public void adjustPairGameScoresAt(int me)
      Description copied from class: IBSPopulation
      Adjusts scores of focal individual with index me and its neighbors after me changed strategy. Only works if adjustScores==true.

      Important: new strategy must not yet have been committed.

      Specified by:
      adjustPairGameScoresAt in class IBSPopulation
      Parameters:
      me - the index of the focal individual
    • playGroupGameAt Link icon

      public void playGroupGameAt(IBSGroup group)
      Description copied from class: IBSPopulation
      Play a group interaction with the individuals in group.
      Specified by:
      playGroupGameAt in class IBSPopulation
      Parameters:
      group - the group of interacting individuals
    • yalpGroupGameAt Link icon

      public void yalpGroupGameAt(IBSGroup group)
      Description copied from class: IBSPopulation
      Counterpart of IBSPopulation.playGroupGameAt(IBSGroup), IBSPopulation.playGameAt(int) and/or IBSPopulation.playGameSyncAt(int). Removes the payoffs of group interactions.
      Specified by:
      yalpGroupGameAt in class IBSPopulation
      Parameters:
      group - the interaction group
    • adjustGameScoresAt Link icon

      public void adjustGameScoresAt(int me)
      Adjust scores of focal player me and its neighbours (interaction partners).

      Requirements/notes: Link icon

      1. This optimized method is only applicable if IBSGroup.SamplingType.ALL is true and not Geometry.Type.MEANFIELD, i.e. if the interaction group includes all neighbors but not all other members of the population.
      2. For pairwise interactions more efficient approaches are possible but those require direct access to the stratgies and are hence delegated to subclasses.

      Overridden to allow for adjusting scores in well-mixed populations.

      Overrides:
      adjustGameScoresAt in class IBSPopulation
      Parameters:
      me - the index of the focal individual
      See Also:
    • updateMixedMeanScores Link icon

      protected void updateMixedMeanScores()
      Calculate scores in well-mixed populations as well as hierarchical structures with well-mixed units.
    • countTraits Link icon

      public void countTraits(int[] counts, int[] traits, int offset, int len)
      Count the number of each trait in the array traits starting at offset for len individuals. The result is stored in counts.

      Note: offset is convenient for hierarchical structures and prevents copying parts of the strategies array.

      Parameters:
      counts - the array to return the number of individuals with each trait/strategy
      traits - the array with the strategies/traits of he individuals
      offset - the offset into the array traits to start counting
      len - the number of individuals to count
    • resetStrategies Link icon

      public void resetStrategies()
      Reset all strategies in preparation of the next update step. Simply an opportunity for customizations in subclasses.

      Reset the colors of recently changed strategies.

      Overrides:
      resetStrategies in class IBSPopulation
    • prepareStrategies Link icon

      public void prepareStrategies()
      Description copied from class: IBSPopulation
      Prior to a synchronous update step the current state must be duplicated in preparation for processing the next step.
      Specified by:
      prepareStrategies in class IBSPopulation
      See Also:
    • commitStrategies Link icon

      public void commitStrategies()
      After a synchronous update step the new state must be copied back to become the current state.

      For discrete modules, update the strategy count of each type and check if population reached a homogeneous state.

      Specified by:
      commitStrategies in class IBSPopulation
      See Also:
    • updateStrategiesTypeCount Link icon

      public void updateStrategiesTypeCount()
      Update the count of each trait/strategic type.
      See Also:
    • getStrategiesTypeCount Link icon

      public int[] getStrategiesTypeCount()
      Gets the count of each trait/strategic type.
      Returns:
      count of each trait/strategic type
    • isConsistent Link icon

      public void isConsistent()
      Description copied from class: IBSPopulation
      Convenience method during development to perform a number of consistency checks of the current state. Once an inconsistency is found there is no need to keep looking and no further checks are performed.

      Execution time is of little concern here. Never use in the final simulation code.

      Overrides:
      isConsistent in class IBSPopulation
    • isMonomorphic Link icon

      public boolean isMonomorphic()
      Description copied from class: IBSPopulation
      Check if population is monomorphic.

      Note: In models that admit vacant sites this does not imply a homogeneous (or absorbing) state of the population. Without vacant sites monomorphic states are absorbing, at least in the absence of mutations.

      Overrides:
      isMonomorphic in class IBSPopulation
      Returns:
      true if population is monomorphic
      See Also:
    • checkConvergence Link icon

      public boolean checkConvergence()
      Description copied from class: IBSPopulation
      Check if population has converged. By default true if population is monomorphic and no (zero) mutations. However, different implementations may have different criteria for convergence.

      Note: This tends to be less restrictive than reaching an absorbing state. Typically convergence is used as a criterion to abort simulations.

      Specified by:
      checkConvergence in class IBSPopulation
      Returns:
      true if converged.
    • isVacantAt Link icon

      public boolean isVacantAt(int index)
      Description copied from class: IBSPopulation
      Check if site with index index is occupied by an individual or vacant.

      Note: Assumes that strategies are committed.

      Overrides:
      isVacantAt in class IBSPopulation
      Parameters:
      index - the index of the individual/site to check
      Returns:
      true if site index is vacant
    • becomesVacantAt Link icon

      public boolean becomesVacantAt(int index)
      Description copied from class: IBSPopulation
      Check if site with index index will become vacant in this time step.

      Note: Assumes that strategies are not committed.

      Overrides:
      becomesVacantAt in class IBSPopulation
      Parameters:
      index - the index of the individual/site to check
      Returns:
      true if site index will become vacant
    • commitStrategyAt Link icon

      public void commitStrategyAt(int me)
      Description copied from class: IBSPopulation
      The change of a strategy of the player at index is stored in a temporary variable and must be committed before proceeding.
      Specified by:
      commitStrategyAt in class IBSPopulation
      Parameters:
      me - the index of the player that needs to have its new strategy committed
    • getMonoScore Link icon

      public double getMonoScore(int type)
      Gets the score of individuals in a population that is monomorphic in trait type.
      Parameters:
      type - the trait type
      Returns:
      the monomorphic score
    • getFitnessHistogramData Link icon

      public void getFitnessHistogramData(double[][] bins)
      Description copied from class: IBSPopulation
      Generates a histogram of the fitness distribution in this population. The result is returned in the array bins.

      Notes: Link icon

      1. bins is a 2D array because discrete models generate histograms for each trait separately.
      2. By default generate a histogram of the scores in bins[0].
      3. Consider moving to IBSDPopulation and IBSCPopulation with arguments bins[][] and bins[], respectively.
      Overrides:
      getFitnessHistogramData in class IBSPopulation
      Parameters:
      bins - the 2D array to store the histogram(s)
    • setInitialTraits Link icon

      public boolean setInitialTraits(double[] init)
      Set the initial trait frequencies in the population. Switches the initialization type to IBSD.Init.Type.FREQUENCY.
      Parameters:
      init - the initial traits
      Returns:
      true if the initialization was successful
    • getInitialTraits Link icon

      public void getInitialTraits(double[] traits)
      Description copied from class: IBSPopulation
      Returns the initial trait(s) of this population in the array init. Used by GUI to visualize the initial state of this IBS model.
      Specified by:
      getInitialTraits in class IBSPopulation
      Parameters:
      traits - the array for returning the initial trait values
      See Also:
    • getMeanTraits Link icon

      public void getMeanTraits(double[] mean)
      Description copied from class: IBSPopulation
      Returns the mean trait(s) of this population in the array mean. Used by GUI to visualize the current state of this IBS model.
      Specified by:
      getMeanTraits in class IBSPopulation
      Parameters:
      mean - the array for returning the trait values
      See Also:
    • getTraitData Link icon

      public <T> void getTraitData(T[] colors, ColorMap<T> colorMap)
      Description copied from class: IBSPopulation
      Returns the traits of all individuals in this population coded as colors in the array colors using the map colorMap. Used by GUI to visualize the current state of this IBS model. Colors are coded in different data types <T> depending on the runtime environment (GWT or JRE) as well as the graph (e.g. PopGraph2D or PopGraph3D).
      Specified by:
      getTraitData in class IBSPopulation
      Type Parameters:
      T - the type of color data (String or MeshLambertMaterial for GWT and Color for JRE).
      Parameters:
      colors - the array where the colors of all nodes are stored
      colorMap - the map that converts traits into colors
    • getMeanFitness Link icon

      public void getMeanFitness(double[] mean)
      Description copied from class: IBSPopulation
      Returns the mean fitness of this population in the array mean. Used by GUI to visualize the current state of this IBS model. Returns true if data point belongs to the same time series and false if a new series was started through IBSPopulation.init() or IBSPopulation.reset().
      Specified by:
      getMeanFitness in class IBSPopulation
      Parameters:
      mean - the array for storing the mean fitness values
      See Also:
    • getTraits Link icon

      public String getTraits()
      Gets the traits of all individuals as indices. Those with indices in [0, nTraits) denote individuals that have not changed strategy since the previous report, while those in [nTraits, 2*nTraits) have.
      Returns:
      the traits
    • getTraitNameAt Link icon

      public String getTraitNameAt(int idx)
      Description copied from class: IBSPopulation
      Gets the formatted name of the trait of the individual at site index.
      Specified by:
      getTraitNameAt in class IBSPopulation
      Parameters:
      idx - the index of the
      Returns:
      the string describing the trait
    • getStatus Link icon

      public String getStatus()
      Description copied from class: IBSPopulation
      Gets the status of the as a formatted string. This is typically used in the GUI to summarize the progress of the model.
      Specified by:
      getStatus in class IBSPopulation
      Returns:
      the status of the population
    • check Link icon

      public boolean check()
      Description copied from class: IBSPopulation
      Check all model parameters for consistency and adjust if necessary (and feasible). Returns true if adjustments require a reset. Free memory if possible and request a reset if new memory needs to be allocated.
      Overrides:
      check in class IBSPopulation
      Returns:
      true if reset is required
      See Also:
    • doAdjustScores Link icon

      protected boolean doAdjustScores()
      Description copied from class: IBSPopulation
      Check if scores can be adjusted rather than recalculated after an individual changed its strategy. This requires that individuals interact with all their neighbours and that the structure of the population is not well-mixed. Some implementations may be able to extend adjustments to other structures. For example, adjusting scores is feasible in well-mixed populations for discrete traits/strategies.

      Requirements: Link icon

      Group.SAMPLING_ALL
      individuals need to be interacting with all their neighbours (not just a randomly selected subset).
      Geometry.MEANFIELD
      interactions with everyone are not feasible (impossible to model efficiently), in general, for unstructured populations (subclasses can do better, e.g. for discrete strategies it is possible, see doAdjustScores()).
      playerScoreReset
      if scores are reset whenever an individual adopts the strategy of another (regardless of whether an actual strategy change occurred) then the expected number of interactions of each individual remains constant over time (even though the interaction count may differ for individuals on heterogeneous structures).
      Specified by:
      doAdjustScores in class IBSPopulation
      Returns:
      true if adjusting scores is feasible
      See Also:
    • init Link icon

      public void init()
      Description copied from class: IBSPopulation
      Initialize the model. All parameters must be consistent. Subclasses must override this method to generate the initial strategy configuration and call super.

      Note: Initialization leaves the interaction and competition structures untouched

      Overrides:
      init in class IBSPopulation
      See Also:
    • initUniform Link icon

      protected void initUniform()
      Initial configuration with uniform strategy frequencies of all active strategies.
      See Also:
    • initFrequency Link icon

      protected void initFrequency()
      Initial configuration with strategy frequencies as specified in arguments.
      See Also:
    • initMono Link icon

      protected void initMono()
      Monomorphic initial configuration with specified trait (and frequency in modules that allow empty sites).
      See Also:
    • estimateVacantFrequency Link icon

      private double estimateVacantFrequency(int type)
      Helper method to determine the frequency of vacant sites based on an estimate of the carrying capacity. In well-mixed populations this is 1d/r, where d is the death rate and r the fitness of the resident type. Similarly, on regular graphs the carrying capacity is 1(k1)d/(r(k1)d), where k is the degree of the graph. Finally, on generic structures, the estimate of the carrying capacity is based on the average out-degree of all nodes.

      Note: residents in structured populations additionally have a characteristic distribution, which is not accounted for in this estimate.

      Parameters:
      type - the resident type
      Returns:
      the estimated frequency of vacant sites
    • initMono Link icon

      private void initMono(int monoType, double monoFreq)
      Helper method for initializing monomorphic populations. If the module admits vacant sites the frequency of individuals with the monomorphic trait is set to monoFreq.
      Parameters:
      monoType - the monomorphic trait
      monoFreq - the frequency of the monomorphic trait
    • initMutant Link icon

      protected int initMutant()
      Monomorphic initial configuration with a single mutant placed in a location chosen uniformly at random (uniform initialization, cosmic rays).
      Returns:
      the location of the mutant
      See Also:
    • initTemperature Link icon

      protected int initTemperature()
      Monomorphic initial configuration with a single mutant placed in a random location chosen with probability proprtional to the number of incoming links (temperature initialization, errors in reproduction).
      Returns:
      the location of the mutant
      See Also:
    • initKaleidoscope Link icon

      protected void initKaleidoscope()
      Initial configuration that generates evolutionary kaleidoscopes for deterministic update rules. Whether this is possible and and what kind of initial configurations are required depends on the module. Hence this method must be overriden in subclasses that admit kaleidoscopes.

      Note: requires the explicit adding of the key IBSD.Init.Type.KALEIDOSCOPE for IBS models. For example, add

       if (model instanceof IBSD) {
              CLOption clo = ((IBSDPopulation) getIBSPopulation()).getInit().clo;
              clo.addKey(Init.Type.KALEIDOSCOPE);
       }
       
      to org.evoludo.simulator.modules.Module#adjustCLO(org.evoludo.util.CLOParser).
      See Also:
    • initStripes Link icon

      protected void initStripes()
      Initial configuration with monomorphic stripes of each type to investigate invasion properties of one strategy into another with at least one instance of all possible pairings.
      See Also:
    • fillStripe Link icon

      private void fillStripe(int offset, int width, int trait)
      Helper method to initialize lattice structures with homogeneous stripes of each trait/strategic type.
      Parameters:
      offset - the offset to the start of the stripe
      width - the width of the stripe
      trait - the trait/stratgy of the stripe
      See Also:
    • sum Link icon

      private int sum(int start, int end)
      Helper method to determine the number of stripes required so that each trait/strategic type shares at least one interface with every other trait: nStripes = nTraits + 2 * sum(2, nTraits - 2). Procedure tested for 2, 3, 4, 5 traits.
      Parameters:
      start - the starting trait
      end - the end trait
      Returns:
      the number of traits
    • setInit Link icon

      public void setInit(IBSD.Init init)
      Sets the type of the initial configuration and any accompanying arguments. If either type or args are null the respective current setting is preserved.
      Parameters:
      init - the type and arguments of the initial configuration
    • getInit Link icon

      public IBSD.Init getInit()
      Gets the type of the initial configuration and its arguments.
      Returns:
      the type and arguments of the initial configuration
    • mouseHitNode Link icon

      public boolean mouseHitNode(int hit, boolean alt)
      Description copied from class: IBSPopulation
      Called from GUI if node/individual with index idx received a mouse click or tap and indicates whether the alt-key had been pressed.
      Overrides:
      mouseHitNode in class IBSPopulation
      Parameters:
      hit - the index of the node
      alt - true if the alt-key was pressed
      Returns:
      false if no actions taken
    • mouseSetHit Link icon

      private boolean mouseSetHit(int hit, int strategy)
      Process event from GUI: individual with index hit was hit by mouse (or tap) in order to set its strategy to strategy.
      Parameters:
      hit - the index of the individual that was hit by mouse or tap
      strategy - the new strategy of the individual
      Returns:
      false if no actions taken (should not happen)
    • restoreFitness Link icon

      public boolean restoreFitness(Plist plist)
      Restore the fitness of all individuals encoded in the plist inspired map of key, value-pairs.

      Important: Strategies must already be restored!

      Overrides:
      restoreFitness in class IBSPopulation
      Parameters:
      plist - the map of key, value-pairs
      Returns:
      true if successful
      See Also:
    • encodeStrategies Link icon

      public void encodeStrategies(StringBuilder plist)
      Description copied from class: IBSPopulation
      Encode the strategies of all individuals in the IBS model in a plist inspired XML string.
      Specified by:
      encodeStrategies in class IBSPopulation
      Parameters:
      plist - the StringBuilder to write the encoded state to
      See Also:
    • restoreStrategies Link icon

      public boolean restoreStrategies(Plist plist)
      Description copied from class: IBSPopulation
      Restore the strategies of all individuals encoded in the plist inspired map of key, value-pairs.
      Specified by:
      restoreStrategies in class IBSPopulation
      Parameters:
      plist - the map of key, value-pairs
      Returns:
      true if successful
      See Also: