Using packages
[Agent practical 5 of 9]


This practical we've covered the following key skills:

In addition, we've now finished our core ABM! We now have a model that exemplifies the following core ideas of ABM:

From now on, we're going to concentrate on the user interface and visualising information. We're going to look at how we read data into our model and display it, and how we display the running model and save the results. If you're not that into ABM, this will be the core code for building other kinds of model and analysis toolkits.

There's been a *huge* amount of code coming and going, so now is a good moment to stand back and think about how it all hangs together. Spend a bit of time examining the code you've written, and thinking about what the core elements are, and which are bits you could strip out to make your model (if you're making one). To help, here's our version of the code, fully documented:

and here's the javadocs. Note that the documentation also now includes a copyright and license statement. This may seem peculiarly formal, but it's an essential part of the Open Source ideal. Without a copyright statement, someone else could come along and claim ownership, sticking a license on that prevents you then using your own code. Once you have claimed copyright, you can then *licence* other people to use the code. For details, and suggested licences see the Open Source Initiative. We would strongly encourage you to Open Source all your code, if for no other reason than improving scientific reproducibility and public engagement. We'll talk about where you can store Open Source code in the next hacking session.

Note also that we've cleaned up the Model class so the constructor is easier to read, in the same way that we earlier divided up the run method in Nibbler. You may want to do this in your own code (though you're welcome to use the copies above in future practicals) as we'll assume from now on that the constructor for Model looks like this:

public Model () {

   buildWorld();
   buildAgents();
   runAgents();

}

You can always work around it by assuming the method calls are replaced by code, but it is just a cut and paste, and makes the code sooooo much easier to understand.

Note also the level of comments in the code and in the documentation. You should try and reach the same (or better!) level. Time spent commenting your code is *always* time well spent. It may seem like a waste of time, but a) if you have to pass on your code, it may be the only thing that saves another coder dumping it in the bin and reimplementing it, and b) you only have to come back to your own code after a couple of weeks to know that comments are really useful.