Natural Selection Simulator

View on GitHub   GitHub


EvoNoodles is a natural selection simulator that looks at creatures, known as noodles, as they evolve in a environment competing for resources and surviving in the presence of predators.

Simulation

Noodles

Noodles are simple, (mainly) vegetarian creatures which search for food in their nearby enviornment. They attempt to find food at all times to replenish their health, with the goal of reproducing. Food appears regularly in their environment, or at the location of a dead noodle which they will also eat.

They have a chance at reproducing after a certain number of timesteps, where they produce a genetically similar offspring that potentially has a mutation in their DNA to differ in a single trait from their parent.

All noodles start with these attributes, which are randomly chosen in the following ranges:

AttributeDescriptionRange
Sizesize, max health=size*206 - 10
Speedhow fast they move1 - 4
Sightrange of vision30 - 200
Viewdegree angle of vision40 - 240
Reproduction% chance of reproducing15 - 35

These attributes all contribute to the loss function of a noodle, or how much energy they consume per timestep. The function can be edited to favor certain attributes over others, but the default function that allows for stable populations is:

loss = size*2 + speed*3 + sight/2 + view/3

Preds

Preds are the predators of the environment, with their prey being noodles. Preds are also smart creatures, which gives them two distinct advantages:

Their default starting attributes are also slightly different, with greater size, speed, and range of vision, with a much narrower vision angle.

Development

I started with green, circular blobs that I called noodles. The noodles started by moving around a map looking for food, which I implemented with a simple food-seeking algorithm where noodles moved towards the closest food with a certain velocity. When they reach the food, they would “eat” it by removing it from the list of foods, and a new food would be added in a random location.

Next came giving the noodles the gift of sight; I planned on them competing for food and evolving their attributes which would include vision. The first step was to give noodles a range (variable: sight) of how far they can see food. Then they are assigned a viewing angle (variable: view) which dictates the angle they can see with relation to their velocity. This was implemented by calculating the points on an arc given a noodle’s range and view and rotating that arc with respect to the noodle velocity.

A boundary detection method was added to noodle movements to constrain them to the environment limits. Noodles will move in a random direction away from boundaries to help make noodles not get stuck.

A smooth turning function was added to give the noodles more realistic movements. Their sight, view, and other attributes of size and speed are now all be randomized to give a hetergeneous starting population. There is a countdown for adding new food if multiple foods are consumed within a short timespan, which helps prevent population explosions. There is also a chance of a new, random noodle immigrating to the local environment every few thousand timesteps, to introduce more diversity.

An energy loss function was added which can be changed to give greater importance to certain attributes, but the default is:

loss = size*2 + speed*3 + sight/2 + view/3

Noodles will die when they run out of health and leave behind a new food object which is proportional to their size. A noodle’s size also affects its health - their maximum health is size*20. A noodle who is size 4 will only have a maximum of 80 health compared with a size 10 noodle with 200 health, but the smaller noodle will also lose health less quickly.

A health color function was added which shows noodles turn from green to red the closer they get to losing all health.

After observing how noodles evolve competing with just each other, the next step was to introduce a predator. Preds are blue triangular hunters, which use the same creature class as the noodles, except they only eat noodles.

They have been given a slightly different range of starting attributes to encourage a stable but diverse population:

AttributeDescriptionRange
Sizesize, max health8 - 12
Speedincreases velocity3 - 5
Sightrange of vision200 - 400
Viewdegree angle of vision20 - 80
Reproduction% chance of reproducing25 - 45

Notable differences are that predators are bigger, faster, and can see further but with a greatly reduced range of vision, mimicking the way predators have eyes on the front of their head instead of the side like prey.

The other important difference is that they are “smart” creatures, since they are hunters and a smaller population. This means they

Examples of predators switching targets to a closer noodle, and ignoring noodles within their sight due to being satiated enough that they have full health can be seen above.

Dozens of simulations were ran over hundreds of generations to identify appropriate starting parameters, as well as to analyze the long term natural selection forces exerted on these populations.

View post-hoc Analysis page

Credit

This was inspired by papers I presented and did related work to in a course I took on probabilistic modeling for computational biology. I was specifically interested in neutral biodiversity theory, looking at Hubbell’s work as well as approaches to fit models to species abundance distributions. The interplay between speciation, extinction, and immigration inspired me to develop my own model of evolution on a small scale.

Relevant papers:

I also took inspiration from Primer Learning and MinuteLabs.io (https://www.youtube.com/primerlearning) and their work on creating evolutionary simulations to demonstrate basic principles of natural selection, and Luke Garbutt’s genetic steering algorithm (https://github.com/lukegarbutt).