Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## uchicago.src.sim.space
Class Diffuse2DHexagonal

    java.lang.Object
      uchicago.src.sim.space.Diffuse2D
          uchicago.src.sim.space.Diffuse2DHexagonal

All Implemented Interfaces:
  Discrete2DSpace, Torus

Direct Known Subclasses:
  HexaSpace

    public class Diffuse2DHexagonal

extends Diffuse2D

Discrete 2nd order approximation of 2d diffusion with evaporation on a hexagonal grid. Based on the Objective C implementation of Diffuse2d in the Swarm simulation toolkit, with the addition of a hexagonal grid. 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.

The hexagonal cells are referenced by x, y coordinates as follows:

           _
       _ / 1 \ _
     / 0 \ _ / 2 \
     \ _ / 4 \ _ /
     / 3 \ _ / 5 \
     \ _ / 7 \ _ /
     / 6 \ _ / 8 \
     \ _ /   \ _ /

Here we have a 3 x 3 hexagonal grid. The first row of cells is 0, 1, 2 such that 0,0 refers to cell 0, and 0,2 refers to cell 2. The next row of cells is 3, 4, 5, so 1,0 refers to cell 3 and so on. The last row of cells is 6, 7, and 8, so 2, 0 refers to cell 6. The ring of neighbors with radius one that surrounds cell 4 is composed of 1, 2, 5, 7, 3, and 0. The grid wraps as a toriod such that cell -1, 0 refers to cell 2 and cell 0, -1 is cell 6.

See `diffuse` for a brief explanation of the diffusion algorithm.

Field Summary

Fields inherited from class uchicago.src.sim.space.Diffuse2D
`diffCon, evapRate, MAX, MIN, nextX, nextY, prevX, prevY, readMatrix, writeMatrix, x, xSize, y, ySize`

Fields inherited from interface uchicago.src.sim.space.Discrete2DSpace
`MOORE, VON_NEUMANN`

Constructor Summary
`Diffuse2DHexagonal(double diffusionConstant, double evaporationRate, int xSize, int ySize)` Constructs a Diffuse2DHexagonal space with the specified diffusion constant, evaporation rate, and dimensions
`Diffuse2DHexagonal(int xSize, int ySize)` Constructs a Diffuse2DHexagonal space with the specificed dimensions

Method Summary
`void` | `diffuse()` Runs the diffusion with the current rates and values.
`double[]` | `findMaximum(int x, int y, int radius, boolean includeOrigin)` Finds the maximum grid cell value within a specified radius from the specified origin coordinate.
`double[]` | `findMinimum(int x, int y, int radius, boolean includeOrigin)` Finds the maximum grid cell value within a specified radius from the specified origin coordinate.
`double[]` | `getMooreNeighbors(int x, int y)` The notion of a Moore neighborhood is incoherent on a hexagonal grid.
`double[]` | `getMooreNeighbors(int x, int y, int xExtent, int yExtent)` The notion of a Moore neighborhood is incoherent for a hexagonal grid.
`double[]` | `getNeighbors(int x, int y)` Returns the ring of neighbors with a radius of 1 surrounding the cell at x, y.
`double[]` | `getNeighbors(int x, int y, int radius)` Returns the rings of neighbors surrounding the cell at x, y.
`double[]` | `getVonNeumannNeighbors(int x, int y)` The notion of a vonNeumann neighborhood is incoherent for a hexagonal grid.
`double[]` | `getVonNeumannNeighbors(int x, int y, int xExtent, int yExtent)` The notion of a vonNeumann neighborhood is incoherent for a hexagonal grid.

Methods inherited from class uchicago.src.sim.space.Diffuse2D
`compareMax, compareMin, findMaximum, findMinimum, getMatrix, getObjectAt, getSize, getSizeX, getSizeY, getValueAt, putObjectAt, putValueAt, setDiffusionConstant, setEvaporationRate, update, xnorm, ynorm`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Diffuse2DHexagonal

    public Diffuse2DHexagonal(int xSize,
                              int ySize)

  Constructs a Diffuse2DHexagonal space with the specificed dimensions

  Parameters:
    `xSize` - size of the x dimension
    `ySize` - size of the y dimension

### Diffuse2DHexagonal

    public Diffuse2DHexagonal(double diffusionConstant,
                              double evaporationRate,
                              int xSize,
                              int ySize)

  Constructs a Diffuse2DHexagonal 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 Detail

### 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 six 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.

  Overrides:
    `diffuse` in class `Diffuse2D`

### getVonNeumannNeighbors

    public double[] getVonNeumannNeighbors(int x,
                                           int y)

  The notion of a vonNeumann neighborhood is incoherent for a hexagonal grid. Consequently this method always throws an UnsupportedOperationException. To get neighbors see `getNeighbors` or `getNeighbors`.

  Overrides:
    `getVonNeumannNeighbors` in class `Diffuse2D`
  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
  Throws:
    `java.lang.UnsupportedOperationException` - when called

### getVonNeumannNeighbors

    public double[] getVonNeumannNeighbors(int x,
                                           int y,
                                           int xExtent,
                                           int yExtent)

  The notion of a vonNeumann neighborhood is incoherent for a hexagonal grid. Consequently this method always throws an UnsupportedOperationException. To get neighbors see `getNeighbors` or `getNeighbors`.

  Overrides:
    `getVonNeumannNeighbors` in class `Diffuse2D`
  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.
  Throws:
    `java.lang.UnsupportedOperationException` - when called

### getMooreNeighbors

    public double[] getMooreNeighbors(int x,
                                      int y)

  The notion of a Moore neighborhood is incoherent on a hexagonal grid. Consequently this method always throws an UnsupportedOperationException. To get neighbors see `getNeighbors` or `getNeighbors`.

  Overrides:
    `getMooreNeighbors` in class `Diffuse2D`
  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."
  Throws:
    `java.lang.UnsupportedOperationException` - when called

### getMooreNeighbors

    public double[] getMooreNeighbors(int x,
                                      int y,
                                      int xExtent,
                                      int yExtent)

  The notion of a Moore neighborhood is incoherent for a hexagonal grid. Consequently this method always throws an UnsupportedOperationException. To get neighbors see `getNeighbors` or `getNeighbors`.

  Overrides:
    `getMooreNeighbors` in class `Diffuse2D`
  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."
  Throws:
    `java.lang.UnsupportedOperationException` - when called

### getNeighbors

    public double[] getNeighbors(int x,
                                 int y)

  Returns the ring of neighbors with a radius of 1 surrounding the cell at x, y.

  Parameters:
    `x` - the x coordinate of the cell
    `y` - the y coordinate of the cell
  Returns:
    an array of doubles in clockwise order starting with the north or "12" neighboring cell

### getNeighbors

    public double[] getNeighbors(int x,
                                 int y,
                                 int radius)

  Returns the rings of neighbors surrounding the cell at x, y. The number of rings is specified by the radius parameter.

  Parameters:
    `x` - the x coordinate of the cell
    `y` - the y coordinate of the cell
    `radius` - the number of neighbor rings to return
  Returns:
    an array of doubles beginning with the outermost ring of neighbors, starting with the north or "12 o'clock" neighboring cell, continuing clockwise and spiraling inwards

### findMaximum

    public double[] findMaximum(int x,
                                int y,
                                int radius,
                                boolean includeOrigin)

  Finds the maximum grid cell value within a specified radius from the specified origin coordinate. This searches through the neighborhood rings and returns the maximum value.

  Parameters:
    `x` - the x origin coordinate
    `y` - the y origin coordinate
    `radius` - the neighborhood radius defining the area to search
    `includeOrigin` - include object at origin in search
  Returns:
    the values determined to be the maximum.

### findMinimum

    public double[] findMinimum(int x,
                                int y,
                                int radius,
                                boolean includeOrigin)

  Finds the maximum grid cell value within a specified radius from the specified origin coordinate. This searches through the neighborhood rings and returns the maximum value.

  Parameters:
    `x` - the x origin coordinate
    `y` - the y origin coordinate
    `radius` - the neighborhood radius defining the area to search
    `includeOrigin` - include object at origin in search
  Returns:
    the values determined to be the maximum.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD