Xholon - Stupid Model 5tg - Two or more Grids
What is it
This is a Xholon-specific version of the 5th in a series of 16 "Stupid Models". It's intended as a starting point for learning how to develop grid and agent-based models using Xholon. It can also be used to compare Xholon with other agent-based modeling tools that have also implemented the Stupid Model series.
The model includes three separate grids. Bugs in two of the grids migrate to the third grid whenever a bug tries to occupy an already occupied cell. Initially all the bugs, except for one in the third grid, are evenly divided between grids 1 and 2. The third grid starts to fill up fairly quickly.
Migration between grids is easy to do, because everything in a Xholon model is part of a tree structure, and any component can interact with any other component.
The move() method of BugStupidModel5tg.java implements the migration.
When the bug moves, it changes its class from Bug (BugCE) to DisplacedBug (DisplacedBugCE). This makes it easier to give bugs a different behavior once they move to the new grid. The move() method checks to see if the bug is of class BugCE. This could be done in a number of other ways, such as by using a variable called "state".
In GridPanelStupidModel5tg.java, the color of the bug is determined by its class. A Bug is a red circle, while a DisplacedBug is a blue star.
DisplacedBug is defined in StupidModel5tg_InheritanceHierarchy.xml, as a subclass of Bug.