Repast suggests an architecture to be used while designing a simulation. Basically every simulation is divided, in it's simpler form into a Model Object and an Agent Object.
While this shows how Repast is organized in it's basic structure, does little in aiding the design of a robust architecture.
The way we're organizing our simulations is as follows:
Model Object
ModelBuilder Object
Space Object
Agent Object
The Model must define the parameters of the simulation and works a central point in all the process. So this connects the Agents with the Space and both with the parameters defined by the user. It also specifies the schedules for the different actions of the Agents.
The ModelBuilder encapsulates a set of operations within the Model. The point of this separation is that the set and get of parameters is a quite extensive block of code. We reserve the Model Object to this operations.
The get and set operations works as the Java standard get and set operation. If we have a integer variable named fooBar, it should have the corresponding get and set operations:
public int getFooBar()
public void setFooBar(int i)
Note the capitalized F in the name of the function and uncapitalized f in the name of the variable.
So the model has, besides the get and set operations:
- a setup() function, defining what should be performed (independently of the user set parameters) in order to allow the construction (build) of the Model.
- a begin() function, defining what should be built (dependably of the user set parameters).
These two functions are required by the platform and are attached to the buttons on the interface. This is why one must setup and then initialize every time the simulation is started.
The 8th button is the setup button. It's attached to the setup() function.
The 5th button is the initialize button. It's attached to the begin() function.
Actually, the first time a simulation is played it only needs to be initialized. This gives another perspective of the setup() function. It's supposed to tear down the model. This means it should destroy every instance that is going to be set in the begin() function later on.
We actually make every instance null, after an eventual dispose() operation and call the System.gc(). This forces the garbage collector to clean up and free memory. After this we create the required new instances. Note that the space is not usually destroyed/created here. Here we manage the Agents data structure, the Schedule and the eventual displays. The space has it's own set of operations.
So the begin() function is pretty complex. It involves building all the main components of the model. These are the Space, the Agents, the Schedule and the Displays. This requires four different operations, namely:
buildSpace()
buildAgents()
buildSchedule()
buildDisplay()
The ModelBuilder was thought specifically because of these operations. The begin function looks as something like this:
public void begin() {
builder.buildSpace();
builder.buildAgents();
builder.buildSchedule();
builder.buildDisplays();
}
The everything is set on the builder. This is only for organization purposes. Good practice anyway.
More to follow!
Tuesday, July 10, 2007
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment