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 Object2DGrid

    java.lang.Object
      uchicago.src.sim.space.Object2DGrid

All Implemented Interfaces:
  Discrete2DSpace

Direct Known Subclasses:
  Object2DHexagonalGrid, Object2DTorus

    public class Object2DGrid

extends java.lang.Object
implements Discrete2DSpace

A discrete 2 dimensional grid of objects, accessed by x and y coordinates.

Author:
  Nick Collier

Field Summary
`protected NewMatrix` | `matrix`
`protected Neighborhooder` | `Mneigh`
`static int` | `PGM_ASCII`
`static int` | `RASTER_ASCII`
`protected Neighborhooder` | `VNneigh`
`protected int` | `xSize`
`protected int` | `ySize`

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

Constructor Summary
`Object2DGrid(java.io.InputStream stream, int type)` Constructs a grid from an InputStream.
`Object2DGrid(int xSize, int ySize)` Constructs a grid with the specified size.
`Object2DGrid(java.lang.String fileName, int type)` Constructs a grid from a file.

Method Summary
`java.util.Vector` | `findMaximum(int x, int y, int range, boolean includeOrigin, int neighborhoodType)` Finds the maximum grid cell occupant within a specified range from the specified origin coordinate.
`java.util.Vector` | `findMinimum(int x, int y, int range, boolean includeOrigin, int neighborhoodType)` Finds the minimum grid cell occupant within a specified range from the specified origin coordinate.
`BaseMatrix` | `getMatrix()` Returns the matrix collection object associated with this 2d grid
`java.util.Vector` | `getMooreNeighbors(int x, int y, boolean returnNulls)` Gets the Moore neighbors of the object at x, y.
`java.util.Vector` | `getMooreNeighbors(int x, int y, int xExtent, int yExtent, boolean returnNulls)` Gets the extended Moore neighbors of the object at x, y.
`java.lang.Object` | `getObjectAt(int x, int y)` Gets the object at (x,y)
`java.awt.Dimension` | `getSize()` Gets the size as a Dimension.
`int` | `getSizeX()` Gets the size of the x dimension.
`int` | `getSizeY()` Gets the size of the y dimension.
`double` | `getValueAt(int x, int y)` Gets the double value at (x,y) if possible
`java.util.Vector` | `getVonNeumannNeighbors(int x, int y, boolean returnNulls)` Gets the von Neumann neighbors of the object at x, y.
`java.util.Vector` | `getVonNeumannNeighbors(int x, int y, int xExtent, int yExtent, boolean returnNulls)` Gets the extended von Neumann neighbors of the object at x, y.
`void` | `putObjectAt(int x, int y, java.lang.Object object)` Puts the specified object at (x,y)
`void` | `putValueAt(int x, int y, double value)` Puts the specified double at (x,y)
`protected void` | `rangeCheck(int x, int y)`
`void` | `setComparator(java.util.Comparator comparator)` Sets the comparator class used by the findMaximum and findMinimum methods.

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

Field Detail

### PGM_ASCII

    public static final int PGM_ASCII

See Also:
  Constant Field Values

### RASTER_ASCII

    public static final int RASTER_ASCII

See Also:
  Constant Field Values

### matrix

    protected NewMatrix matrix

### xSize

    protected int xSize

### ySize

    protected int ySize

### VNneigh

    protected Neighborhooder VNneigh

### Mneigh

    protected Neighborhooder Mneigh

Constructor Detail

### Object2DGrid

    public Object2DGrid(int xSize,
                        int ySize)

  Constructs a grid with the specified size.

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

### Object2DGrid

    public Object2DGrid(java.io.InputStream stream,
                        int type)

  Constructs a grid from an InputStream. Only ASCII PGM format files as the ssource of the InputStream are supported at this time. Code adapted from Nelson Minar's implementation of SugarScape with Swarm.

### Object2DGrid

    public Object2DGrid(java.lang.String fileName,
                        int type)

  Constructs a grid from a file. Only ASCII PGM files are supported at this time. Code adapted from Nelson Minar's implementation of SugarScape with Swarm.

Method Detail

### getVonNeumannNeighbors

    public java.util.Vector getVonNeumannNeighbors(int x,
                                                   int y,
                                                   boolean returnNulls)

  Gets the von Neumann neighbors of the object at x, y. Objects are returned in west, east, north, south order. The object at x, y is not returned.

  Parameters:
    `x` - the x coordinate of the object
    `y` - the y coordinate of the object
    `returnNulls` - whether nulls (nothing at x,y) should be returned
  Returns:
    a vector of objects (and possibly nulls) in west, east, north, south order
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the given coordinates are out of range (x < 0 || x >= xSize || y < 0 || y >= ySize)

### getVonNeumannNeighbors

    public java.util.Vector getVonNeumannNeighbors(int x,
                                                   int y,
                                                   int xExtent,
                                                   int yExtent,
                                                   boolean returnNulls)

  Gets the extended von Neumann neighbors of the object at x, y. The extension in the x and y direction are specified by xExtent and yExtent. Objects are return in west, east, north, south order.The most distant objects are returned first, that is, all the objects to the west starting with the most distant, then those to the east and so on. The Object 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
    `returnNulls` - whether nulls should be returned
  Returns:
    a vector of objects (and possibly nulls) in west, east, north, south order with the most distant object first.
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the given coordinates are out of range (x < 0 || x >= xSize || y < 0 || y >= ySize)

### getMooreNeighbors

    public java.util.Vector getMooreNeighbors(int x,
                                              int y,
                                              boolean returnNulls)

  Gets the Moore neighbors of the object at x, y. Objects are returned by row starting with the "NW corner" and ending with the "SE corner." The Object at x, y is not returned.

  Parameters:
    `x` - the x coordinate of the object
    `y` - the y coordinate of the object
    `returnNulls` - should the returned Vector contain null objects
  Returns:
    a vector of objects (and possibly nulls) ordered by row starting with the "NW corner" and ending with the "SE corner."
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the given coordinates are out of range (x < 0 || x >= xSize || y < 0 || y >= ySize)

### getMooreNeighbors

    public java.util.Vector getMooreNeighbors(int x,
                                              int y,
                                              int xExtent,
                                              int yExtent,
                                              boolean returnNulls)

  Gets the extended Moore neighbors of the object at x, y. The extension in the x and y direction are specified by xExtent and yExtent. Objects are returned by row starting with the "NW corner" and ending with the "SE corner." The Object 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
    `returnNulls` - should the returned Vector contain null objects
  Returns:
    a vector of objects (and possibly nulls) ordered by row starting with the "NW corner" and ending with the "SE corner."
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the given coordinates are out of range (x < 0 || x >= xSize || y < 0 || y >= ySize)

### setComparator

    public void setComparator(java.util.Comparator comparator)

  Sets the comparator class used by the findMaximum and findMinimum methods.

  Parameters:
    `comparator` - the comparator to use for finding maximum and minimum.

### findMaximum

    public java.util.Vector findMaximum(int x,
                                        int y,
                                        int range,
                                        boolean includeOrigin,
                                        int neighborhoodType)

  Finds the maximum grid cell occupant within a specified range from the specified origin coordinate. Maximum is determined by the default or user supplied comparator class. The default comparator compares objects using the >, <, and = operators on the hashcode of the objects.

  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.
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the given coordinates are out of range (x < 0 || x >= xSize || y < 0 || y >= ySize)

### findMinimum

    public java.util.Vector findMinimum(int x,
                                        int y,
                                        int range,
                                        boolean includeOrigin,
                                        int neighborhoodType)

  Finds the minimum grid cell occupant within a specified range from the specified origin coordinate. Minimum is determined by the default or user supplied comparator class. The default comparator compares objects using the >, <, and = operators on the hashcode of the objects.

  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.
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the given coordinates are out of range (x < 0 || x >= xSize || y < 0 || y >= ySize)

### rangeCheck

    protected void rangeCheck(int x,
                              int y)

### getSizeX

    public int getSizeX()

  Gets the size of the x dimension.

  Specified by:
    `getSizeX` in interface `Discrete2DSpace`

### getSizeY

    public int getSizeY()

  Gets the size of the y dimension.

  Specified by:
    `getSizeY` in interface `Discrete2DSpace`

### getSize

    public java.awt.Dimension getSize()

  Gets the size as a Dimension.

  Specified by:
    `getSize` in interface `Discrete2DSpace`

### getObjectAt

    public java.lang.Object getObjectAt(int x,
                                        int y)

  Gets the object at (x,y)

  Specified by:
    `getObjectAt` in interface `Discrete2DSpace`
  Parameters:
    `x` - the x coordinate
    `y` - the y coordinate
  Returns:
    the Object at x,y
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the given coordinates are out of range (x < 0 || x >= xSize || y < 0 || y >= ySize)

### getValueAt

    public double getValueAt(int x,
                             int y)

  Gets the double value at (x,y) if possible

  Specified by:
    `getValueAt` in interface `Discrete2DSpace`
  Parameters:
    `x` - the x coordinate
    `y` - the y coordinate
  Returns:
    the value at x, y
  Throws:
    `java.lang.IllegalArgumentException` - if object at x,y cannot be converted to a number.
    `java.lang.IndexOutOfBoundsException` - if the given coordinates are out of range (x < 0 || x >= xSize || y < 0 || y >= ySize)

### putObjectAt

    public void putObjectAt(int x,
                            int y,
                            java.lang.Object object)

  Puts the specified object at (x,y)

  Specified by:
    `putObjectAt` in interface `Discrete2DSpace`
  Parameters:
    `x` - the x coordinate
    `y` - the y coordinate
    `object` - the object to put at (x,y)
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the given coordinates are out of range (x < 0 || x >= xSize || y < 0 || y >= ySize)

### putValueAt

    public void putValueAt(int x,
                           int y,
                           double value)

  Puts the specified double at (x,y)

  Specified by:
    `putValueAt` in interface `Discrete2DSpace`
  Parameters:
    `x` - the x coordinate
    `y` - the y coordinate
    `value` - the double to put at (x,y)
  Throws:
    `java.lang.IndexOutOfBoundsException` - if the given coordinates are out of range (x < 0 || x >= xSize || y < 0 || y >= ySize)

### getMatrix

    public BaseMatrix getMatrix()

  Returns the matrix collection object associated with this 2d grid

  Specified by:
    `getMatrix` in interface `Discrete2DSpace`

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