Experiments in Artificial Life Part 1

June 01, 2017

Around the time of the dot-com collapse I talked with a local Computer Science professor about going back to school and getting a PhD in CS but after some discussion he dissuaded me from trying, basically he said schools didn’t want students as old as I was (early 40’s) and that the market for CS professors was limited. Of course this was before Google and others started hiring PhD’s in droves. Oh well.

After graduating from college with a BS in Chemistry I had been accepted for a PhD in Chemistry but declined as I didn’t want to go to school forever. Two chances not taken sadly.

What I wanted to study in CS was artificial biological systems, ways of constructing biological environments entirely in software to study how natural systems may have come about. Part of this area is often called artificial life, although that seems to have become less popular these days as AI and machine learning have become more interesting to study. In any case I’ve decide to play around with this despite my lack of time—sometimes you have to work on something completely unrelated to work so as not to get stuck in a technological rut.

Normally I do iOS in Swift but for this project I will be using Swift with Metal on OSX. I really like working with Swift, after years of Objective-C, C++ and C I find it a very expressive and pleasant language to work in. Xcode still stinks a lot, but that’s another post for the future!

I want to work on a fairly simply “critter” which has 5 genes that relate how each critter desires or dislikes the company of other related critters, how far they are willing to look for one, how far they are willing to look for food, and how fast they are willing to move to either friends or food. Moving and looking will cost fixed energy which is collected by eating “food” that is randomly strewn about (and may provide a dimension to play with). A 6th gene will determine how much energy is required to split into two, with a fixed minimum. The split gene total can be anything above this amount, allowing for any excess to be split by the “children” as a starter bit of energy.

This set of genes seems sufficient to discover what types of “critters” will evolve: my theory is some will evolve to seek food, some will evolve to follow them around but contribute little (freeloaders) and some will evolve that will actively seek to avoid others and hoard food for themselves. I have no idea how this will work out in practice, but it should be fun trying. Assuming I get this work I have ideas for expanding on the genome.

I have the basic Metal code working to draw “critters” in the world. My intention is to find a mapping from the gene values to an RGB color so I can see similarity. So far I have not found the right way to do this.

The performance challenge is to find neighbors for each “critter” in a dynamic environment. Each one will be moving each iteration but will keep a bubble (the distance willing to look for each other or food). Building this to support 10,000 or 100,000 critters is hard. So far I have a decent sparse data structure that seems to work, but I have found no really good algorithm yet to perform this many neighbor searches in a dynamic world. I might find some way to use a Metal compute shader but its not too clear yet how to organize the data to make this performant.

In any case it’s fun to work on something completely useless yet difficult. Perhaps if I can make it do something interesting I will put it on github.