Package microsim.space
Class DoubleDiffuseSpace
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final longstatic final intstatic final intFields inherited from class microsim.space.DoubleSpace
mFields inherited from class microsim.space.AbstractSpace
modCount, xSize, ySize -
Constructor Summary
ConstructorsConstructorDescriptionDoubleDiffuseSpace(int xSize, int ySize) Constructs a DblDiffuseTorusGrid space with the specificed dimensionsDoubleDiffuseSpace(int xSize, int ySize, double diffusionConstant, double evaporationRate) Constructs a DblDiffuseTorusGrid space with the specified diffusion constant, evaporation rate, and dimensions -
Method Summary
Modifier and TypeMethodDescriptionvoiddiffuse()Runs the diffusion with the current rates and values.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.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.double[]Return the matrix of values representing the grid.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."double[]getMooreNeighbors(int x, int y, int xExtent, int yExtent) Gets the extended Moore neighbors of the specified coordinate.double[]getVonNeumannNeighbors(int x, int y) Gets the von Neumann neighbors of the specified coordinate. doubles are returned in west, east, north, south order.double[]getVonNeumannNeighbors(int x, int y, int xExtent, int yExtent) Gets the extended von Neumann neighbors of the specified coordinate.voidvoidprint(double[] mtr) voidsetDiffusionConstant(double diffusionConstant) Sets the diffusion constant for this DblDiffuseTorusGrid spacevoidsetEvaporationRate(double rate) Sets the evaporation rate for this DblDiffuseTorusGrid spacevoidupdate()Copies the writeLattice to the readLatticeMethods inherited from class microsim.space.DoubleSpace
add, at, clear, copyGridTo, copyGridTo, countObjectsAt, get, getDbl, max, mean, min, multiply, resetTo, set, setDbl, size, sum, swapPositions, varianceMethods inherited from class microsim.space.AbstractSpace
boundX, boundY, equals, getMooreNeighborsPositions, getVonNeumannNeighborsPositions, getXSize, getYSize, reflectX, reflectY, torusX, torusY, toString
-
Field Details
-
EVENT_DIFFUSE
public static final int EVENT_DIFFUSE- See Also:
-
VON_NEUMANN
public static final int VON_NEUMANN- See Also:
-
MOORE
public static final int MOORE- See Also:
-
MAX
public static final long MAX- See Also:
-
-
Constructor Details
-
DoubleDiffuseSpace
public DoubleDiffuseSpace(int xSize, int ySize) Constructs a DblDiffuseTorusGrid space with the specificed dimensions- Parameters:
xSize- size of the x dimensionySize- 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 constantevaporationRate- the evaporation ratexSize- size of the x dimensionySize- 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 objecty- 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 objecty- the y coordinate of the objectxExtent- the extension of the neighborhood in the x directionyExtent- 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 objecty- 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 objecty- the y coordinate of the objectxExtent- the extension of the neighborhood in the x directionyExtent- 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 coordinatey- the y origin coordinaterange- the range out from the coordinate to searchincludeOrigin- include object at origin in searchneighborhoodType- 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 coordinatey- the y origin coordinaterange- the range out from the coordinate to searchincludeOrigin- include object at origin in searchneighborhoodType- 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:DoubleSpaceReturn the matrix of values representing the grid.- Overrides:
getMatrixin classDoubleSpace- Returns:
- A matrix of double with the same dimensions of the grid.
-
onEvent
- Specified by:
onEventin interfaceEventListener
-