Class HierarchicalGeometry


public class HierarchicalGeometry extends AbstractLattice
Hierarchical meta-population structure implementation. Embeds well-mixed or square-lattice demes into recursive layers.
  • Field Details

    • subType

      private GeometryType subType
      The geometry of each hierarchical level.
    • hierarchy

      private int[] hierarchy
      The number of units at each hierarchical level.
    • hierarchyWeight

      private double hierarchyWeight
      Coupling strength between hierarchical levels.
  • Constructor Details

    • HierarchicalGeometry

      public HierarchicalGeometry(EvoLudo engine)
      Create a hierarchical geometry tied to the given engine.
      Parameters:
      engine - EvoLudo pacemaker
  • Method Details

    • parse

      boolean parse(String spec)
      Description copied from class: AbstractGeometry
      Parse geometry-specific CLI options.
      Overrides:
      parse in class AbstractGeometry
      Parameters:
      spec - the argument string without the geometry key
      Returns:
      true if parsing succeeded, false if invalid
    • isSubtype

      public boolean isSubtype(GeometryType type)
      Check if the sub-geometry matches the given type.
      Parameters:
      type - the geometry type to check against
      Returns:
      true if the sub-geometry matches the given type
    • getSubType

      public GeometryType getSubType()
      Retrieve the geometry used within each hierarchy level (e.g. square or well-mixed).
      Returns:
      the geometry used within each hierarchy level (e.g. square or well-mixed)
    • getHierarchyWeight

      public double getHierarchyWeight()
      Report the weight applied to inter-level interactions.
      Returns:
      the weight applied to inter-level interactions
    • getHierarchyLevels

      public int[] getHierarchyLevels()
      Retrieve a copy of the processed hierarchy definition (levels plus individuals per deme).
      Returns:
      a copy of the processed hierarchy definition (levels plus individuals per deme)
    • checkSettings

      protected boolean checkSettings()
      Description copied from class: AbstractGeometry
      Hook for subclasses to implement geometry specific checks.
      Overrides:
      checkSettings in class AbstractGeometry
      Returns:
      true if adjustments require a reset
    • calcUnitSize

      private boolean calcUnitSize()
      Process the hierarchy specifications to calculate the number of units and the size of each unit. On each level there must be at least 2 units for well-mixed hierarchies and each unit must contain at least 2 individuals. For hierarchies with square lattices each level must ahev at least 2x2 units with at least 3x3 individuals each.
      Returns:
      true if the size was adjusted and resetting is required
    • calcSquareUnit

      private int calcSquareUnit(int nHierarchy)
      Calculate the unit size for square-lattice hierarchies, adjusting each level to a perfect square with at least 2x2 units with at least 3x3 individuals each.
      Parameters:
      nHierarchy - the number of hierarchy levels
      Returns:
      the total size of the graph
    • init

      public void init()
      Initialise the geometry.

      Requirements/notes:

      Only well-mixed (complete) or square lattice graphs are currently supported.
      Specified by:
      init in class AbstractGeometry
    • initHierarchy

      private void initHierarchy(int level, int start)
      Utility method to generate hierarchical graphs.
      Parameters:
      level - the hierarchical level
      start - the index of the first node to process
    • initHierarchyMeanfield

      private void initHierarchyMeanfield(int start, int end)
      Utility method to generate hierarchical well-mixed subpopulations (demes).
      Parameters:
      start - the index of the first node to process
      end - the index of the last node to process
    • initHierarchySquare

      private void initHierarchySquare(int start, int end)
      Utility method to generate hierarchical square-lattice demes.
      Parameters:
      start - the index of the first node to process
      end - the index of the last node to process
    • initSquareVonNeumann

      private void initSquareVonNeumann(int sideLen, int fullside, int offset)
      Initialize a square deme with von Neumann connectivity, optionally adjusting for boundary conditions.
      Parameters:
      sideLen - side length of the deme
      fullside - side length of the full lattice
      offset - index offset of the deme
    • adjustNeumannBoundaries

      private void adjustNeumannBoundaries(int sideLen, int fullside, int offset, boolean interspecies)
      Adjust von Neumann neighbourhoods along fixed boundaries.
      Parameters:
      sideLen - side length of the deme
      fullside - side length of the full lattice
      offset - index offset of the deme
      interspecies - true if interspecific interactions allow self-links
    • initSquareVonNeumann2nd

      private void initSquareVonNeumann2nd(int sideLen, int fullside, int offset)
      Initialize a square deme with second-neighbour von Neumann connectivity.
      Parameters:
      sideLen - side length of the deme
      fullside - side length of the full lattice
      offset - index offset of the deme
    • adjustNeumann2ndBoundaries

      private void adjustNeumann2ndBoundaries(int sideLen, int fullside, int offset, boolean interspecies)
      Adjust second-neighbour von Neumann neighbourhoods along fixed boundaries.
      Parameters:
      sideLen - side length of the deme
      fullside - side length of the full lattice
      offset - index offset of the deme
      interspecies - true if interspecific interactions allow self-links
    • initSquareMoore

      private void initSquareMoore(int sideLen, int fullside, int offset)
      Initialize a square deme with Moore connectivity.
      Parameters:
      sideLen - side length of the deme
      fullside - side length of the full lattice
      offset - index offset of the deme
    • adjustMooreBoundaries

      private void adjustMooreBoundaries(int sideLen, int fullside, int offset, boolean interspecies)
      Adjust Moore neighbourhoods along fixed boundaries.
      Parameters:
      sideLen - side length of the deme
      fullside - side length of the full lattice
      offset - index offset of the deme
      interspecies - true if interspecific interactions allow self-links
    • initSquare

      private void initSquare(int sideLen, int fullside, int offset)
      Initialize a square deme for arbitrary (odd) neighbourhood sizes.
      Parameters:
      sideLen - side length of the deme
      fullside - side length of the full lattice
      offset - index offset of the deme
    • addSquareNeighborhood

      private void addSquareNeighborhood(int i, int j, int sideLen, int fullside, int offset, int range, boolean interspecies)
      Add all neighbours for a player in the square deme.
      Parameters:
      i - row index within the deme
      j - column index within the deme
      sideLen - side length of the deme
      fullside - side length of the full lattice
      offset - index offset of the deme
      range - neighbour range
      interspecies - true if interspecific interactions allow self-links
    • adjustSquareBoundaries

      private void adjustSquareBoundaries(int sideLen, int fullside, int offset, int range, boolean interspecies)
      Adjust arbitrary-range square neighbourhoods along fixed boundaries.
      Parameters:
      sideLen - side length of the deme
      fullside - side length of the full lattice
      offset - index offset of the deme
      range - neighbour range
      interspecies - true if interspecific interactions allow self-links
    • addBoundaryLinks

      private void addBoundaryLinks(int player, int fullside, int range, boolean interspecies, int uStep, int vStep)
      Add links for a boundary player in a square deme.
      Parameters:
      player - the player at the boundary
      fullside - the side length of the full lattice
      range - the neighbour range
      interspecies - true for interspecific interactions
      uStep - the step size in the u direction
      vStep - the step size in the v direction
    • isUnique

      public boolean isUnique()
      Description copied from class: AbstractGeometry
      Check if current geometry unique. Only unique geomteries need to be encoded.

      Requirements/notes:

      1. Lattices etc. are not unique because they can be identically recreated.
      2. Complete graphs, stars, wheels, etc. are not unique.
      3. All geometries involving random elements are unique.
      4. All rewired geometries are unique.
      5. Hierarchical geometries require recursive checks of uniqueness.
      Overrides:
      isUnique in class AbstractGeometry
      Returns:
      true if geometry is unique
    • clone

      public HierarchicalGeometry clone()
      Description copied from class: AbstractGeometry
      Clone geometry.

      Requirements/notes:

      1. Overrides clone() in Object but conflicts with GWT's aversion to clone()ing...
      2. Remove @SuppressWarnings("all") to ensure that no other issues crept in when modifying method.
      Overrides:
      clone in class AbstractLattice
      Returns:
      clone of geometry
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AbstractLattice
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class AbstractLattice
    • parseHierarchy

      private void parseHierarchy()
      Parse the hierarchy-related CLI spec, updating subtype, boundary flag and weight, and storing the raw hierarchy levels (without the computed leaf size).