Class DoubleDiffuseSpace

All Implemented Interfaces:
EventListener

public class DoubleDiffuseSpace extends DoubleSpace implements EventListener
Discrete 2nd order approximation of 2d diffusion with evaporation. Essentialy a java implementation of Diffuse2d in the Swarm simulation toolkit. Toroidal in shape and works with number values. This space simulates concurency through the use of a read and write matrix. Any writes to the space, write to the write matrix, and any reads to the read matrix. The diffuse() method then diffuses the write matrix and copies the new values into the read matrix.

For an example of a DblDiffuseTorusGrid space see the heatBugs example. See diffuse for a brief explanation of the diffusion algorithm. Note that this space doesn't seem to work correctly when run with hotspot 1.01

Version:
$Revision: 1.2 $ $Date: 2004/08/11 09:05:30 $
Author:
Nick Collier
  • Field Details

  • Constructor Details

    • DoubleDiffuseSpace

      public DoubleDiffuseSpace(int xSize, int ySize)
      Constructs a DblDiffuseTorusGrid space with the specificed dimensions
      Parameters:
      xSize - size of the x dimension
      ySize - size of the y dimension
    • DoubleDiffuseSpace

      public DoubleDiffuseSpace(int xSize, int ySize, double diffusionConstant, double evaporationRate)
      Constructs a DblDiffuseTorusGrid space with the specified diffusion constant, evaporation rate, and dimensions
      Parameters:
      diffusionConstant - the diffusion constant
      evaporationRate - the evaporation rate
      xSize - size of the x dimension
      ySize - size of the y dimension
  • Method Details

    • setDiffusionConstant

      public void setDiffusionConstant(double diffusionConstant)
      Sets the diffusion constant for this DblDiffuseTorusGrid space
    • setEvaporationRate

      public void setEvaporationRate(double rate)
      Sets the evaporation rate for this DblDiffuseTorusGrid space
    • diffuse

      public void diffuse()
      Runs the diffusion with the current rates and values. Following the Swarm class, it is roughly newValue = evap(ownValue + diffusionConstant * (nghAvg - ownValue)) where nghAvg is the weighted average of a cells eight neighbors, and ownValue is the current value for the current cell.

      Values from the readMatrix are used to calculate diffusion. This value is then written to the writeMatrix. When this has been done for every cell in the grid, the writeMatrix is copied to the readMatrix.

    • update

      public void update()
      Copies the writeLattice to the readLattice
    • print

      public void print(double[] mtr)
    • getVonNeumannNeighbors

      public double[] getVonNeumannNeighbors(int x, int y)
      Gets the von Neumann neighbors of the specified coordinate. doubles are returned in west, east, north, south order. The double at x, y is not returned.
      Parameters:
      x - the x coordinate of the object
      y - the y coordinate of the object
      Returns:
      an array of doubles in west, east, north, south order
    • getVonNeumannNeighbors

      public double[] getVonNeumannNeighbors(int x, int y, int xExtent, int yExtent)
      Gets the extended von Neumann neighbors of the specified coordinate. The extension in the x and y direction are specified by xExtent and yExtent. doubles are returned in west, east, north, south order with the most distant object first. The double at x,y is not returned.
      Parameters:
      x - the x coordinate of the object
      y - the y coordinate of the object
      xExtent - the extension of the neighborhood in the x direction
      yExtent - the extension of the neighborhood in the y direction
      Returns:
      an array of doubles in west, east, north, south order with the most distant object first.
    • getMooreNeighbors

      public double[] getMooreNeighbors(int x, int y)
      Gets the Moore neighbors of the specified coordinate. doubles are returned by row starting with the "NW corner" and ending with the "SE corner." The double at x, y is not returned.
      Parameters:
      x - the x coordinate of the object
      y - the y coordinate of the object
      Returns:
      an array of doubles ordered by row starting with the "NW corner" and ending with the "SE corner."
    • getMooreNeighbors

      public double[] getMooreNeighbors(int x, int y, int xExtent, int yExtent)
      Gets the extended Moore neighbors of the specified coordinate. The extension in the x and y direction are specified by xExtent and yExtent. doubles are returned by row starting with the "NW corner" and ending with the "SE corner." The double at x,y is not returned.
      Parameters:
      x - the x coordinate of the object
      y - the y coordinate of the object
      xExtent - the extension of the neighborhood in the x direction
      yExtent - the extension of the neighborhood in the y direction
      Returns:
      an array of doubles ordered by row starting with the "NW corner" and ending with the "SE corner."
    • findMaximum

      public double[] findMaximum(int x, int y, int range, boolean includeOrigin, int neighborhoodType)
      Finds the maximum grid cell value within a specified range from the specified origin coordinate.
      Parameters:
      x - the x origin coordinate
      y - the y origin coordinate
      range - the range out from the coordinate to search
      includeOrigin - include object at origin in search
      neighborhoodType - the type of neighborhood to search. Can be one of Discrete2DSpace.VON_NEUMANN or Discrete2DSpace.MOORE.
      Returns:
      the Objects determined to be the maximum.
    • findMinimum

      public double[] findMinimum(int x, int y, int range, boolean includeOrigin, int neighborhoodType)
      Finds the minimum grid cell value within a specified range from the specified origin coordinate.
      Parameters:
      x - the x origin coordinate
      y - the y origin coordinate
      range - the range out from the coordinate to search
      includeOrigin - include object at origin in search
      neighborhoodType - the type of neighborhood to search. Can be one of Discrete2DSpace.VON_NEUMANN or Discrete2DSpace.MOORE.
      Returns:
      the Objects determined to be the maximum.
    • getMatrix

      public double[] getMatrix()
      Description copied from class: DoubleSpace
      Return the matrix of values representing the grid.
      Overrides:
      getMatrix in class DoubleSpace
      Returns:
      A matrix of double with the same dimensions of the grid.
    • onEvent

      public void onEvent(Enum<?> type)
      Specified by:
      onEvent in interface EventListener