Swarm provides a standard class (Discrete2d) for implementing a discrete, 2-D, space, with an arbitrary object (or nil) in each cell. This class does not provide for any special treatment or handling of the boundary of this space. A subclass of this, Grid2d adds functionality to check that a new object is not inserted in the space overwriting a previous object. The sample heatbugs application uses this class, and additionally imposes a toroidal topology. The calculations for the latter are carried out in the heatbug agents; because these calculations are rather frequent, the size of the space is cached in the agents.
In SCL I wanted both this toroidal topology, and also the restriction to at most one agent (particle in my case) in any single cell. However, the approach in SCL is somewhat different--indeed, it takes an almost diametrically opposed approach to where to locate these functionalities.
First, instead of locating the calculations for the toroidal topology in the agents, I developed a new space class, DiscreteToroid, subclassed from Discrete2d, which offers explicit methods for adjusting (wrapping) co-ordinates appropriately. I consider this preferable, because the space object is the appropriate object to ``know'' how to deal with co-ordinates that go outside the defined boundaries. However, it does mean sacrificing some performance compared to the heatbugs approach. In my particular case, performance has not been a problem, so this was a reasonable change; it would not necessarily be so in other models.
Secondly, instead of having the space attempt to restrict occupation of any cell to one object at a time, I embedded this functionality in a new agent class, Agent2d, which became the superclass for all particle classes. Agent2d also encapsulates a lot of other ``generic'' functionality for agents in a 2D space--at least where interactions are local (in the von Neumann or Moore neighborhoods), and include movement by swapping. Agent2d may thus be useful in other models, quite different from SCL. Agent2d functionality is layered, in part, on top of two other new agent classes, VNneighbor and MooreNeighbor which provide support for co-ordinate calculations within these particular neighborhoods.
Copyright © 1997 All Rights Reserved.
Timestamp: Tue Dec 31 19:40:38 GMT 1996