|
From: Mark R. D. <mdi...@la...> - 2003-05-29 18:34:02
|
Ok, I know you guys have plans to rework the space library. In working on a project here at Harvard with Yuri Mansury, I managed to start some major refactorings to the space library to work with our simulation we're writing. I got a little out-of-hand late one night and this the result. I've just exposed this to the public on my sourceforge site. Please look it over, I feel its a step toward allot of the ideas that Gulya has proposed for a future refactoring of the space library using Context and Relation concepts. It may save some steps in getting there. http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/repast-jellytag/repast-jelly-taglibrary/common/src/java/uchicago/src/sim/space2/ The really important features to point out are the following. 1.) ObjectSpace effectively joins the IMulti2DGrid and Discrete2DSpace Interfaces into one Interface for all "Object2DSpaces". 2.) Neighborhooding has been completely separated from each space implementation. Hex spaces have been removed, the only difference between a Hex space and regular space is the Display and the Neighborhood, any space can be used as a Hex2DSpace when one uses the a HexNeighborhood and HexDisplay. 3.) ObjectLocation and Cell have been merged into one interface "Location". Object2DGrids use "SingleLocation", Mutli2DGrids use "BagLocation and OrderedLocation". Locations have x,y coordinates related to their storage point in the space. 4.) Neighborhooding is the biggest change, Neighborhood is a "Collection Like" Interface to a specific Location. The standard Moore, VonNeumann (and in the near future Hex) neighborhoods are different classes that can be instantiated over a specific Location. These Neighborhoods provide several "Iterators" over the grid to return "Locations" without actually building a Vector or List object, these can then be used to also build ArrayLists for when more complex iterations/decisions need to occur. There are 4 types of Iterators available for a neighborhood LocationIterator --> each object in the Iterator is a Location in the neighborhood (order is a clockwise spiral out from the origin). EmptyLocationIterator --> Extends the above iterator to only return empty locations OccupiedLocationIterator --> Extends LocationIterator and provides iteration over locations that only have objects stored in them. NeighborIterator --> Uses the above iterators to iterate over the objects themselves, using LocationIterator and the iterator for the List at each location, this iterates over the Locations handing back the objects. in the future I'm considering building a "RandomLocationIterator" and "RandomNeighborIterator" that randomly draws the locations/objects from the neighborhood without replacement when iterating. I believe these implementations provide a means to iterate over neighbors without having to build separate lists of those objects. I'm interested if this might provide a performance improvement in some simulations where iteration over neighbors occurs often, constantly building new Lists/vectors of Neighbors. 5.) Discrete2DAgent is an interface that can be implemented in Agents to make them aware of the "Location" they are in, this provides get/setLocationMethods, when adding an Object to Location, if the Object is an instanceof this interface, the Location "sets itself" as the objects Location when the object is added to that location. Finally, because it currently implements 'space.Cell' and 'space.Discrete2DSpace' They work with the current version of the RePast Displays. Diffuse and Double2DGrids are still a work in progress and will will probibly have separate neighboorhood implementations as they are optimized to work with DoubleMatrix and not NewMatrix. Please let me know what you think about this approach. -Mark |