A lightweight, bare-metal Genetic Algorithm implementation written in pure C. This project was developed to explore evolutionary computing principles, focusing on high-performance logic and cross-platform consistency.
This program simulates an evolutionary process where a population of "players" attempts to evolve a specific sequence of binary moves to match a target goal array. Unlike standard implementations that rely on OS-specific random libraries, this project implements a custom Xorshift32 pseudo-random number generator to ensure identical behavior across different operating systems (Windows/Linux) and to maintain high performance in resource-constrained environments.
- Bare-Metal Logic: Zero dependencies on external libraries (pure C standard library only).
- Deterministic Randomization: Implemented a custom Xorshift32 algorithm to replace standard
rand(), ensuring portability, speed, and better statistical distribution of bits. - Efficient Memory Management: Manual heap allocation and management (
malloc/calloc/free) for dynamically sized populations and move sets. - Performance Focused: Built for scalability, utilizing bitwise operations and efficient sorting algorithms (
qsort) to handle population evolution.
genetic_learning_algorithm.c: Core logic, evolution loop, and implementation of the Xorshift PRNG.genetic_learning_algorithm.h: API definitions, data structures, and project configurations.Makefile: Automates the build process for different environments.
This implementation demonstrates a deep understanding of:
- Memory safety: Manual heap management and avoiding memory leaks.
- Computational efficiency: Writing low-level logic that minimizes CPU cycles.
- Cross-platform development: Solving platform-specific inconsistencies in standard libraries through custom implementations.
Ensure you have gcc and make installed.
# Build the project
make
# Run the simulation
make run
# Clean build artifacts
make clean