The skeleton code provides infrastructure for reading and writing specifications for simulations. The specifications are encoded as XML documents.
If you are not familiar with XML, check out the Wikipedia entry. Basically, an XML document defines a tree of data. Each node in the tree corresponds to a tag, with a type and a list of attribute-value pairs. Nodes can be atomic, in which case there is a single tag marking the node description as complete. Or nodes can have children, in which case the node opens with a beginning tag, then continues with a nested specification of the node's children, then ends with a closing tag. XML is a convenient way to read in and out data because it's a standard, flexible format and java provides easy and efficient tools for reading it.
The XML reading code is located in the file FlockingReader.java. The code uses the SAX interface (see this quickstart guide), which processes each XML document incrementally and provides data from the XML file to an application using callbacks. In FlockingReader.java, the startElement callback does all the interesting work of creating and updating agents in the simulation.
In this project, the root node of the XML file is a world tag. It describes the complete simulation. Individual agent specifications are nested in groups (see below) and included as children of the world element. The world currently provides the following attributes:
If you just want to create a simulation and run it, you can nest the specification of the individual agents that you want to create directly within the world element.
However, there are two useful structuring elements that let you organize the specification of a world further.
In addition, there are two further elements that do not correspond to agents but instead describe how the world should evolve.
The skeleton code includes code you can look at and play with for five simple kinds of agents, most of which we have gone through during course lectures. These are:
In addition, the skeleton code includes stubs that you can extend for five more kinds of agents. The initial version of the XML reading code provides interfaces so your project will automatically read and write instances of these agents. Of course, nothing will happen yet! The behavior of these new agents is not yet defined! The tags for these agents are:
All these agents come with a range of attributes and values that you can set from XML. These are:
The input and output of these parameters are managed by nested classes FixedAgentAttributes and DynamicAgentAttributes in the file Agent.java.
Finally, certain individual agents have some additional parameters. The grazer agents have a parameter threshold that says how close in pixels they have to get to one food source before they move on to the next one. The flocker agents have a whole bunch of parameters that control the details of the flocking algorithm. These parameters are: