A coordinate system class defining a rectangular two-dimensional grid, where each column has the same number of rows. Patches are accessed using a two-dimensional [x,y]
index.
This coordinate system assigns up
, down
, left
, and right
properties to patches, and moveUp()
, moveDown()
, moveLeft()
, and moveRight()
methods to non-patch agents, and also defines distance and angle functions on a rectangular grid.
This class should not be initialized in user code; it is initialized automatically with model.spatial(geometry='rect')
.
Initialization Parameters
dim — tuple(int, int), required
The (x,y) dimensions of the grid.
wrap — bool|tuple(bool,bool), optional
Whether patches at the edges of the map should be connected to patches on the opposite edge.
PatchesRect
can support several geometries this way:False
: Rectangular (no wrapping).True
: Toroidal (wrapping on both axes).(True, False)
or(False, True)
: Cylindrical (wrapping on one axis).
Default value: True
**kwargs — optional
Additional arguments passed from
model.spatial()
.Default value: {}
Methods
Click a method name for more detailed documentation.
at( x, y )
Returns the patch at the specified coordinate.
revive( coords )
Reinstates a dead patch.
neighbors( model )
Establishes the spatial network among the patches after initialization. This function is registered automatically as a
modelPostSetup
hook during spatial setup and should not be called by user code.place( patch )
Organizes
Patch
objects within the Patches object. Takes a patch object when created byAgents.initialize()
, places it in the appropriate list, and assigns itsposition
property.
Object Properties
offmap — bool
Whether agents can enter areas of the map with no patch. If
False
and an agent tries tomove()
to a coordinate with no patch, the move will fail and a warning will be raised. Set from theoffmap
argument ofmodel.spatial()
.Initial value: False
boundaries — tuple(tuple(int,int), tuple(int,int))
A tuple of tuples with the maximum and minimum coordinates that agents can take, given the grid dimensions.
((xmin, xmax), (ymin, ymax))
.corners — bool|float
Whether the
'spatial'
network includes patches connected only by a corner. Corresponds to thecorners
argument ofmodel.spatial()
.Initial value: False
wrap — tuple(bool, bool)
Whether each respective dimension wraps around beyond the limits of
boundaries
.dim — tuple(int, int)
The (x,y) dimensions of the grid.
Static Properties
geometry — str
The name of the patch geometry, to be set by subclasses.
Initial value: ''
Notes and Examples