Sets up functions, properties, and methods for spatial models. This function should be run before the control panel is drawn.
The function does several things:
- Creates a spatially fixed
patchprimitive to represent map coordinates.
- Creates a network named
'space'connecting each patch to its neighbors.
- Initializes the
- Adds movement methods and properties to agents of all primitives except patches, which cannot move.
agent.moveRight()— move the agent one patch over starting from the current location.
agent.move(x, y)— moves the agent some number of patches over and some number of patches down.
agent.moveTo(patch)— moves the agent to the patch located at (x,y) or the location of the patch.
agent.distanceFrom(agent)— calculates the spatial distance between the current agent and another.
agent.position— the current coordinates of the agent. Patches also have
patch.position, but it cannot be modified. Integer locations correspond to the center of a patch, so the range of the
dim-0.5, and mutatis mutandis for
- Registers the
Chartsvisualizer and a
networkplot with a patchgrid layout upon it. The plot object has a
config()method that allows various aspects of the map to be customized. By default patches are displayed in a grid with colors corresponding to a specified parameter, and agents are displayed as dots of their breed color. The
model.visualobject can be used to display other chart plots alongside the spatial map. Note that functions calling
model.spatial()do not then need to call
By default, agents are randomly positioned on the grid on model launch. The
agentPosition hook can be used to override this and specify agents’ initial positions.
dim — int|tuple, optional
The map dimensions. Pass an integer for a square map, or a two-element tuple to specify (x,y) dimensions.
Default value: 10
wrap — bool|tuple, optional
Whether patches at the edges of the map should be connected to patches on the opposite edge, if the
PatchesRect, for example, can support several geometries:
False: Rectangular (no wrapping).
True: Toroidal (wrapping on both axes).
(False, True): Cylindrical (wrapping on one axis).
Default value: True
corners — bool|float, optional
Whether to connect patches to their corners, and if so, the weight of the connection (between 0 and 1).
Default value: False
geometry — str|class, optional
Default value: 'rect'