# Evolution 1

Up a level : Biology

Evolution simulation 1

On this page, you can find a simulation of a simple biological system. I have kept it simple to show that even an extremely simple system is enough to show the evolution of bacteria into different types.  The program is inspired by an article in Scientific American that I read somewhere in the 80s. I have not found the article though. The basis of the program is the Pascal program I still had left, translated to JS + maaaany things added that a modern computer can handle, but a computer of those days would be totally bogged down by.

The program is written in vanilla JS  without any external package added.

The Bacterium

You will have small bacteria in the environment, shown as small circular disks. Each bacterium will have an age, an amount of energy, and a direction of motion, and it contains four genes.

At each time step each bacterium will make one step. Each step costs one energy unit. If the energy level of the bacterium reaches 0 it will die – and it will be removed from the environment.

If the bacterium has survived for at least 500 steps, and if it has at least 1200 units of energy it will divide into two bacteria. One will retain the original bacterium’s genes, and one will possibly get a random mutation of one unit on one of its genes. The gene to be mutated is selected at random, and the mutation change, –1, 0 or 1 is also selected at random. Both bacteria will then start at an energy level of 500 units.

The bacteria have no sensors. The whole “behaviour” of a bacterium is governed by its genes and the age and energy of it.

The Genes

The genes present a distribution of probabilities for how the bacterium will move. The four genes represent, gene by gene:

• F, Forward: The relative probability of moving forward.
• R, Righ: The relative probability of turning 90 degrees to the right.
• L, Left: The relative probability of turning 90 degrees to the left.
• B: Backward: The relative probability of turning 180 degrees.

The genes can have values from 0 to 15. Say the genes for a particular bacterium have the values [2,3,1,4]. The sum is in this case 10. We can then imagine a 10-sided die is thrown. If the result is 1 or 2 it will continue forward, if the result is 3, 4 or 5 it will turn right, and so on. The gene value/the gene sum is thus the probability that the gene will be selected.

The colours of a bacterium depend on several factors. The colour of the edge is dependent on how much energy it has. The redder the more energy. The centre of the bacterium is coloured depending on the values of genes 1 to 3. (One can select between two colour pallets.)

The genes do not transcribe to any type of simulated proteins, instead, we only see the genotype, the set of values for the four genes, and phenotype, the behaviour and colour of a bacterium.

The Food and the Environment

The environment is presented as a black rectangle. Time ticks on at steps. In each step, a few pieces of food, shown as green dots, occur in the environment. Three are randomly placed somewhere in the environment,  three are randomly placed in a smaller rectangular area and two are placed in a little bit larger circular area. These values, as many others can be changed later on.

Each piece of food is worth 30 energy points. If two are placed at the same spot they are counted as one. The colour changes slightly though to make it look more dynamic. The colours are also slightly different in the three

There is initially only one bacterium with gene values in the range 2 to 6. The bacteria are larger than the food pieces, but the food is only counted as food if it is at the centre of the bacterium disc. It is then eaten, the bacterium will gain 30 energy units, and the food particle will disappear from the environment.

Initially, 11000 pieces of food are placed in the environment.

The environment forms a torus, i.e. the lower and upper edges are connected, and the left and right edges are connected. Any animal that moves past the edges will move to the opposite edge.

The controls and displayed information

On the top, you will see the number of steps that have passed, the number of bacteria and the most generations any single bacterium has had.

The buttons:

• Reset: Resets the run, but keeps the setup settings.
• Pause/Restart, or the Escape key: Pauses and restarts the program again.
• Single Step, or the S key: Make a single time step.
• Copy: Copy a list of the bacteria properties to the clipboard in a format suitable for Excel.
• Setup/Restart: This allows you to change quite many parameters of the simulation. The values are applied immediately as you Reset or Resume.
• Demo: Will start the game with some selected genes to show examples of what the genes do to the behaviour of the bacterium.
• Display Bacteria/Display Distribution/Display Scatter Plot: Toggles the information shown in the side panel.
• Colours: Change between two colour palettes.

The Side panel:

• Bacteria: Shows a list of the bacteria. For each bacterium you get its genes, the amount of energy and its age.
• Distribution: Shows a table of the genes and how many bacteria have a particular value of the gene in question.
• Scatter Plot: This will show scatter plots of all gene/gene pairs. It will mark the positions where any combination exists. The genes [3, 4, 2, 1] will, for example,  show up at the coordinates (3, 4) in the Gene F vs Gene R plot. The positions will show up as circles with areas proportional to how many bacteria have that particular combination of genes. To see all six combinations of genes  – (F, R),
(F, L), (F, B), (R, L), (R, B) and (L, B)  –  you have to use the scroll bar to the right in the side panel.
• The number of bacteria vs timesteps.

The Scatter Plot display may be the most informative. You can here see how the bacteria will split into different types. This usually shows up after some 100 generations or so. It usually spits in two types, but sometimes in three.

You may try to predict the most common gene combinations will be – and why, and also what values the different genes will approach – in particular gene 4.

You may also observe the patterns of motion of bacteria in the square where more food is created vs those bacteria that roam in the sparser areas.

This is also where the setup panel will be shown, and the demo information.

Selecting a bacterium

If you move the mouse pointer over the environment and click close enough to a bacterium it will be selected and shown in yellow. It will appear in boldface in the Bacteria list, and the corresponding circles in the Scatter Plots will be filled. If you click at a point where no bacterium is nearby any selected bacterium will be unselected.

You may also hoover the mouse pointer over any point in the scatter plot, and the bacteria corresponding to that data point will show up in yellow in the main plot.

A tip is to pause the program, and then select various bacteria. It is easier to choose one for inspection when they don’t move.

Suggestions

Try a different setup. Why not try with a Minimum age to divide at 50, Minimum Energy to divide at 30 and the Initial energy at 15?