A genetic algorithm simulator that models population evolution through natural selection, crossover, and mutation. Built as a C++ educational project demonstrating Darwinian evolution principles.
Darwin reads an initial population of individuals from an input file, where each individual has a chromosome represented as a sequence of natural numbers. Over a specified number of generations, the program applies:
- Crossover – pairs of individuals exchange genetic material to produce offspring
- Fitness evaluation – individuals are scored based on chromosome properties
- Selection – weaker individuals are eliminated and stronger ones reproduce
The result is a final evolved population written to an output file.
Darwin/
├── Darwin.cpp # Full version of the simulator
├── Darwin LITE/
│ ├── DarwinLITE.cpp # Lightweight version
│ └── inFile.txt # Sample input population
├── doxygen/
│ ├── html/ # Generated HTML documentation
│ └── latex/ # Generated LaTeX documentation
├── inFile.txt # Sample input population
└── README.md
Compile with any C++ compiler that supports the C++ standard library. The full version uses the Windows API (<windows.h>) for colored console output.
g++ -o Darwin Darwin.cppFor the lightweight version:
g++ -o DarwinLITE "Darwin LITE/DarwinLITE.cpp"./Darwin -i <input_file> -o <output_file> -w <extinction_coeff> -r <reproduction_coeff> -p <generations> -k <crossover_pairs>
| Flag | Description | Constraints |
|---|---|---|
-i |
Path to input file with initial population (.txt) |
Required |
-o |
Path to output file for final population (.txt) |
Required |
-w |
Extinction coefficient | 0 ≤ w ≤ 1 |
-r |
Reproduction coefficient | 0 ≤ r ≤ 1 |
-p |
Number of generations to simulate | p ≥ 1 |
-k |
Number of crossover pairs per generation | k ≥ 1 |
./Darwin -i inFile.txt -o outFile.txt -w 0.4 -r 0.7 -p 3 -k 5Each line represents one individual. The line starts with the individual's number followed by a sequence of space-separated natural numbers forming its chromosome:
1. 164 790 402 529 678 250 752 740
2. 580 74 490 374 452 376 414 652 18 132 862 144 781 790 67
3. 101 781 578 585 615 754
API documentation is available in the doxygen/ directory. Open doxygen/html/index.html in a browser to view the generated HTML documentation.
Krzysztof Koźlik – November 2020