Linking Repast to another Java program

Repast is one of the leading software packages for agent-based simulation. It provides useful classes for building and controlling simulations and users can run their models using a graphic display or in batch mode. These functions are fairly straight-forward if you want to build a stand-alone Repast simulation but what if you want to integrate Repast within a larger modelling system? This tutorial will explain the problem and show a solution influenced by design patterns.

Read more

Fun with Pajek

I’m working on the conclusion chapter of my thesis at the moment. It’s meant to sum up the results presented in earlier chapters and then discuss wider questions in the literature and for policy. There are a couple ideas I’m working on, such as an ideal tariff for microgenerators and clarifying PV’s place within the context of other household energy conservation measures, but a basic concern is sorting out how PV households interact with other stakeholders within the PV industry.

I wasn’t really sure how to start answering this question until a friend told me about Pajek. It’s a bit of software that can be used to analyse large social networks and it will perform all sorts of calculations. The options can be a bit confusing though so I thought I’d start simple. I entered some data from my interviews and you can see the resulting plot below. The size of the dots represents the ability of each node to control the network (inverse of dyadic constraint if you’re interested).

UK PV actor network

This is only a first draft but reassuringly, some basic things like a strong connection between PV households, electricity suppliers and PV installers can be seen. It also seems to show that the DTI and Ofgem play a major role behind the scenes, framing the interactions of other stakeholders. This came out of the interviews as well but the advantage of the network graph is that it’s immediately clear that there is no direct link between households and these government agencies. So, for example, if we want PV households to become more active participants in the electricity network – i.e. exporting electricity at times when it’s good for the grid or generally reducing demand – then the graph suggests that perhaps a link between DTI, Ofgem and the households needs to be built. This might be achieved by developing a pilot programme with innovative metering and monitoring technologies, working in conjunction with the electricity suppliers and PV installers. As it happens, there has actually been talk of doing just that!

That’s a pretty rough sketch of course but I’m keen to play with Pajek a bit more and see what I else I might be able to find out.

HSQLDB

As I was saying last time, I’ve got quite a bit of configuration data used in the model and I couldn’t figure out a good way to access it quickly and without too much coding. After the EnumMap stuff (which works fine but gets a bit cumbersome if you try and do anything to fancy), I switched to a JDBC connection to Access. Again it works fine but because of how frequently the database needs to be checked, it ends up being really slow.

So I was poking around on the web trying to find a solution and came across HSQLDB. Bit of a mouthful I know, but it really is a fantastic solution to this problem. Why? Because it lets you create an SQL style internal database. That’s right – at the start of my model I load everything in from the Access database, make a copy of it in RAM using HSQLDB, and then use that copy for the rest of the model run. It’s really fast but any changes to the database are lost when the model finishes. At the moment that’s fine but I may add something to periodically write to file.

That’s another sub-version done. Things are coming along quite nicely.

Data storage and manipulation

I’m making good progress on the next version of the model, adding more configuration information for the initialization of household agents. However I’m having difficulty deciding on a common file format so that I can have just one or two methods for reading in files and parsing them into appropriate input. Some of my files have two or three columns, some labelled rows, some just single numeric values. In some ways it would be easier if everything was in a database but I kind of like using text files since it’s very easy to see what’s going on, add comments and share information – everyone’s got Notepad but not everyone has the latest MySQL setup.

But once the data’s in from the file I’ve got another problem about how to store it. At the moment, I’ve defined many of my finite data categories as enum types. For example, households can either be FAMILY or RETIRED. This works great in some respects: I can use the fast EnumMap to store data and it makes iterating very easy. Of course, enum’s are final static so if I want to expand the range of enum types I need to edit the source. Adding extra types also has implications for the text file inputs – again it might be easier if everything was done with databases since I could just add fields and so on as new data types are added.

Any thoughts on how might be the best way to manipulate this type of data? Am I going to have to bite the bullet and move away from text files?

Version 0.3 finished

Last week I finished the first version of my model and I’m pretty pleased with how it works so far.

There are twp issues worth noting though. JUnit was and is invaluable in developing the model but since my model uses a lot of random numbers it can be tricky to write the assert cases since you don’t know what the outcome of a particular method might be. To get around this, I’ve created dummy input files with binary (0 or 1) input data. Ordinarily these values would be a probability between 0 and 1 but with the test input, I know definitely what the model is doing at any stage.

The other one is that the model outputs its results to a text file as it goes along. This makes it kind of tricky to write a JUnit test. Perhaps there is some way of doing this but for the moment I just output everything to a file and look at it manually to see if the data makes sense.

PS In case anyone’s wondering about the version numbers. V0.1 was a dummy version, just playing around with Repast and Eclipse. V0.2 was a more serious attempt and had a few interesting features liking reading in input from a proper database (well Access…). I’ve tried to map out the version numbers so that they’ll make some sense, at least in hindsight. For the moment I’m planning on adding features to the basic model for the 0.3x releases. I think V0.4 will introduce the all of the remaining agents, though they may not be fully implemented.

Modelling load profiles

I’ve been trying to figure out how to model load profiles for different appliances. There are a few different approaches but the most sensible approach begins by assuming that, for an appliance to be used:

There are some different ways to allocate the precise timing but I think I’m going to simplify this approach. I’ll test it and then if that doesn’t work I’ll try something different.

Next Page →