Agent Based Model

As part of our Programming for the Social Sciences module, we had an intensive python course at The Leeds Institute for Data Analytics in September. The week involved learning how to produce a simple Agent Based Model (ABM), which is a model designed to simulate autonomous agents and their actions/interactions with each other. These can be used to understand patterns and behaviors in areas such as crime and crowd behavior.

We created a simple model where the environment data is loaded in, and then the ‘sheep’ agents eat through the environment and share their resources with other ‘sheep’ agents. I also tweaked the model so that ‘wolf’ agents were also added to the mix, which would pray on the ‘sheep’ agents. The model is split into three scripts; one for the model itself, and then a separate script for the sheep and wolf classes which are then imported into the main model.

The sheep class contains 4 functions; to either move, eat, share resources or check whether they have been prayed upon by a wolf. This could be improved by having the sheep check the area for wolves and be more likely to move away from them, or to be more likely to move towards areas with more grass. Here’s the functions below.

Here’s the update function for the model, in it the sheep and wolf agents functions to move, eat and share are called, as well as plotting the new position of the agents and sorting between the ‘dead’ and ‘living’ sheep. When a sheep-agent’s store is taken down to below 5, it’s status is marked as ‘dead’ and then the function checks that the status variable equals ‘dead’.

I also installed ImageMagick, which is software which allows bitmap images to be quickly read, edited and rewritten through PythonMagick. This allowed me to quickly create animations in matplotlib and then save them to .gif files.

While a good starting point, the sheep and wolf agents would benefit from improved behavioral patterns. At the moment all the agents movement is randomized, where they could have a higher probability of moving towards a food source. It would also be interesting to see the agents have more behaviors in which they can exhibit. This could be the sheep’s behavior changing depending on whether they are ‘full’ or ‘hungry’, and make it so movement also costs energy from the sheep’s store.

For the full project, visit my GitHub here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s