Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/cpp-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: C++ tests

on:
pull_request:
push:
branches: ["main"]
workflow_dispatch:

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
build_type: [Debug, Release]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: Configure
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}

- name: Build
run: cmake --build build --config ${{ matrix.build_type }} --parallel 2

- name: Test
run: ctest --test-dir build --build-config ${{ matrix.build_type }} --output-on-failure
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* cp312-*"
CIBW_SKIP: "pp* *-musllinux_*"
CIBW_TEST_COMMAND: >-
python -c "import genetic_algorithm_lib as ga; cfg = ga.Config(); print(cfg)"
python -c "import genetic_algorithm_lib as ga; s = ga.SearchConfig(); s.population_size = 6; s.iterations = 2; s.dimension = 2; s.seed = 1; c = ga.PsoConfig(); c.search = s; r = ga.ParticleSwarmOptimizer(c).optimize(lambda x: 1.0 / (1.0 + sum(v * v for v in x))); assert len(r.best_solution) == 2"

- name: Upload wheels
uses: actions/upload-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
/build-*/
.scikit-build/
_skbuild/
.venv/
Expand Down
51 changes: 47 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.16)
project(GeneticAlgorithm VERSION 1.0.0 LANGUAGES CXX)

find_package(Threads REQUIRED)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -18,6 +20,12 @@ set(CORE_SOURCES
src/genetic_algorithm.cpp
src/c_api.cpp
src/algorithms/moea/nsga2.cpp
src/aco/ant_colony.cpp
src/aco/continuous_ant_colony.cpp
src/fuzzy/fuzzy_c_means.cpp
src/gsa/gravitational_search.cpp
src/hybrid/metaheuristic_pipeline.cpp
src/pso/particle_swarm.cpp
)

# Build reusable library (framework)
Expand All @@ -32,6 +40,7 @@ target_include_directories(genetic_algorithm PUBLIC
$<INSTALL_INTERFACE:include>
)
set_target_properties(genetic_algorithm PROPERTIES OUTPUT_NAME "genetic_algorithm")
target_link_libraries(genetic_algorithm PUBLIC Threads::Threads)

# Warnings: keep them compiler-appropriate (avoid injecting GCC/Clang flags into MSVC).
if(MSVC)
Expand All @@ -41,6 +50,8 @@ else()
endif()

if(NOT SKBUILD)
enable_testing()

# Main executable
add_executable(simple-ga-test
simple-ga-test.cc
Expand Down Expand Up @@ -102,6 +113,12 @@ if(NOT SKBUILD)
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples"
)

add_executable(ga-metaheuristics-minimal examples/metaheuristics_minimal.cpp)
target_link_libraries(ga-metaheuristics-minimal PRIVATE genetic_algorithm)
set_target_properties(ga-metaheuristics-minimal PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples"
)

# Tests (lightweight sanity checks)
add_executable(operators-sanity tests/operators_sanity.cc)
target_link_libraries(operators-sanity PRIVATE genetic_algorithm)
Expand Down Expand Up @@ -151,6 +168,22 @@ if(NOT SKBUILD)
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
)

add_executable(metaheuristics-sanity tests/metaheuristics_sanity.cc)
target_link_libraries(metaheuristics-sanity PRIVATE genetic_algorithm)
set_target_properties(metaheuristics-sanity PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
)

add_test(NAME operators-sanity COMMAND operators-sanity)
add_test(NAME nsga2-sanity COMMAND nsga2-sanity)
add_test(NAME nsga3-sanity COMMAND nsga3-sanity)
add_test(NAME c-api-sanity COMMAND c-api-sanity)
add_test(NAME features-foundation-sanity COMMAND features-foundation-sanity)
add_test(NAME process-distributed-sanity COMMAND process-distributed-sanity)
add_test(NAME advanced-features-sanity COMMAND advanced-features-sanity)
add_test(NAME representations-core-sanity COMMAND representations-core-sanity)
add_test(NAME metaheuristics-sanity COMMAND metaheuristics-sanity)

# Benchmark suite
add_executable(ga-benchmark
benchmark/benchmark_main.cc
Expand All @@ -160,6 +193,12 @@ if(NOT SKBUILD)
set_target_properties(ga-benchmark PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)

add_executable(metaheuristics-benchmark benchmark/metaheuristics_benchmark.cc)
target_link_libraries(metaheuristics-benchmark PRIVATE genetic_algorithm)
set_target_properties(metaheuristics-benchmark PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
endif()

# ---------------------------------------------------------------- Python bindings
Expand Down Expand Up @@ -221,6 +260,14 @@ if(Python3_FOUND AND pybind11_FOUND)
LIBRARY DESTINATION lib/python/genetic_algorithm_lib
RUNTIME DESTINATION lib/python/genetic_algorithm_lib
)
add_test(
NAME python-bindings-sanity
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/python/bindings_sanity.py"
)
set_tests_properties(python-bindings-sanity PROPERTIES
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
ENVIRONMENT "GA_PYTHON_MODULE_DIR=${CMAKE_BINARY_DIR}/python"
)
endif()
message(STATUS "Python bindings: ENABLED (pybind11 ${pybind11_VERSION})")
else()
Expand Down Expand Up @@ -250,10 +297,6 @@ if(NOT SKBUILD)
)
endif()

# Add test target (if you want to add unit tests later)
# enable_testing()
# add_test(NAME GA_Test COMMAND simple-ga-test)

# Print configuration summary
message(STATUS "=== Genetic Algorithm Build Configuration ===")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
Expand Down
8 changes: 6 additions & 2 deletions FEATURE_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Legend: implemented, partial, planned
| Checkpointing | implemented | binary + JSON checkpoint save/load manager in `include/ga/checkpoint/checkpoint.hpp` |
| Adaptive operators | implemented | adaptive rate controller in `include/ga/adaptive/adaptive_policy.hpp` |
| Hybrid optimization | implemented | GA+local-search hybrid pipeline in `include/ga/hybrid/hybrid_optimizer.hpp` |
| PSO family | implemented | global/local, constriction, bare-bones, fully informed, quantum, and binary variants in `include/ga/pso/*` |
| ACO family | implemented | five graph ACO variants plus continuous ACOR in `include/ga/aco/*` |
| Gravitational Search (GSA) | implemented | continuous K-best GSA in `include/ga/gsa/*` |
| Fuzzy optimization support | implemented | fuzzy C-means and opt-in, user-configurable Sugeno adaptive controller in `include/ga/fuzzy/*` |
| Heterogeneous hybrid pipeline | implemented | caller-selected optimizer order, GA adapter, and solution-transfer pipeline in `include/ga/metaheuristics/*` and `include/ga/hybrid/metaheuristic_pipeline.hpp` |
| Constraint handling | implemented | hard/soft/repair constraint toolkit in `include/ga/constraints/constraints.hpp` |
| Experiment tracking | implemented | experiment tracker with CSV export in `include/ga/tracking/experiment_tracker.hpp` |
| Visualization support | implemented | CSV export helpers for fitness/pareto/diversity in `include/ga/visualization/export.hpp` |
Expand All @@ -29,7 +34,7 @@ Legend: implemented, partial, planned
| Core representations (all types) | implemented | `VectorGenome`, `BitsetGenome`, `PermutationGenome`, `TreeGenome`, `SetGenome`, `MapGenome`, `NdArrayGenome` in `include/ga/representations/*` |
| Core abstractions | implemented | `IGenome`, `Individual`, `IProblem`, `Evaluation` in `include/ga/core/*`; `Population`, `IEvaluator`, `IAlgorithm`, `OptimizationResult` added |
| High-level API | implemented | fluent `Optimizer` API for single/multi-objective in `include/ga/api/optimizer.hpp`; `OptimizerBuilder` fluent builder in `include/ga/api/builder.hpp` |
| C and Python export path | implemented | Python bindings (`python/ga_bindings.cpp`); C ABI wrapper (`include/ga/c_api.h`, `src/c_api.cpp`) |
| C and Python export path | implemented | Python bindings include PSO/ACO/ACOR/GSA/fuzzy/user-defined pipelines (`python/ga_bindings.cpp`); C ABI wrapper (`include/ga/c_api.h`, `src/c_api.cpp`) |

## 2) Complete Checklist (What, Why, How)

Expand Down Expand Up @@ -411,4 +416,3 @@ public:
- adaptive operators, hybrid local search, ergonomic optimizer API
7. Language exports:
- C wrapper and expanded Python bindings

30 changes: 28 additions & 2 deletions IMPLEMENTATION_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,26 @@ This report documents the comprehensive analysis and testing of the genetic algo
- Co-evolution Engine: PASS
- Integration Test (all features together): PASS

8. **representations-core-sanity** - Representations and core abstractions: PASS

9. **metaheuristics-sanity** - New optimization suite: PASS
- Seven PSO families: PASS
- Five graph ACO variants and continuous ACOR: PASS
- GSA: PASS
- Fuzzy C-means and fuzzy adaptive control: PASS
- GA/PSO solution-transfer pipeline: PASS
- Exact evaluation accounting and no-elitism best retention: PASS

### Examples (All Working)
- **ga-minimal**: Basic single-objective GA - Working
- **ga-nsga2-minimal**: Multi-objective NSGA-II - Working
- **ga-optimizer-minimal**: High-level optimizer API - Working
- **ga-metaheuristics-minimal**: Fuzzy-controlled GA/PSO/ACOR pipeline - Working

### Benchmark Suite (All Working)
- **Operators Benchmark**: Performance testing of all operators - Working
- **Functions Benchmark**: Optimization of test functions (Sphere, Rastrigin, Ackley, Schwefel, Rosenbrock) - Working
- **Metaheuristics Benchmark**: PSO family, ACOR, and GSA timing/evaluation comparison - Working
- All benchmarks complete successfully and generate reports

## Implementation Status by Feature
Expand All @@ -66,6 +78,20 @@ This report documents the comprehensive analysis and testing of the genetic algo
- 11 Mutation operators in `mutation/`
- 6 Selection operators in `selection-operator/`

### ✅ Metaheuristics Suite
- **Particle Swarm Optimization** (`include/ga/pso/`, `src/pso/`)
- Global-best, ring local-best, constriction, bare-bones, fully informed,
quantum-behaved, and binary variants
- **Ant Colony Optimization** (`include/ga/aco/`, `src/aco/`)
- Ant System, Elitist AS, Rank-Based AS, ACS, MAX-MIN AS, and continuous ACOR
- **Gravitational Search** (`include/ga/gsa/`, `src/gsa/`)
- Continuous GSA with decreasing K-best interaction
- **Fuzzy support** (`include/ga/fuzzy/`, `src/fuzzy/`)
- Standalone fuzzy C-means and a reusable Sugeno adaptive controller
- **Composition** (`include/ga/metaheuristics/`, `include/ga/hybrid/`)
- Common continuous-optimizer contract, GA adapter, and sequential
solution-transfer pipeline

### ✅ Multi-Objective Optimization (100% Complete)
- **NSGA-II** (`src/algorithms/moea/nsga2.cpp`)
- Non-dominated sorting
Expand Down Expand Up @@ -208,7 +234,7 @@ This report documents the comprehensive analysis and testing of the genetic algo
## Code Quality Metrics

### Test Coverage
- **7 Comprehensive Test Suites**: All passing
- **9 Comprehensive Test Suites**: All passing
- **37,000+ lines** of test code across all test files
- **35+ operators** individually tested
- **All advanced features** have dedicated tests
Expand Down Expand Up @@ -283,7 +309,7 @@ The genetic algorithm library is feature-complete according to the FEATURE_CHECK
- Co-evolution framework
- All integration scenarios

**Total Test Status: 7/7 test suites passing, 0 failures**
**Total Test Status: 9/9 test suites passing, 0 failures**

The library now has:
- ✅ Production-ready code quality
Expand Down
Loading
Loading