Grid Model

 Grid Model

This is the default model for creating simulations that take place on a grid / torus topology. In a grid model, the agents occupy a grid cell, a single agent to a single grid cell.

Appropriate Parent Component

Project. The grid model is added to an Environemt component.

Properties

Properties are the items that appear in the property pane when you click on a component in the project tree. For more information of properties, see here.

Name     Description
Actions See the section on Actions and editing them if you are unfamiliar with Actions.

Grid Model includes a single default action: initAgents. This action will be executed at the beginning of the simulation as part of set up. This action will execute after the agents have been created and added to their respective groups. Consequently, you can iterate through an agent group and perform any additional custom initialization. For example,

for agent as GridAgent in self.gridAgentGroup:
  agent.init()

which will iterate through all the agents in the gridAgentGroup group and call the init() action on them. This assumes of course, that you have created an init action for your Agent component.

Display Name This name will be displayed as the title of your model when it is running.
Master Schedule See the schedule help and tutorial 3 for more information on schedules and scheduling.

The master schedule property gives you an editable view of all the scheduled actions in relation to each other. You can edit their relative order here. By default, the step action of every agent is scheduled to execute every iteration of the simulation beginning at the first iteration.

Model Name The name of the model used internally by Repast Py during compilation.The java class created by Repast Py uses this name and normally it need not be changed.
Fields See the the Fields section of the help docs for information on creating and editing fields. Here you can define any fields you want your model to have. RepastPy will create the following implicit fields for each agent component in the project.
  • groupNameNumAgents where groupName is replaced by the agent component's group name. This is the number of agents of this type to create.

  • groupNameSpace where groupName is replaced by the agent component's group name. This is the space that the agents in that group inhabit. See the section on implicit fields below for more on the properties of this space.
Schedule See the schedule help and tutorial 3 for more information on the schedule property. The schedule property defines the execution schedule of any actions defined in your model.
Space Height The height of the space associated with this grid model. The height refers to the number of grid cell rows in the space.
Space Type The type of space, either a 2-dimensional grid or 2-dimensional torus. The torus differs from the grid in that its sides are considered to be adjacent forming a "doughnut" topology.
Space Width The width of the space associated with this grid model. The width refers to the number of grid cell columns in the space.



Implicit Fields

Implicit Fields are variables that the Repast Py exposes for your use in code. For example, if there is an implicit field named agentGroup, you can refer to that field with self.agentGroup in your NQPy code.

Name     Description
Agent Groups For each type of agent that you create, Repast Py creates a DefaultGroup (a Java class) that contains all the agents of that type. The name of this variable is the value of the Agent Component's Group Name property. For example, if the group name is "agents" then Repast Py will create a Default Group called "agents". You can access this group from within model actions with self.groupName (e.g. self.agents). These groups are also exposed via a "get" accessor method. So, assuming you have a reference to the model, you can do something like model.getGroupName() (e.g. self.getAgents()). A Default Group in general behaves much like an indexable list. So, you can do things like

agent = self.agents.get(3)

to get the third agent in the list, and

numAgents = self.agents.size()

to get the size of the Default Group and so on.

groupNamespace For each agent component in the project, RepastPy creates a space field variable. The name of that variable is the agent compoment's group name followed by "Space." This space variable is an Object2DGrid (a Repast java class) that represents the grid or torus topology. You can reference this from within your NQPy code with self.groupNameSpace, for example, self.agentGroupSpace. The Object2DGrid has a variety of methods which are explained in the RePast API documentation. The most important of which are described below.

getMooreNeighbors( int x , int y , boolean ) : Vector - a vector of objects (and possibly nulls) ordered by row starting with the "NW corner" and ending with the "SE corner."
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.

getMooreNeighbors( int x , int y , int xExtent , int yExtent , boolean ) : Vector - a vector of objects (and possibly nulls) ordered by row starting with the "NW corner" and ending with the "SE corner."
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.

getObjectAt( int x , int y ) : Object
Gets the object at (x,y)

getSizeX( ) : int
Gets the size of the x dimension.

getSizeY( ) : int
Gets the size of the y dimension.

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

getVonNeumannNeighbors( int x , int y , boolean ) : Vector - a vector of objects (and possibly nulls) in west, east, north, south order
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.

getVonNeumannNeighbors( int x , int y , int xExtent , int yExtent , boolean ) : Vector - a vector of objects (and possibly nulls) in west, east, north, south order with the most distant object first.
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.

putObjectAt( int x , int y , Object ) :
Puts the specified object at (x,y)

putValueAt( int x , int y , double ) :
Puts the specified double at (x,y)

For example, if you want to insert an agent into the grid at a particular x, y coordinate you would do the following:

o = self.space.getObjectAt(x, y)
if (o):
  self.space.putObjectAt(x, y, agent)

The first two lines check to make sure that the grid cell at the x,y coordinate is unoccupied. If so, then the agent is place in that cell.



Java Parent Class

Many of the RepastPy components are based on Java code. What this means is that these components come with built-in fields and methods inherited from their Java parent classes. The docs below describe these built in fields and methods.

Grid Model is based on SimModelImpl. SimModelImpl is a partial implementation of the SimModel interface. Most, if not all, actual models will inherit from this class. By default SimModelImpl initializes the random number generator in the Random class using the current timestamp as a seed. Random can then be used for random number generator. If you need to have two random number streams with different seeds, you'll need to make your own. See the random number how to in repast/docs/how_to/random.html for more information. When data is collected from a model, it is this seed for this rng that is written out.


The fields of a Java parent class can be used just as if they were fields in your own model. For example, self.descriptors and so on. The format used below is

field name : field type
description

where the field type is a Java class type.

Java Parent Class Fields
descriptors : Hashtable
Used to store property descriptors. The key should be the property or parameter name and the value the descriptor associated with that property.

modelManipulator : ModelManipulator
A ModelManipulator that can be used to manipulate the model at run time.


The methods or actions of a Java parent class can be used just as if they were actions in your own model. For example, self.setRngSeed(33) and so on. The format used below is

method name(argument types, if any) : return type - an optional explanation of the return type
description

where the return type is a Java class type.

Java Parent Class Methods (Actions)
addPropertyListener( PropertyListener ) :
Adds a PropertyListener to this model.

addSimEventListener( SimEventListener ) :
Adds a SimEventListener to listen for SimEvents broadcast from this model.

clearMediaProducers( ) :
Clears the vector of media producers.

clearPropertyListeners( ) :
Clears the list of PropertyListeners.

fireBooleanPropertyEvent( PropertyEvent ) :
Broadcasts a boolean property event to all this model's PropertyEventListeners.

fireEndSim( ) :
Broadcasts a SimEvent with an id of SimEvent.END_EVENT to all this model's listeners.

fireNumericPropertyEvent( PropertyEvent ) :
Broadcasts a numeric property event to all this model's PropertyEventListeners.

fireObjectPropertyEvent( PropertyEvent ) :
Broadcasts an object property event to all this model's PropertyEventListeners.

firePauseSim( ) :
Broadcasts a SimEvent with an id of SimEvent.PAUSE_EVENT to all this model's listeners.

fireSimEvent( SimEvent ) :
Broadcast the specified SimEvent to all this model's SimEventListeners

fireStopSim( ) :
Broadcasts a SimEvent with an id of SimEvent.STOP_EVENT to all this model's listeners.

fireStringPropertyEvent( PropertyEvent ) :
Broadcasts a string property event to all this model's PropertyEventListeners.

generateNewSeed( ) :
Generates a new seed for the random number generator using the current timestamp.

getAgentList( ) : ArrayList
Gets list of agents controlled by this model.

getController( ) : IController
Gets the BaseController associated with this model.

getMediaProducers( ) : Vector
Gets the mediaProducers registered with this model. The returned vector will contain a ProducerNamePair objects.

getModelManipulator( ) : ModelManipulator
Gets the ModelManipulator.

getParameterDescriptors( ) : Hashtable
Gets a hashtable of ParameterDescriptors where key is parameter name, and value is the ParameterDescriptor.

getPropertiesValues( ) : String - a list of the model parameters and values.
Gets a String listing the model parameters and values. For example, <pre> MaxVision: 3 MaxMetabolism: 4 NumAgents: 52 </pre>

getRngSeed( ) : long
Gets the current random seed.

getTickCount( ) : double
Gets the current tick count

pause( ) :
Pause the simulation.

registerDisplaySurface( String , DisplaySurface ) :
Registers a DisplaySurface with this model and associates it with a particular name.

registerMediaProducer( String , MediaProducer ) :
Registers a MediaProducer with this model and associates it with the specified name.

removePropertyListener( PropertyListener ) :
Removes a PropertyListener from this model.

removeSimEventListener( SimEventListener ) :
Removes a SimEventListener from the list of listeners listening for SimEvents broadcast from this model.

setController( IController ) :
Sets the controller associated with this model

setRngSeed( long ) :
Sets the random number generator in Random to a new value. Note this will invalidate any distributions created with Random. These will need to be recreated.

stop( ) :
Stops the simulation.