genetic-algorithm-lib 1.0.0__cp310-cp310-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- genetic_algorithm_lib/__init__.py +29 -0
- genetic_algorithm_lib/_core.cp310-win32.pyd +0 -0
- genetic_algorithm_lib-1.0.0.dist-info/METADATA +576 -0
- genetic_algorithm_lib-1.0.0.dist-info/RECORD +6 -0
- genetic_algorithm_lib-1.0.0.dist-info/WHEEL +5 -0
- genetic_algorithm_lib-1.0.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Python bindings for the Genetic Algorithm framework.
|
|
2
|
+
|
|
3
|
+
This package is a thin wrapper around the compiled extension module ``_core``.
|
|
4
|
+
After installation, users should:
|
|
5
|
+
|
|
6
|
+
import genetic_algorithm_lib as ga
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
# The extension is expected to live at ``genetic_algorithm_lib._core`` in wheels.
|
|
13
|
+
# The fallback supports local non-wheel builds where it may be top-level.
|
|
14
|
+
try:
|
|
15
|
+
from ._core import * # type: ignore # noqa: F401,F403
|
|
16
|
+
except ImportError: # pragma: no cover
|
|
17
|
+
from _core import * # type: ignore # noqa: F401,F403
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def __getattr__(name: str):
|
|
21
|
+
if name == "__version__":
|
|
22
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
return version("genetic-algorithm-lib")
|
|
26
|
+
except PackageNotFoundError: # pragma: no cover
|
|
27
|
+
return "0.0.0"
|
|
28
|
+
|
|
29
|
+
raise AttributeError(name)
|
|
Binary file
|
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: genetic-algorithm-lib
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Genetic Algorithm framework with C++ core and Python bindings
|
|
5
|
+
Author: Rahuldrabit
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: C++
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering
|
|
12
|
+
Project-URL: Homepage, https://github.com/Rahuldrabit/Genetic_algorithm
|
|
13
|
+
Project-URL: Repository, https://github.com/Rahuldrabit/Genetic_algorithm
|
|
14
|
+
Project-URL: Issues, https://github.com/Rahuldrabit/Genetic_algorithm/issues
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# Genetic Algorithm Framework (C++)
|
|
19
|
+
|
|
20
|
+
A reusable C++ genetic algorithm framework you can embed in any application. It exposes a small, modern C++ API and ships with a rich set of crossover, mutation, and selection operators.
|
|
21
|
+
|
|
22
|
+
## 🚀 Features
|
|
23
|
+
|
|
24
|
+
- **Multi-Representation Support**: Binary, Real-valued, Integer, and Permutation representations
|
|
25
|
+
- **Comprehensive Operators**: 35+ crossover, mutation, and selection operators
|
|
26
|
+
- **Benchmark Functions**: Rastrigin, Ackley, Schwefel, Rosenbrock, and Sphere optimization problems
|
|
27
|
+
- **Modern Build System**: CMake-based build configuration
|
|
28
|
+
- **Cross-Platform**: Works on Linux, macOS, and Windows
|
|
29
|
+
- **Multi-Language Support**: C++ (primary), Python bindings, and C-compatible interfaces
|
|
30
|
+
- **Performance Benchmarks**: Comprehensive benchmark suite for operators and functions
|
|
31
|
+
- **Production-Ready**: Modern C++17 with smart pointers and RAII
|
|
32
|
+
|
|
33
|
+
## 📖 Documentation
|
|
34
|
+
|
|
35
|
+
- **Complete user guide with C++ and Python examples**: [USER_GUIDE.md](USER_GUIDE.md)
|
|
36
|
+
- Complete feature checklist : [FEATURE_CHECKLIST.md](FEATURE_CHECKLIST.md)
|
|
37
|
+
- Architecture overview and usage guidance: [ARCHITECTURE.md](ARCHITECTURE.md)
|
|
38
|
+
|
|
39
|
+
## 📁 Project Structure
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
Genetic_algorithm/
|
|
43
|
+
├── CMakeLists.txt # Main CMake configuration
|
|
44
|
+
├── README.md # This file
|
|
45
|
+
├── include/ga/ # Public framework headers (installable)
|
|
46
|
+
│ ├── config.hpp # Config, Bounds, Result, Fitness alias
|
|
47
|
+
│ └── genetic_algorithm.hpp # GeneticAlgorithm class and factories
|
|
48
|
+
├── src/
|
|
49
|
+
│ └── genetic_algorithm.cpp # Core GA engine implementation
|
|
50
|
+
├── examples/
|
|
51
|
+
│ └── minimal.cpp # Tiny example app using the framework
|
|
52
|
+
├── simple-ga-test.cc # Legacy interactive demo (still works)
|
|
53
|
+
├── crossover/ # Crossover operators
|
|
54
|
+
│ ├── base_crossover.h/cc # Base crossover interface
|
|
55
|
+
│ ├── one_point_crossover.h/cc
|
|
56
|
+
│ ├── two_point_crossover.h/cc
|
|
57
|
+
│ ├── uniform_crossover.h/cc
|
|
58
|
+
│ ├── blend_crossover.h/cc
|
|
59
|
+
│ ├── simulated_binary_crossover.h/cc
|
|
60
|
+
│ ├── order_crossover.h/cc
|
|
61
|
+
│ ├── partially_mapped_crossover.h/cc
|
|
62
|
+
│ ├── cycle_crossover.h/cc
|
|
63
|
+
│ └── ... (15+ more operators)
|
|
64
|
+
├── mutation/ # Mutation operators
|
|
65
|
+
│ ├── base_mutation.h/cc # Base mutation interface
|
|
66
|
+
│ ├── bit_flip_mutation.h/cc
|
|
67
|
+
│ ├── gaussian_mutation.h/cc
|
|
68
|
+
│ ├── uniform_mutation.h/cc
|
|
69
|
+
│ ├── swap_mutation.h/cc
|
|
70
|
+
│ └── ... (10+ more operators)
|
|
71
|
+
├── selection-operator/ # Selection methods
|
|
72
|
+
│ ├── base_selection.h/cc # Base selection interface
|
|
73
|
+
│ ├── tournament_selection.h/cc
|
|
74
|
+
│ ├── roulette_wheel_selection.h/cc
|
|
75
|
+
│ ├── rank_selection.h/cc
|
|
76
|
+
│ └── ... (5+ more operators)
|
|
77
|
+
├── benchmark/ # Benchmark suite (NEW!)
|
|
78
|
+
│ ├── ga_benchmark.h/cc # Comprehensive benchmarks
|
|
79
|
+
│ └── benchmark_main.cc # Benchmark executable
|
|
80
|
+
└── simple-GA-Test/ # Test suite and fitness functions
|
|
81
|
+
├── fitness-function.h # Fitness function declarations
|
|
82
|
+
├── fitness-fuction.cc # Fitness function implementations
|
|
83
|
+
└── README.md # Detailed test documentation
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## 🛠️ Building with CMake
|
|
87
|
+
|
|
88
|
+
### Prerequisites
|
|
89
|
+
|
|
90
|
+
- **CMake** (version 3.16 or higher)
|
|
91
|
+
- **C++17 compatible compiler**:
|
|
92
|
+
- GCC 7+ (Linux/macOS)
|
|
93
|
+
- Clang 5+ (Linux/macOS)
|
|
94
|
+
- MSVC 2017+ (Windows)
|
|
95
|
+
|
|
96
|
+
### Quick Start
|
|
97
|
+
|
|
98
|
+
#### Using Build Script (Recommended)
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
# Clone or navigate to the project directory
|
|
102
|
+
cd test-ga
|
|
103
|
+
|
|
104
|
+
# Build and run in one command
|
|
105
|
+
./build.sh --run
|
|
106
|
+
|
|
107
|
+
# Or build only
|
|
108
|
+
./build.sh
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Using CMake Directly
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
cd Genetic_algorithm
|
|
115
|
+
|
|
116
|
+
# Create build directory
|
|
117
|
+
mkdir build && cd build
|
|
118
|
+
|
|
119
|
+
# Configure with CMake
|
|
120
|
+
cmake ..
|
|
121
|
+
|
|
122
|
+
# Build the project
|
|
123
|
+
cmake --build .
|
|
124
|
+
|
|
125
|
+
# Run the legacy demo
|
|
126
|
+
./bin/simple_ga_test
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Advanced Build Options
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# Debug build with verbose output
|
|
133
|
+
cmake -DCMAKE_BUILD_TYPE=Debug ..
|
|
134
|
+
cmake --build . --verbose
|
|
135
|
+
|
|
136
|
+
# Release build with optimizations
|
|
137
|
+
cmake -DCMAKE_BUILD_TYPE=Release ..
|
|
138
|
+
cmake --build . -j$(nproc)
|
|
139
|
+
|
|
140
|
+
# Install to system (optional)
|
|
141
|
+
sudo cmake --build . --target install
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Build Script
|
|
145
|
+
|
|
146
|
+
The project includes a convenient build script (`build.sh`) that automates the build process:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Basic build
|
|
150
|
+
./build.sh
|
|
151
|
+
|
|
152
|
+
# Build with options
|
|
153
|
+
./build.sh --debug --run --verbose
|
|
154
|
+
|
|
155
|
+
# Clean build
|
|
156
|
+
./build.sh --clean
|
|
157
|
+
|
|
158
|
+
# Install to system
|
|
159
|
+
./build.sh --install
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### CMake Targets
|
|
163
|
+
|
|
164
|
+
- `genetic_algorithm`: Static library (the framework)
|
|
165
|
+
- `simple-ga-test`: Interactive demo executable
|
|
166
|
+
- `run`: Build and run the GA test
|
|
167
|
+
- `clean-results`: Remove output files
|
|
168
|
+
- `install`: Install to system
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# Use custom targets
|
|
172
|
+
cmake --build . --target run
|
|
173
|
+
cmake --build . --target clean-results
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## 🎯 Using the framework in your code
|
|
177
|
+
|
|
178
|
+
The public API is in `include/ga`. Example:
|
|
179
|
+
|
|
180
|
+
```cpp
|
|
181
|
+
#include <ga/genetic_algorithm.hpp>
|
|
182
|
+
#include <cmath>
|
|
183
|
+
|
|
184
|
+
static double rastrigin(const std::vector<double>& x) {
|
|
185
|
+
const double A = 10.0;
|
|
186
|
+
double sum = A * x.size();
|
|
187
|
+
for (double xi : x) sum += xi*xi - A*std::cos(2*M_PI*xi);
|
|
188
|
+
// convert minimization to maximization fitness
|
|
189
|
+
return 1000.0 / (1.0 + sum);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
int main() {
|
|
193
|
+
ga::Config cfg;
|
|
194
|
+
cfg.populationSize = 60;
|
|
195
|
+
cfg.generations = 100;
|
|
196
|
+
cfg.dimension = 10;
|
|
197
|
+
cfg.bounds = {-5.12, 5.12};
|
|
198
|
+
|
|
199
|
+
ga::GeneticAlgorithm alg(cfg);
|
|
200
|
+
ga::Result res = alg.run(rastrigin);
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
You can also compile and run the ready-made example:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
cmake --build build -j
|
|
208
|
+
./build/examples/minimal
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
NSGA-II minimal example:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
cmake --build build -j
|
|
215
|
+
./build/examples/ga-nsga2-minimal
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
High-level optimizer API example:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
cmake --build build -j
|
|
222
|
+
./build/examples/ga-optimizer-minimal
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
NSGA-III sanity test:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
cmake --build build --target nsga3-sanity
|
|
229
|
+
./build/tests/nsga3-sanity
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
To customize operators:
|
|
233
|
+
|
|
234
|
+
```cpp
|
|
235
|
+
#include <ga/genetic_algorithm.hpp>
|
|
236
|
+
|
|
237
|
+
auto alg = ga::GeneticAlgorithm(cfg);
|
|
238
|
+
alg.setCrossoverOperator(ga::makeTwoPointCrossover());
|
|
239
|
+
alg.setMutationOperator(ga::makeUniformMutation());
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### C API (Baseline Wrapper)
|
|
243
|
+
|
|
244
|
+
The project includes a C-compatible API in `include/ga/c_api.h`.
|
|
245
|
+
|
|
246
|
+
Key C API additions:
|
|
247
|
+
- `ga_validate_config(...)` for pre-run argument checks
|
|
248
|
+
- `ga_history_length(...)`, `ga_best_history(...)`, `ga_avg_history(...)` for convergence history export
|
|
249
|
+
|
|
250
|
+
```c
|
|
251
|
+
#include <ga/c_api.h>
|
|
252
|
+
|
|
253
|
+
static double sphere_fitness(const double* genes, int length, void* user_data) {
|
|
254
|
+
(void)user_data;
|
|
255
|
+
double sum = 0.0;
|
|
256
|
+
for (int i = 0; i < length; ++i) {
|
|
257
|
+
sum += genes[i] * genes[i];
|
|
258
|
+
}
|
|
259
|
+
return 1000.0 / (1.0 + sum);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
int main(void) {
|
|
263
|
+
ga_config_c cfg = {60, 100, 10, 0.8, 0.1, -5.12, 5.12, 0.05, 42};
|
|
264
|
+
if (ga_validate_config(&cfg) != GA_STATUS_OK) {
|
|
265
|
+
return 1;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
ga_handle* h = ga_create(&cfg);
|
|
269
|
+
if (!h) {
|
|
270
|
+
return 1;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (ga_run(h, sphere_fitness, 0) != GA_STATUS_OK) {
|
|
274
|
+
ga_destroy(h);
|
|
275
|
+
return 1;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
double best = ga_best_fitness(h);
|
|
279
|
+
|
|
280
|
+
int n = ga_history_length(h);
|
|
281
|
+
double history[1024];
|
|
282
|
+
if (n > 0 && n <= 1024) {
|
|
283
|
+
(void)ga_best_history(h, history, n);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
ga_destroy(h);
|
|
287
|
+
(void)best;
|
|
288
|
+
return 0;
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### NSGA-II Utilities (C++ Core)
|
|
293
|
+
|
|
294
|
+
NSGA-II helper APIs are available in `include/ga/algorithms/moea/nsga2.hpp`:
|
|
295
|
+
- non-dominated sorting
|
|
296
|
+
- crowding distance
|
|
297
|
+
- callback-based generation loop (`run(...)`)
|
|
298
|
+
|
|
299
|
+
NSGA-III helper APIs are available in `include/ga/moea/nsga3.hpp`:
|
|
300
|
+
- Das-Dennis reference point generation
|
|
301
|
+
- reference-point environmental selection niching with intercept-based normalization
|
|
302
|
+
|
|
303
|
+
High-level optimizer methods in `include/ga/api/optimizer.hpp` now include:
|
|
304
|
+
- `optimizeMultiObjective(...)` (NSGA-II)
|
|
305
|
+
- `optimizeMultiObjectiveNsga3(...)`
|
|
306
|
+
|
|
307
|
+
Distributed evaluation backends in `include/ga/evaluation/distributed_executor.hpp`:
|
|
308
|
+
- `LocalDistributedExecutor` (threaded local backend)
|
|
309
|
+
- `ProcessDistributedExecutor` (true multi-process backend on POSIX)
|
|
310
|
+
|
|
311
|
+
Python bindings (`python/ga_bindings.cpp`) also expose:
|
|
312
|
+
- NSGA-III objective-space utilities (`Nsga3`, `nsga3_reference_points`, `nsga3_environmental_select_indices`)
|
|
313
|
+
- checkpoint JSON API (`CheckpointState`, `checkpoint_save_json`, `checkpoint_load_json`)
|
|
314
|
+
|
|
315
|
+
### Interactive Mode (Recommended)
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
./bin/simple_ga_test
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
The program will guide you through:
|
|
322
|
+
1. **Representation selection** (binary, real_valued, integer, permutation)
|
|
323
|
+
2. **Operator validation** against chosen representation
|
|
324
|
+
3. **Automatic configuration** of compatible operators
|
|
325
|
+
|
|
326
|
+
### Command Line Testing
|
|
327
|
+
|
|
328
|
+
#### Real-Valued Optimization
|
|
329
|
+
```bash
|
|
330
|
+
echo -e "real_valued\nblend\ngaussian\ntournament" | ./bin/simple_ga_test
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
#### Binary Optimization
|
|
334
|
+
```bash
|
|
335
|
+
echo -e "binary\nuniform\nbit_flip\ntournament" | ./bin/simple_ga_test
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
#### Integer Optimization
|
|
339
|
+
```bash
|
|
340
|
+
echo -e "integer\narithmetic\nrandom_resetting\ntournament" | ./bin/simple_ga_test
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
#### Permutation Problems
|
|
344
|
+
```bash
|
|
345
|
+
echo -e "permutation\norder_crossover\nswap\ntournament" | ./bin/simple_ga_test
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
#### C API Sanity Test
|
|
349
|
+
```bash
|
|
350
|
+
cmake --build build --target c-api-sanity
|
|
351
|
+
./build/tests/c-api-sanity
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
#### Feature Foundation Sanity Test
|
|
355
|
+
```bash
|
|
356
|
+
cmake --build build --target features-foundation-sanity
|
|
357
|
+
./build/tests/features-foundation-sanity
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
#### Process Distributed Backend Sanity Test
|
|
361
|
+
```bash
|
|
362
|
+
cmake --build build --target process-distributed-sanity
|
|
363
|
+
./build/tests/process-distributed-sanity
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## 🔧 Configuration
|
|
367
|
+
|
|
368
|
+
The framework uses `ga::Config`:
|
|
369
|
+
|
|
370
|
+
```cpp
|
|
371
|
+
struct Bounds { double lower, upper; };
|
|
372
|
+
struct Config {
|
|
373
|
+
int populationSize = 50;
|
|
374
|
+
int generations = 100;
|
|
375
|
+
int dimension = 10;
|
|
376
|
+
double crossoverRate = 0.8;
|
|
377
|
+
double mutationRate = 0.1;
|
|
378
|
+
Bounds bounds{-5.12, 5.12};
|
|
379
|
+
double eliteRatio = 0.05; // 5% elites
|
|
380
|
+
unsigned seed = 0; // 0 -> random
|
|
381
|
+
};
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## 📊 Supported Representations & Operators
|
|
385
|
+
|
|
386
|
+
### Binary Representation
|
|
387
|
+
- **Crossovers**: One-point, Two-point, Uniform
|
|
388
|
+
- **Mutations**: Bit-flip
|
|
389
|
+
- **Use Cases**: Feature selection, binary optimization
|
|
390
|
+
|
|
391
|
+
### Real-Valued Representation
|
|
392
|
+
- **Crossovers**: Arithmetic, Blend (BLX-α), SBX, One-point, Two-point, Uniform
|
|
393
|
+
- **Mutations**: Gaussian, Uniform
|
|
394
|
+
- **Use Cases**: Continuous function optimization, parameter tuning
|
|
395
|
+
|
|
396
|
+
### Integer Representation
|
|
397
|
+
- **Crossovers**: One-point, Two-point, Uniform, Arithmetic
|
|
398
|
+
- **Mutations**: Random resetting, Creep
|
|
399
|
+
- **Use Cases**: Discrete optimization, scheduling problems
|
|
400
|
+
|
|
401
|
+
### Permutation Representation
|
|
402
|
+
- **Crossovers**: Order crossover (OX), Partially mapped crossover (PMX), Cycle crossover
|
|
403
|
+
- **Mutations**: Swap, Insert, Scramble, Inversion
|
|
404
|
+
- **Use Cases**: Traveling salesman problem, job scheduling
|
|
405
|
+
|
|
406
|
+
## 🧪 Benchmark Functions
|
|
407
|
+
|
|
408
|
+
The framework includes 5 standard optimization test functions:
|
|
409
|
+
|
|
410
|
+
1. **Sphere Function**: Simple unimodal function (baseline)
|
|
411
|
+
2. **Rastrigin Function**: Highly multimodal with many local optima
|
|
412
|
+
3. **Ackley Function**: One global minimum with many local minima
|
|
413
|
+
4. **Schwefel Function**: Deceptive function with global optimum far from local optima
|
|
414
|
+
5. **Rosenbrock Function**: Narrow valley, challenging for optimization
|
|
415
|
+
|
|
416
|
+
## 🔬 Running Benchmarks
|
|
417
|
+
|
|
418
|
+
The framework includes a comprehensive benchmark suite that tests:
|
|
419
|
+
- **Operator Performance**: Speed of crossover, mutation, and selection operators
|
|
420
|
+
- **Function Optimization**: Convergence quality on test functions
|
|
421
|
+
- **Scalability**: Performance vs. population size and problem dimension
|
|
422
|
+
|
|
423
|
+
### Quick Start
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
# Build the benchmark executable
|
|
427
|
+
cmake --build build
|
|
428
|
+
|
|
429
|
+
# Run all benchmarks
|
|
430
|
+
./build/bin/ga-benchmark --all
|
|
431
|
+
|
|
432
|
+
# Run specific benchmark categories
|
|
433
|
+
./build/bin/ga-benchmark --operators # Test operator performance
|
|
434
|
+
./build/bin/ga-benchmark --functions # Test function optimization
|
|
435
|
+
./build/bin/ga-benchmark --scalability # Test scalability
|
|
436
|
+
|
|
437
|
+
# Customize benchmark iterations
|
|
438
|
+
./build/bin/ga-benchmark --operators --iterations 1000
|
|
439
|
+
|
|
440
|
+
# Export results to CSV
|
|
441
|
+
./build/bin/ga-benchmark --all --csv
|
|
442
|
+
|
|
443
|
+
# Show help
|
|
444
|
+
./build/bin/ga-benchmark --help
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Benchmark Results
|
|
448
|
+
|
|
449
|
+
**Operator Performance (typical results on modern CPU):**
|
|
450
|
+
| Operator Category | Representative | Throughput |
|
|
451
|
+
|-------------------|----------------|------------|
|
|
452
|
+
| Binary Crossover | TwoPointCrossover | 2M ops/sec |
|
|
453
|
+
| Real Crossover | BlendCrossover (BLX-α) | 5M ops/sec |
|
|
454
|
+
| Permutation Crossover | OrderCrossover (OX) | 869K ops/sec |
|
|
455
|
+
| Binary Mutation | BitFlipMutation | 1.1M ops/sec |
|
|
456
|
+
| Real Mutation | GaussianMutation | 6.6M ops/sec |
|
|
457
|
+
| Permutation Mutation | SwapMutation | 20M ops/sec |
|
|
458
|
+
| Selection | TournamentSelection | 181K ops/sec |
|
|
459
|
+
|
|
460
|
+
**Function Optimization (convergence times):**
|
|
461
|
+
| Function | Generations | Time (ms) | Best Fitness |
|
|
462
|
+
|----------|-------------|-----------|--------------|
|
|
463
|
+
| Sphere | 100 | ~1 | >500 |
|
|
464
|
+
| Rastrigin | 200 | ~5 | >60 |
|
|
465
|
+
| Ackley | 150 | ~4 | >60 |
|
|
466
|
+
| Schwefel | 200 | ~7 | Variable |
|
|
467
|
+
| Rosenbrock | 300 | ~8 | >200 |
|
|
468
|
+
|
|
469
|
+
*Results will vary based on hardware, problem configuration, and random seed.*
|
|
470
|
+
|
|
471
|
+
### Understanding Benchmark Output
|
|
472
|
+
|
|
473
|
+
The benchmark tool generates:
|
|
474
|
+
- **Console output**: Real-time progress and summary statistics
|
|
475
|
+
- **benchmark_results.txt**: Detailed results with all metrics
|
|
476
|
+
- **benchmark_results.csv**: Machine-readable format (with `--csv` flag)
|
|
477
|
+
|
|
478
|
+
## 🏗️ Architecture & Efficiency
|
|
479
|
+
|
|
480
|
+
For a detailed analysis of the framework's architecture, efficiency, and usability across C++, Python, and C, see [ARCHITECTURE.md](ARCHITECTURE.md).
|
|
481
|
+
|
|
482
|
+
**Key Highlights:**
|
|
483
|
+
- ⚡ **Performance**: Native C++17 with zero-overhead abstractions
|
|
484
|
+
- 🔧 **Extensible**: Easy to add custom operators and fitness functions
|
|
485
|
+
- 🌐 **Multi-language**: C++ core with Python bindings
|
|
486
|
+
- 📊 **Validated**: Comprehensive benchmark suite included
|
|
487
|
+
- 🧪 **Tested**: Multiple test programs and sanity checks
|
|
488
|
+
|
|
489
|
+
## 🔍 Development
|
|
490
|
+
|
|
491
|
+
### Adding New Operators
|
|
492
|
+
|
|
493
|
+
1. Create header and implementation files in the appropriate directory
|
|
494
|
+
2. Inherit from the base operator class
|
|
495
|
+
3. Implement required virtual methods
|
|
496
|
+
4. Optionally expose convenience factories alongside `ga::make*` helpers
|
|
497
|
+
|
|
498
|
+
### Adding New Fitness Functions
|
|
499
|
+
|
|
500
|
+
1. Add declaration to `simple-GA-Test/fitness-function.h`
|
|
501
|
+
2. Implement in `simple-GA-Test/fitness-fuction.cc`
|
|
502
|
+
3. Add to the `GAConfig::FunctionType` enum
|
|
503
|
+
4. Update the fitness function selection logic
|
|
504
|
+
|
|
505
|
+
### Building for Development
|
|
506
|
+
|
|
507
|
+
```bash
|
|
508
|
+
# Debug build with symbols
|
|
509
|
+
cmake -DCMAKE_BUILD_TYPE=Debug ..
|
|
510
|
+
cmake --build .
|
|
511
|
+
|
|
512
|
+
# Run with debug output
|
|
513
|
+
./bin/simple_ga_test
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
## 📝 Output
|
|
517
|
+
|
|
518
|
+
The program generates:
|
|
519
|
+
- **Console output**: Progress information and final results
|
|
520
|
+
- **ga_results.txt**: Detailed results including:
|
|
521
|
+
- Best fitness values per generation
|
|
522
|
+
- Average fitness values
|
|
523
|
+
- Best individual's chromosome
|
|
524
|
+
- Optimization statistics
|
|
525
|
+
|
|
526
|
+
## 🤝 Contributing
|
|
527
|
+
|
|
528
|
+
1. Fork the repository
|
|
529
|
+
2. Create a feature branch
|
|
530
|
+
3. Make your changes
|
|
531
|
+
4. Add tests if applicable
|
|
532
|
+
5. Submit a pull request
|
|
533
|
+
|
|
534
|
+
## 📄 License
|
|
535
|
+
|
|
536
|
+
This project is open source. Please check individual files for license information.
|
|
537
|
+
|
|
538
|
+
## 🆘 Troubleshooting
|
|
539
|
+
|
|
540
|
+
### Common Issues
|
|
541
|
+
|
|
542
|
+
**CMake not found:**
|
|
543
|
+
```bash
|
|
544
|
+
# Ubuntu/Debian
|
|
545
|
+
sudo apt install cmake
|
|
546
|
+
|
|
547
|
+
# macOS
|
|
548
|
+
brew install cmake
|
|
549
|
+
|
|
550
|
+
# Windows
|
|
551
|
+
# Download from https://cmake.org/download/
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
**Compiler not found:**
|
|
555
|
+
```bash
|
|
556
|
+
# Ubuntu/Debian
|
|
557
|
+
sudo apt install build-essential
|
|
558
|
+
|
|
559
|
+
# macOS
|
|
560
|
+
xcode-select --install
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
**Build errors:**
|
|
564
|
+
```bash
|
|
565
|
+
# Clean and rebuild
|
|
566
|
+
rm -rf build
|
|
567
|
+
mkdir build && cd build
|
|
568
|
+
cmake ..
|
|
569
|
+
cmake --build .
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
### Getting Help
|
|
573
|
+
|
|
574
|
+
- Check the detailed documentation in `simple-GA-Test/README.md`
|
|
575
|
+
- Review the CMake configuration in `CMakeLists.txt`
|
|
576
|
+
- Examine the source code for implementation details
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
genetic_algorithm_lib/__init__.py,sha256=Ik9fth76ImZYr1a3x4PkcsLVNCIAdXzftGM9rhfi398,912
|
|
2
|
+
genetic_algorithm_lib/_core.cp310-win32.pyd,sha256=8TYT4hfFz-61NcEAV4Ls_yTpBgUNc4fP4kWNAafvNoE,1117184
|
|
3
|
+
genetic_algorithm_lib-1.0.0.dist-info/METADATA,sha256=zgqv453widkAhOjYv766cVHJDcekZNtSuiO1QKfLbHo,16315
|
|
4
|
+
genetic_algorithm_lib-1.0.0.dist-info/WHEEL,sha256=S_zGryBfjwWLi5e5LyCOGRp6hjXpi88SDdr41GgmxyI,102
|
|
5
|
+
genetic_algorithm_lib-1.0.0.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
|
|
6
|
+
genetic_algorithm_lib-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|