Genetic algorithms for a self-contained ecosystem.
Evolution
is a repository for simulating populations with genetic algorithms. It primarily runs in Python, and can be used as a teaching element to display how populations change with time.
- Install VsCode
- Install (Github Desktop)[https://docs.github.com/en/desktop/installing-and-configuring-github-desktop/installing-and-authenticating-to-github-desktop/installing-github-desktop]
- Fork this repository
- Open in VsCode
- Start a new Terminal in VsCode
- In
notes.md
run the following. This will download and install the latest dependencies in a virtual environment.
python -m venv venv
venv\Scripts\activate
python -m pip install --upgrade pip
pip install -r requirements.txt
- Run the file
World.py
insrc\World\World.py
Sprites
These are sprites. They represent single entities in the environment. The actions that the entities are performing can be seen above the sprite. In this case, this entity is moving upward relative to the surrounding screen.
Environment
The environment is a collection of sprites and their actions. Every year
or turn
the sprites can perform exactly one action. During this action period, they may fight, mate, move, rotate, or make another decision, this is reflected in the console, and on the corresponding display.
- How are the sprites able to make decisions, and how do these decisions change as the generations and years increase? The sprites are able to make decisions based upon their initialized genetic code. Their genetic code is first set at random, and then every subsequent generation contains the offspring of the survivors of the last generation. The genetic code is in hexadecimal which is then decoded into a binary string. The binary string is further decoded into weights for a neural network - this neural network allows each sprite to make a decision based upon its environment.
- How does the sprite know what is going on around it? If the sprite has a neuron which allows it to visualize, or take information, from the environment in the form of direction, proximity, or more -- then it will utilize that information in the neural network input.
- How is the sprite look determined? At this moment the sprite is created based upon flipping the binary representation of the first hexadecimal section of its genetic code. Therefore offspring, and parents of the offspring, all look relatively the same.
- How are mutations handled? As the generations increase, offspring are created from the survivors. During this mating process, mutations are incorporated into their genome, this can be used to solve a problem faster - or to encourage diversity in a population.
- What do the symbols above each sprite represent?
The symbols above each sprite represent the action that the sprite is performing. If it is moving upward, you will see an upward moving arrow. If it has turned into a
plant
then it will have a grass icon above its representation.
- What is the shape of the environment? At the moment, the shape of the environment is a rectangle. This may change in the future.
- Can I remove the edges of the environment and allow for overlap?
Yes, this can be done in the
src\World\Entity\status.py
file, this location will change in the future. - Can I add obstructions to the environment? Not at this time, though that will be planned for the future.