This repository contains a program created as part of a bachelor thesis at BUT FME. The aim of the thesis was to create a cellular automaton with rules generated by a genetic algorithm to find interesting behaviours and patterns.
![]() |
---|
Visualization of symmetry patterns in the Cellular Automata generated by the Genetic Algorithm |
To run the programs in this repository, you need to install the following libraries:
- numpy: For numerical operations and handling the cellular automaton grid.
- Install with:
pip install numpy
- Install with:
- opencv-python: For capturing and writing video frames of the simulation.
- Install with:
pip install opencv-python
- Install with:
- pygame: For rendering the cellular automaton simulation in a graphical window.
- Install with:
pip install pygame
- Install with:
- matplotlib: For plotting and saving graphs of simulation results.
- Install with:
pip install matplotlib
- Install with:
Ensure you have these libraries installed before running the scripts.
This script defines the CellularAutomaton
class, which simulates a cellular automaton on a grid.
Key features of this script include:
- Grid Initialization: Methods for setting the initial state of the grid, either randomly or with a single live cell in the center.
- Rule Application: Functionality to apply birth and survival rules to the grid to generate the next state.
- Fitness Functions: Various fitness functions to evaluate the performance of the automaton, including:
- min_count_alter: Minimizes the number of live cells while ensuring at least one live cell survives each generation.
- max_div: Maximizes the difference between two consecutive grid states.
- symmetry_fitness: Evaluates the grid for symmetry and interesting patterns.
- alternating_pattern: Looks for the development of a checkerboard pattern.
This script implements a genetic algorithm to evolve the rules of the cellular automaton defined in cellularAutomaton.py
.
Key features include:
- Rule Generation: Creates random initial rules for the cellular automaton.
- Fitness Evaluation: Uses the fitness functions from
cellularAutomaton.py
to evaluate each rule. - Selection Methods: Implements tournament and roulette selection to choose parents for crossover.
- Crossover and Mutation: Combines and mutates rules to create new generations.
- Evolution Process: Manages the entire evolutionary cycle, including elitism to retain the best solutions.
This script runs the genetic algorithm to evolve cellular automaton rules. It sets the parameters for the genetic algorithm, including grid dimensions, population size, mutation rate, and number of generations. It also selects the fitness function to be used and prints the best rule found along with the time taken.
This script handles the visualization of the cellular automaton simulation and records the process into a video file. It initializes the cellular automaton, applies the specified rules, and displays the simulation using Pygame libraries.
This script generates graphs to visualize the number of live cells over generations during the cellular automaton simulation. It initializes the cellular automaton, runs the simulation, and plots the results using Matplotlib libraries.
- cellularAutomaton.py: Defines the cellular automaton and its behavior.
- geneticAlgorithm.py: Implements the genetic algorithm to find optimal rules for the cellular automaton.
- main.py: Script to run the genetic algorithm.
- visual/main.py: Script to visualize the cellular automaton and record the simulation.
- graphs/main.py: Script to create graphs showing the number of live cells over generations.
- graphs/: Directory containing PDF files of the generated graphs.
- visual/: Directory containing video files of the simulations.