Inspiration
Life, as we know, is all around us. It lives, it grows, it learns, it adapts, it overcomes. And for what? Some say the purpose of life is emotion, some say experiences, some say altruism, some say egoism. Frankly I don't think talking about it does anyone a whole lot of good. I say, what better way to experience life than to watch it?
It's remarkable - give a bunch of hydrogen atoms some rules about physics and a whole lot of time, and look what comes out! Why can't we do the same with computers? We know how to program physics, we know how to represent sensors, we know how to move joints... Seems like we could get a pretty interesting simulation up and running! After all, it's the sheer simplicity of Darwin's theory of Evolution by Natural Selection that makes it so incredible. Life, by its own living, and with no conscious thought nor volition nor sense of need nor act of God, can progress by leaps and bounds, marching ever onward toward the future with what can seem like truly sentient determination. No matter what challenges its environment throws at it, you can rest assured that life will find a way to not only survive it but master it. Life is limitless; Infinite diversity in infinite combinations, as the Vulcan philosophy puts it.
So it is with this inspiration a project was born! We shall build a Multi-Environment Natural Darwinistic Evolution and Life Simulator. Let's get to it! Let's make a simulator that puts virtual creatures in a virtual environment and watches them evolve. Let's make a whole ecosystem while we're at it, with multiple agents evolving simultaneously! Let's have food, and health, and sexual reproduction, and different bodies and brains and behaviors! Forget about aquariums and ant farms, just think of the endless possibilities we could explore in our very own virtual worlds! So let us embark on this journey, a journey as personal as it is technical, and hope we are made better as a result of it. Let us go forth and be fruitful, that our offspring (computerized or otherwise) may go forth and be fruitful in turn.
How it works
So enough with the dramatic reading, I bet you're all anxious to dive into the details.
Before we proceed, I must express my sincerest thanks to Lee Graham, whose PhD thesis on Exaptation and Evolutionary Computing [https://curve.carleton.ca/system/files/theses/27733.pdf] was an invaluable resource. Of particular relevance to this project is the 3DVCE program he developed as part of his research. I've been fascinated with 3DVCE for years, and it has served as a major inspiration in both this project and others.
As the name implies, the Multi-Environment Natural Darwinistic Evolution and Life Simulator (MENDEL-Sim) is a simulator that brings creatures to life in a virtual environment and allows them to adapt and evolve over time. The name is inspired by Gregor Mendel, whose work with pea plants pioneered the fields of heredity and genetics.
For those among you familiar with genetic algorithms/evolutionary computing, the premise of a single-agent simulator is simple: 1. Create many random creatures for the starting generation 2. Simulate the creatures in the environment and score them by some metric 3. Use the scores to choose winners in each generation, that breed, combine, and mutate to form the creatures in the next generation 4. Repeat steps 2-4 ad infinitum
A multi-agent simulator, on the other hand, would be more like an aquarium where many different creatures are all existing and evolving simultanously. This is a considerably more complex challenge, so given the limited time in this hackathon, MENDEL-Sim did not attempt it. However, it would be a novel and extremely interesting addition to the project!
We decided to use Unity3D [http://unity3d.com], a free and popular game engine, to build our project on, since the game engine provided a ton of cool features and took away all the boring boilerplate involved with setting up a game and let us instead focus on making it behave better. Unity3D in particular provides us with the excellent PhysX physics engine from Nvidia, which gives life to collision detection, gravity, joints, and pretty much everything else.
This project could be very open-ended so we decided to start with a single-agent simulator that just created and scored one creature at a time. The creatures bodies are composed of segments organized into a tree, with every body segment having zero to four child segments, each attached to the parent segment by a movable joint. Each segment can be any arbitrary 3D model, but for easier programming the bodies in this project are composed entirely of cuboids.
The joints are the creatures' way of locomoting through the world, as each joint has two servo motors that can be used to control the joint's movement. This naturally leads to the development of the creatures' brains, which provide a mapping of creature inputs (sensors, time, sine wave generators, constant values, joint proprioception, etc) to creature outputs. As opposed to using a standard mathematical function or neural network, the brains in MENDEL-Sim are composed of Genetic Programming Expression Trees. These Brain-Trees are similar to LISP S-Expressions, where the tree is composed of many expression nodes, some terminals (just returning a joint angle or a constant value) and some composites (that add the input, or square it, or take the sine of it). Several of these Brain-Trees are constructed for each body segment, and their outputs feed into the joint motors for that segment. These trees are very flexible in their ability to represent complex expressions, and by nature of their being trees they lend quite naturally to breeding/merging/mutation.
An essential component of a evolutionary creature simulator is the ability to take creatures and have them sexually reproduce - that is, to create a new creature that is in some sense a combination of the two parents. Because the bodies and brains are both trees, this comes naturally. To merge two trees, we can simply pick and choose different nodes and subtrees from each parent, perhaps deleting a node here, or adding a node there, or modifying a node's parameters over there. The resulting trees behave nicely and as expected, without any additional configuration.
The first generation is created randomly. Random body segments and random brains to go with them are generated recursively to provide the initial genetic diversity need for proper evolution. To simulate the breeding at the end of a generation, each creature is reproduces sexually. Every creature in generation N+1 is created by merging two fit parents chosen via tournament from generation N. A number of creatures from generation N to form a tournament, which is a fair bit smaller than the entire generation size to stimulate genetic diversity. Within the tournament, a winner is chosen based on whichever creature scored the highest as ruled by the scoring metric for the simulation. This tournament selection happens again and the two tournament winners get together and do what comes naturally.
When running MENDEL-Sim, the user will provide several parameters to the simulation: the generation size, the tournament size, and the scoring metric. The generation size is the number of creatures that are created per generation. The tournament size is the number of creatures from generation N that are placed into a tournament to determine the winners for breeding to create the creatures in generation N+1. The scoring metric is a way of evaluating the creatures to give them a numeric score based on their performance. Current implemented scoring metrics are distance, which measures the distance the creature travels from the starting point, and height, which measures the distance the creature jumps off the ground.
With proper configuration of the parameters, a lot of patience, and a little luck, you can watch the creatures evolve before your very eyes!
Challenges we ran into
Unity3D, the game engine we used to develop the actual physics and visualizations, can be very moody at times. The UI is finicky and hard to get right. It took us a long time to get the joints working properly, and at this point they're mediocre at best. There's a lot of work that can be done toward improving the behavior of the joints. It was also more difficult than anticipated trying to merge creatures to simulate sexual reproduction. It's easy to make creatures that are worse than either parent, or impossible altogether as limbs have a tendency to cross into each other. Apart from that, we were very pleased with the progress we were able to make in such a short time. It's further evidence that simple ideas can produce astounding results.
Accomplishments that we're proud of
The project has been a great success. In the course of just two days, we went from lofty concepts and loosely-defined ideas to having a working evolution simulator. There's no feeling like seeing the results of your programming work literally come to life and dance around in front of you. And the BrainTrees were particularly fun to work on!
What's next for MENDEL-Sim
Development ahoy! There's a feature list as big as can be, since there's so much awesome stuff that can be done with this idea. Adding more environments, different body types, new physics like aerodynamics and swimming, and different scoring metrics are all things that can be readily achieved. Getting it working with multiple creatures simultaneously is also a huge goal that would be astounding to achieve. I'd like to open-source the code so that others can contribute to improving this simulator or making their own. I wouldn't mind having a server farm where we could simulate whole ecosystems 24/7. Think of the research value, the entertainment value, the market value! It's as limitless as the creatures themselves. Maybe it'll even be used in high school biology classes someday.
Log in or sign up for Devpost to join the conversation.