Class Continuous

Object
Module
Continuous
All Implemented Interfaces:
Runnable, MilestoneListener, Features, CLOProvider
Direct Known Subclasses:
CLabour, CSD

public abstract class Continuous extends Module
Parent class of all EvoLudo modules with one or more continuous traits.
Author:
Christoph Hauert
  • Field Details

    • species

      The list species contains references to each species in this module. It deliberately shadows Module.species to simplify bookkeeping. During instantiation Module.species and species are linked to represent one and the same list.

      IMPORTANT: currently continuous models support only a single species.

      See Also:
    • population

      Continuous population
      Shortcut for species.get(0) as long as continuous modules are restricted to a single species.
    • extremalScoresSet

      protected boolean extremalScoresSet
      The flag that indicates whether maximal and minimal scores have already been calculated.
      See Also:
    • traitMin

      protected double[] traitMin
      The trait minima.

      Note: internally traits are always in \([0,1]\). traitMin and traitMax are used to transform traits appropriately for results.

    • traitMax

      protected double[] traitMax
      The trait maxima.

      Note: internally traits are always in \([0,1]\). traitMin and traitMax are used to transform traits appropriately for results.

    • mutation

      protected Mutation.Continuous mutation
      The mutation operator for continuous traits.
    • traits2payoff

      protected Continuous.Traits2Payoff traits2payoff
      The map to translate traits of interacting individuals into payoffs.
    • cloTraitRange

      public final CLOption cloTraitRange
      Command line option to set the minimum value of each trait.
    • cloCosts

      public final CLOption cloCosts
      Command line option to set the cost function(s) for continuous traits.
      See Also:
    • cloBenefits

      public final CLOption cloBenefits
      Command line option to set the benefit function(s) for continuous traits.
      See Also:
    • cxMinScore

      protected double cxMinScore
      The absolute minimum score.
    • cxMaxScore

      protected double cxMaxScore
      The absolute maximum score.
    • cxMinMonoScore

      protected double cxMinMonoScore
      The minimum score in a monomorphic population.
    • cxMaxMonoScore

      protected double cxMaxMonoScore
      The maximum score in a monomorphic population.
    • MINMAX_STEPS

      static final int MINMAX_STEPS
      The linear grid size to sample payoffs in the (possibly multi-dimensional) trait space.
      See Also:
    • MINMAX_ITER

      static final int MINMAX_ITER
      The number of iterations for the hill climbing process.
      See Also:
  • Constructor Details

    • Continuous

      protected Continuous(EvoLudo engine)
      Create new module with continuous traits.
      Parameters:
      engine - the pacemaker for running the model
    • Continuous

      protected Continuous(Continuous partner)
      Create another module with continuous traits. The additional module represents another species in multi-species modules that interact with species partner.
      Parameters:
      partner - the partner species
    • Continuous

      protected Continuous(EvoLudo engine, Continuous partner)
      Create a new module with continuous traits for pacemaker engine and interactions with module partner. If partner == null this is a single species module and interactions within species (opponent == this holds).
      Parameters:
      engine - the pacemaker for running the model
      partner - the partner species
  • Method Details

    • getMutation

      public Mutation.Continuous getMutation()
      Description copied from class: Module
      Gets the mutation type.
      Specified by:
      getMutation in class Module
      Returns:
      the mutation type
    • add

      public boolean add(Continuous cpop)
      Add cpop to list of species. Duplicate entries are ignored. Allocate new list if necessary. Assign generic name to species if none provided.
      Parameters:
      cpop - the module to add to species list.
      Returns:
      true if dpop successfully added; false adding failed or already included in list.
    • load

      public void load()
      Description copied from class: Module
      Load new module and perform basic initializations.
      Overrides:
      load in class Module
      See Also:
    • unload

      public void unload()
      Description copied from class: Module
      Unload module and free all resources.
      Overrides:
      unload in class Module
      See Also:
    • check

      public boolean check()
      Description copied from class: Module
      Check all parameters. After this call all parameters must be consistent. If parameter adjustments require a reset then this method must return true.

      Note: All parameter changes that don't require a reset can be made on the fly, in particular also while a model is running.

      Overrides:
      check in class Module
      Returns:
      true to trigger reset
      See Also:
    • getMinGameScore

      public 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.
      Specified by:
      getMinGameScore in class Module
      Returns:
      the minimum payoff/score
      See Also:
    • getMaxGameScore

      public 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.
      Specified by:
      getMaxGameScore in class Module
      Returns:
      the maximum payoff/score
      See Also:
    • getMinMonoGameScore

      public double getMinMonoGameScore()
      Calculates and returns the minimum payoff/score of individuals in monomorphic populations.
      Specified by:
      getMinMonoGameScore in class Module
      Returns:
      the minimum payoff/score in monomorphic populations
      See Also:
    • getMaxMonoGameScore

      public double getMaxMonoGameScore()
      Calculates and returns the maximum payoff/score of individuals in monomorphic populations.
      Specified by:
      getMaxMonoGameScore in class Module
      Returns:
      the maximum payoff/score in monomorphic populations
      See Also:
    • getTraitMin

      public double[] getTraitMin()
      Get the minima for all traits.
      Returns:
      the array with the trait minima
    • getTraitMax

      public double[] getTraitMax()
      Get the maxima for all traits.
      Returns:
      the array with the trait maxima
    • setTraitRange

      public void setTraitRange(double min, double max, int trait)
      Set the trait minimum and maximum for trait trait.
      Parameters:
      min - the trait minimum
      max - the trait maximum
      trait - the index of the trait
    • collectCLO

      public void collectCLO(CLOParser parser)
      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, the parser issues a warning and ignores the option. Thus, in general, implementing subclasses should first register their options and call super.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 interface CLOProvider
      Overrides:
      collectCLO in class Module
      Parameters:
      parser - the reference to parser that manages command line options
      See Also:
    • setExtremalScores

      protected void setExtremalScores()
      Helper method to numerically determine the minimum and maximum scores in the game through a brute force hill climbing algorithm for two competing traits as well as monomorphic populations.
    • findExtremalScore

      private double findExtremalScore(boolean maximum)
      Helper method to determine the minimum or maximum payoff.

      Implementation notes:

      Repeatedly calls findExtrema(double[], double[], int[], int[], double[][], double[][], double[], double[], int[], int[], double, int, double) with the most promising interval in each trait for residents and mutants, respectively. The hill climbing process stops after #MINMAX_ITER iterations.
      Parameters:
      maximum - if true the maximum is returned and the minimum otherwise
      Returns:
      the minimum or maximum payoff
    • findExtrema

      private double findExtrema(double[] resTrait, double[] mutTrait, int[] resIdx, int[] mutIdx, double[][] resInterval, double[][] mutInterval, double[] resScale, double[] mutScale, int[] resMax, int[] mutMax, double scoreMax, int trait, double minmax)
      Helper method to find the minimum or maximum payoff.

      Implementation notes:

      The function returns the maximum payoff after discretizing each trait of both the resident and the mutant into MINMAX_STEPS intervals. The function is recursively called for each trait. The indices of the cell (discretized trait interval) that yields the maximum payoff are returned in the arrays resMax and mutMax for residents and mutants respectively. This provides the starting point for the next iteration of the hill climber process.
      Parameters:
      resTrait - the array of resident traits (helper variable for recursive calculations)
      mutTrait - the array of mutant traits (helper variable for recursive calculations)
      resIdx - the index of the resident trait (helper variable for recursive calculations)
      mutIdx - the index of the mutant trait (helper variable for recursive calculations)
      resInterval - the resident trait intervals for discretization
      mutInterval - the mutant trait intervals for discretization
      resScale - the scaling of the width of the resident trait interval
      mutScale - the scaling of the width of the mutant trait interval
      resMax - the indices of the discretized cell for the resident that yielded the highest payoff
      mutMax - the indices of the discretized cell for the mutant that yielded the highest payoff
      scoreMax - the maximum payoff
      trait - the current trait for the recursion (helper variable for recursive calculations)
      minmax - 1.0 to calculate maximum and -1.0 to calculate minimum
      Returns:
      the minimum or maximum score
    • findExtremalMonoScore

      private double findExtremalMonoScore(boolean maximum)
      Helper method to find the minimum or maximum payoff for monomorphic populations.

      Implementation notes:

      This is essentially the same but simplified hill climber process in findExtremalScore(boolean) under the constraint that the population is monomorphic, i.e. that the resident and mutant traits are identical.
      Parameters:
      maximum - if true the maximum is returned and the minimum otherwise
      Returns:
      the minimum or maximum monomorphic score
    • findExtrema

      private double findExtrema(double[] resTrait, int[] resIdx, double[][] resInterval, double[] resScale, int[] resMax, double scoreMax, int trait, double minmax)
      Helper method to find the minimum or maximum payoff for monomorphic populations.

      Implementation notes:

      This is essentially the same but simplified hill climber process in findExtrema(double[], double[], int[], int[], double[][], double[][], double[], double[], int[], int[], double, int, double) under the constraint that the population is monomorphic, i.e. that the resident and mutant traits are identical.
      Parameters:
      resTrait - the array of resident traits (helper variable for recursive calculations)
      resIdx - the index of the resident trait (helper variable for recursive calculations)
      resInterval - the resident trait intervals for discretization
      resScale - the scaling of the width of the resident trait interval
      resMax - the indices of the discretized cell for the resident that yielded the highest payoff
      scoreMax - the maximum payoff
      trait - the current trait for the recursion (helper variable for recursive calculations)
      minmax - 1.0 to calculate maximum and -1.0 to calculate minimum
      Returns:
      the minimum or maximum monomorphic score